#include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long LL; typedef unsigned long long ULL; const int maxn = 1005; int a[maxn][maxn], b[maxn][maxn]; int xx[maxn], yy[maxn], t1[maxn], t2[maxn]; int n, m, q; void work() { scanf("%d%d%d", &n, &m, &q); for(int i = 1; i <= n; i++) for(int j = 1; j <= m; j++) scanf("%d", &a[i][j]); for(int i = 1; i <= n; i++) xx[i] = i; for(int j = 1; j <= m; j++) yy[j] = j; memset(t1, 0, sizeof t1); memset(t2, 0, sizeof t2); while(q--) { int op, x, y; scanf("%d%d%d", &op, &x, &y); if(op == 1) { swap(xx[x], xx[y]); } else if(op == 2) { swap(yy[x], yy[y]); } else if(op == 3) { t1[xx[x]] += y; } else t2[yy[x]] += y; } for(int i = 1; i <= n; i++) { for(int j = 1; j <= m; j++) a[i][j] += t1[i]; } for(int j = 1; j <= m; j++) { for(int i = 1; i <= n; i++) a[i][j] += t2[j]; } for(int i = 1; i <= n; i++) for(int j = 1; j <= m; j++) b[i][j] = a[xx[i]][yy[j]]; for(int i = 1; i <= n; i++) for(int j = 1; j <= m; j++) printf("%d%c", b[i][j], j == m ? '\n' : ' '); } int main() { int _; scanf("%d", &_); while(_--) work(); return 0; }