#include #include #include using namespace std; #define M 1111 int add_row[M], add_col[M], row[M], col[M]; int a[M][M]; void read(int &x) { x = 0; char c = getchar(); while (c < '0' || c > '9') c = getchar(); while (c >= '0' && c <= '9') x = 10 * x + c - '0', c = getchar(); } int main() { //freopen("1001.in", "r", stdin); int T, n, m, Q, type, x, y; for (scanf("%d", &T); T--; ) { read(n); read(m); read(Q); for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) read(a[i][j]); for (int i = 1; i <= n; i++) { add_row[i] = 0; row[i] = i; } for (int i = 1; i <= m; i++) { add_col[i] = 0; col[i] = i; } while (Q--) { scanf("%d %d %d", &type, &x, &y); if (type == 1) { swap(row[x], row[y]); swap(add_row[x], add_row[y]); } else if (type == 2) { swap(col[x], col[y]); swap(add_col[x], add_col[y]); } else if (type == 3) { add_row[x] += y; } else { add_col[x] += y; } } for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) a[row[i]][col[j]] += add_row[i] + add_col[j]; } for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) printf("%d%c", a[row[i]][col[j]], (j == m) ? '\n' : ' '); } } }