Given that $A \in R^{n \times m}$ and $B \in R^{m \times n}$
The following holds true about their traces.
\begin{align*} \mathrm{tr}(AB) &= \sum_{i=1}^n (AB)_{ii}\\ &=\sum_{i=1}^n \sum_{j=1}^m A_{ij}B_{ji}\\ &= \sum_{j=1}^m \sum_{i=1}^n B_{ji}A_{ij}\\ &= \sum_{j=1}^m (BA)_{jj}\\ &= \mathrm{tr}(BA) \end{align*}
Can someone explain / provide intuition why $\sum_{i=1}^n (AB)_{ii}$ splits into $\sum_{i=1}^n \sum_{j=1}^m A_{ij}B_{ji}$?
Maybe an example matrix would help me understand.