#include #include using namespace std; typedef long long LL; const int INF = 1<<30; int n, m, q; int A[1005][1005]; int h[1005], l[1005], ah[1005], al[1005]; int main() { int T; scanf("%d", &T); int o, x, y; while (T--) { 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) { h[i] = i; ah[i] = 0; } for (int i = 1; i <= m; ++i) { l[i] = i; al[i] = 0; } while (q--) { scanf("%d%d%d", &o, &x, &y); if (o == 1) { swap(h[x], h[y]); continue; } if (o == 2) { swap(l[x], l[y]); continue; } if (o == 3) { ah[h[x]] += y; continue; } if (o == 4) { al[l[x]] += y; } } for (int i = 1; i <= n; ++i) { printf("%d", A[h[i]][l[1]] + ah[h[i]] + al[l[1]]); for (int j = 2; j <= m; ++j) printf(" %d", A[h[i]][l[j]] + ah[h[i]] + al[l[j]]); puts(""); } } return 0; }