I'm brainstorming an idea for storing a compressed list of main class representatives of Latin squares of order $9$. One way to compress the list would be to store one Latin square $L_1$, and for $i \geq 2$, store the Latin trade between $L_i$ and $L_{i-1}$. We can reduce the size of the Latin trade by replacing $L_i$ by another main class representative that agrees with $L_{i-1}$ in more positions. However, main classes of Latin squares of order $9$ usually contain $6 \times 9!^3>10^{17}$ Latin squares, which is too many to look at exhaustively.
Question: Given two Latin squares, $L$ and $M$, of order $9$, which Latin square $M'$ in the same main class as $M$ agrees with $L$ in the most cells? How can we generate it?
I'm seeking an algorithmic answer (something implementable), and practical approximations would suffice.