同じ格子を、行ごとに足すか列ごとに足すかの違いだけです
a11 b11
a12 b21
a13 b31
a21 b12
a22 b22
a23 b32
a31 b13
a32 b23
a33 b33
行の和
列の和
行の和が tr(AB)、列の和が tr(BA) にあたります