#include #include #include #include #include #include #include #include #include #include #include #define lson l , m , rt << 1 #define rson m + 1 , r , rt << 1 | 1 #define ll long long #define ull unsigned long long using namespace std; const int inf = 0x3f3f3f3f; const int M = 1002; int r[M], c[M], rp[M], cp[M]; int a[M][M], ans[M][M]; int main(){ //freopen("input.txt", "r", stdin); int t; scanf("%d", &t); while(t--){ memset(r, 0, sizeof(r)); memset(c, 0, sizeof(c)); int m, n, q; scanf("%d%d%d", &m, &n, &q); for(int i = 1; i <= m; i++){ for(int j = 1; j <= n; j++){ scanf("%d", &a[i][j]); } } for(int i = 1; i <= m; i++) rp[i] = i; for(int j = 1; j <= n; j++) cp[j] = j; int op, x, y; for(int num = 0; num < q; num++){ scanf("%d%d%d", &op, &x, &y); if(op == 1){ int tmp = r[x]; r[x] = r[y]; r[y] = tmp; tmp = rp[x]; rp[x] = rp[y]; rp[y] = tmp; } else if(op == 2){ int tmp = c[x]; c[x] = c[y]; c[y] = tmp; tmp = cp[x]; cp[x] = cp[y]; cp[y] = tmp; } else if(op == 3){ r[x] += y; } else if(op == 4){ c[x] += y; } } for(int i = 1; i <= m; i++){ int rr = rp[i]; for(int j = 1; j <= n; j++){ int cc = cp[j]; ans[i][j] = a[rr][cc] + r[i] + c[j]; } } for(int i = 1; i <= m; i++){ for(int j = 1; j < n; j++){ printf("%d ", ans[i][j]); } printf("%d\n", ans[i][n]); } } return 0; }