Basically you are rearranging each of the matrices rows according to the sorted ordering of a given column in a given matrix.

You just need to figure out what is the new row index of each of the...