#include #include #include using namespace std; const int maxn = 1000+10; int b[maxn][maxn], hang[maxn], lie[maxn], addhang[maxn], addlie[maxn], map[maxn][maxn]; int main(){ int T; scanf("%d", &T); while(T--){ int n, m, q; scanf("%d%d%d", &n, &m, &q); memset(b, 0, sizeof(b)); memset(addhang, 0, sizeof(addhang)); memset(addlie, 0, sizeof(addlie)); for(int i = 1; i <= n; i++) for(int j = 1; j <= m; j++) scanf("%d", &b[i][j]); for(int i = 1; i <= n; i++) hang[i] = i; for(int i = 1; i <= m; i++) lie[i] = i; for(int i = 0; i < q; i++){ int a, x, y; scanf("%d%d%d", &a, &x, &y); switch(a){ case 1: swap(hang[x], hang[y]); break; case 2: swap(lie[x], lie[y]); break; case 3: addhang[hang[x]] += y; break; case 4: addlie[lie[x]] += y; break; } } for(int i = 1; i <= n; i++){ for(int j = 1; j <= m; j++){ map[i][j] = b[hang[i]][lie[j]] + addhang[hang[i]] + addlie[lie[j]]; } } for(int i = 1; i <= n; i++){ printf("%d", map[i][1]); for(int j = 2; j <= m; j++){ printf(" %d", map[i][j]); } printf("\n"); } } return 0; }