Let $p\geq q$ $P\in M_p(\mathbb{C}),Q\in M_q(\mathbb{C})$. We seek $A\in M_{p,q},B\in M_{q,p}$ s.t. $P=AB,Q=BA$. The NS conditions for the existence of $(A,B)$ are given in

On the matrices AB and BA. R.C. Thompson. Linear Algebra and Applic.

In the sequel, we assume that $P,Q$ satisfy the conditions (*) given in he paper above (in free access).

Yet the solution is not unique. Let $V_{P,Q}$ be the algebraic variety $\{(A,B)|AB=P,BA=Q\}$. I think that if $P,Q$ are generic matrices satisfying (*), then $V_{P,Q}$ has dimenson $q$. Now let $p=4,q=3$ and $AB,BA$ be diagonalizable with $spectrum(AB)=\alpha,\beta,\beta,0, spectrum(BA)=\alpha,\beta,\beta$. Then $V_{P,Q}$ has dimension $5$ ; cf. https://math.stackexchange.com/questions/731349/given-ba-find-ab

Of course , $AB,BA$ are not necessarily diagonalizable ! Do you know some results about the dimension of $V_{P,Q}$ ? Thanks.