There are six sorts of activities: R: consistently shift all sections to one side, officially, set the worth of each ai,j to ai,((j−2)modn)+1; L: consistently shift all sections to one side, officially, set the worth of each ai,j to ai,(jmodn)+1; D: consistently shift all columns down, officially, set the worth of each ai,j to a((i−2)modn)+1,j
Correct answer will be upvoted else Multiple Downvoted. Computer science.
There are six sorts of activities:
R: consistently shift all sections to one side, officially, set the worth of each
L: consistently shift all sections to one side, officially, set the worth of each ai,j to ai,(jmodn)+1;
D: consistently shift all columns down, officially, set the worth of each ai,j to a((i−2)modn)+1,j;
U: consistently shift all lines up, officially, set the worth of each ai,j to a(imodn)+1,j;
I: supplant the stage read passed on to squarely in each column with its reverse.
C: supplant the stage read start to finish in every section with its converse.
Opposite of a change p1, p2, … , pn is a stage q1, q2, … , qn, to such an extent that pqi=i for each 1≤i≤n.
One can see that after any grouping of activities each line and each segment of the lattice will in any case be a change of 1,2,… ,n.
Given the underlying grid portrayal, you should handle m activities and output the last lattice.
Input
The principal line contains a solitary integer t (1≤t≤1000) — number of experiments. t experiment depictions follow.
The primary line of each experiment portrayal contains two integers n and m (1≤n≤1000,1≤m≤105) — size of the lattice and number of tasks.
Every one of the following n lines contains n integers isolated by single spaces — portrayal of the framework a (1≤ai,j≤n).
The last line of the portrayal contains a line of m characters depicting the tasks all together, as indicated by the arrangement above.
The amount of n doesn't surpass 1000, and the amount of m doesn't surpass 105.
Output
For each experiment, print n lines with n integers each — the last grid after m activities.
Step by step
Solved in 4 steps with 1 images