Prove a rank equality $\newcommand{\rank}{\mathrm{rank}}$
I am trying to solve the following linear algebra exercise from a textbook.

Let $P_1, P_2, \ldots, P_k, Q_1, Q_2, \ldots, Q_k$ be order $n$ matrices over the number field $F$, and $P_iQ_j = Q_jP_i$, $\rank(P_i) = \rank(P_iQ_i), 1 \leq i, j \leq k$. Prove,
\begin{align*}
\rank(P_1P_2\cdots P_k) = \rank(P_1\cdots P_kQ_1\cdots Q_k).
\end{align*}

So far, I am quite clueless. While the condition $\rank(P_i) = \rank(P_iQ_i)$ implies $P_i = P_iQ_iR_i$ for some order $n$ matrix $R_i$, I don't know how to apply the commutativity condition properly.
For the case $k = 2$, it seems helpful to try to show that $\text{Im}(P_1P_2Q_1Q_2) \subset 
\text{Im}(P_1P_2)$. So I took any $x \in \text{Im}(P_1P_2)$, hence $x = P_1P_2y = P_1P_2Q_2R_2y$ for some $y \in F^n$. Then I got stuck.
 A: We'll prove it by induction, I'll write the base case in details (then if you have difficulties with the induction step don't hesitate to ask for help).
k=2:
$rank(P_1P_2)=rank(P_2)-dim(KerP_1\cap ImmP_2)$ (see the note (*) at the end)
$rank(P_1P_2Q_1Q_2)=rank(P_1Q_1P_2Q_2)=rank(P_2Q_2)-dim(KerP_1Q_1\cap ImmP_2Q_2)$
where I used the commutativity condition for the first passage, and (*) for the second.
By the condition: $rank(P_i)=rank(P_iQ_i)$ we deduce that: $rank(P_2)=rank(P_2Q_2)$. So we have to demonstrate that: $dim(KerP_1\cap ImmP_2)=dim(KerP_1Q_1\cap ImmP_2Q_2)$.
It is easy to see that: $KerP_1\subseteq KerQ_1P_1=KerP_1Q_1$ and: $ImmP_2Q_2\subseteq ImmP_2$. But we also know that $dim(KerP_1)=dim(KerP_1Q_1)$ (because the two matrices have the same rank, it follows from the Rank–nullity theorem), and $dim(ImmP_2Q_2)=dim(ImmP_2).$ So we can conclude that: $KerP_1=KerP_1Q_1$, $ImmP_2Q_2=ImmP_2$.
Considering that $KerP_1\cap ImmP_2=KerP_1Q_1\cap ImmP_2Q_2$, we conclude that they have the same dimension.
(*) $General$ $fact$: Given $A$ (matrix of size $m\times n$) and $B$ (of size $n\times k$) we have that: $rank(AB)=rank(B)-dim(KerA\cap ImmB)$
$Proof$: We can interpret matrices as linear maps. We have: $A:\mathbb{K}^n\to\mathbb{K}^m$, $A:\mathbb{K}^k\to\mathbb{K}^n$, $AB:\mathbb{K}^k\to\mathbb{K}^m$.
$Imm(AB)=A(ImmB)=Imm(A_{|ImmB})$ and $Ker(AB)=Ker(A_{|ImmB})=KerA\cap ImmB$.
Therefore: $rank(B)=dim(ImmA_{|ImmB})+dim(KerA_{|ImmB})=dim(ImmAB)+dim(KerA\cap ImmB)$.
