Let $X$ be a set. Let $M_X$ be the free magma constructed on $X$.
Suppose $N\subset M_X$ is a submagma of $M_X$: i.e. $NN\subset N$. Let $u:(N-NN)\rightarrow N$ be the canonical injection. We know that $u$ extends to a unique homomorphism $\bar{u}:M_{N-NN}\rightarrow N$.
Show that $\bar{u}$ is an isomorphism.
I am not sure how to prove surjectivity.
My work so far:
Let $x\in N$. Either $x\in NN$ or $x\not\in NN$. If $x\not\in NN$, then $x\in N-NN$ and $\bar{u}(x)=u(x)=x$: i.e. $x\in\bar{u}(N-NN)$. If $x\in NN$, then there exist unique $w,w'\in N$ such that $x=ww'$. I don't know what to do now.