#include #include #include #include #include #include #include //#include #define LL long long using namespace std; const int N = 1010; int a[N][N], b[N], c[N]; LL u[N], v[N]; int main () { // freopen ("in.txt", "r", stdin); int T; cin >> T; while (T--) { int n, m, q; cin >> n >> m >> q; // cout << n << ' '<< m << endl; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { scanf ("%d", &a[i][j]); // cout << a[i][j]; } } for (int i = 1; i <= n; i++) b[i] = i, u[i] = 0; for (int i = 1; i <= m; i++) c[i] = i, v[i] = 0; // cout << "x"; int x, y, t; // cin >> q; while (q--) { scanf ("%d%d%d", &t, &x, &y); // cout << t << ' ' << x << ' ' << if (t == 1) { swap (b[x], b[y]); } else if (t == 2) { swap (c[x], c[y]); } else if (t == 3) { u[b[x]] += y; } else { v[c[x]] += y; } } for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { printf ("%I64d", u[b[i]] + v[c[j]] + a[b[i]][c[j]]); if (j != m) printf (" "); else printf ("\n"); } } } }