There are only 4 possible Solved structure/formation.
Now, let's calculate and store the number of rotations needed for each of the 4 formations in an array $Sum$
of length 4.
For each of the 4 formations, you just need to subtract the number of rotations needed before rotation and add number of rotations needed after rotation of the $(i, j)^{th} $
cell that Robi Kaka rotates. Note that you don't need to calculate for the whole structure. Because only one cell is rotated.