If sequences $A$ and $B$ satisfy $A,B=B,A$ then $A$ and $B$ are concatenations of the same sequence
If $A,B$ are strings of length $|A|,|B| \le 1$ and $AB=BA$ then there is some string $D$ such that $A=D^k,B=D^l$ with $k,l \in \{0,1,..\}$.
Suppose that when $A,B$ are strings of length $|A|,|B| \le n$ and $AB=BA$ then there is some string $D$ such that $A=D^k,B=D^l$ with $k,l \in \{0,1,..\}$.
Now suppose $|A| \le n+1, |B|=n+1$ and $AB=BA$. If $|A| = |B|$ then $A=B$ and we can take $D=A$, so suppose $|A| \le n$. Then we must have $B=AC$ for some $|C|\ge 1$. Then $AAC=ACA$ and so $AC=CA$ and hence there is some $D$ such that $A=D^k,C=D^l$. Then $A=D^k, B=D^{k+l}$.