/* ============================== * Author : Odalys * * Blog : Odalys8191.github.io * * Mail : minyuenu@gmail.com * =============================== */ #include<bits/stdc++.h> usingnamespace std; template <typename T> inlinevoidread(T &a){ T w=1; a=0; char ch=getchar(); for(;ch < '0' || ch > '9';ch=getchar()) if(ch == '-') w=-1; for(;ch>='0'&&ch<='9';ch=getchar()) a=(a<<3)+(a<<1)+(ch^48); a*=w; } template <typename T> inlinevoidckmax(T &a, T b){a = a > b ? a : b;} template <typename T> inlinevoidckmin(T &a, T b){a = a < b ? a : b;} #define fi first #define se second #define pb push_back #define mp make_pair #define mii map<int, int> #define pii pair<int, int> #define vi vector<int> #define Debug(x) cout << #x << " = " << x << endl #define For(i,l,r) for (int i = l; i <= r; ++i) #define foR(i,l,r) for (int i = l; i >= r; --i) constint N = 1000; int n, m; intId(int i, int j){ return (i - 1) * n + j; } int a[N * N | 1][3]; int Ans[N][N]; int pos[3], mv[3]; inlinevoidsolve(){ read(n); read(m); For (i, 0, 2) pos[i] = i, mv[i] = 0; For (i, 1, n) For (j, 1, n) { int cur = Id(i, j); a[cur][0] = i, a[cur][1] = j, read(a[cur][2]); } For (i, 1, m) { char ch = getchar(); if (ch == 'U') mv[pos[0]]--; if (ch == 'D') mv[pos[0]]++; if (ch == 'L') mv[pos[1]]--; if (ch == 'R') mv[pos[1]]++; if (ch == 'I') swap(pos[1], pos[2]); if (ch == 'C') swap(pos[0], pos[2]); } For (i, 1, n * n) { For (j, 0, 2) a[i][j] = (a[i][j] - 1 + mv[j] + n * m) % n + 1; Ans[a[i][pos[0]]][a[i][pos[1]]] = a[i][pos[2]]; } For (i, 1, n) { For (j, 1, n) printf("%d ", Ans[i][j]); puts("");} }
intmain(){ int cases; read(cases); while (cases--) solve(), puts(""); return0; }