#include #include using namespace std; void print(int p) { printf("%d\n", p); } void print(long long p) { printf("%I64d\n", p); } void print(double p) { printf("%f\n", p); } void print(char p) { printf("%c\n", p); } void print(char* p) { printf("%s\n", p); } int len(char* p) { return strlen(p); } int gcd(int x, int y) { return y ? gcd(y, x % y) : x; } int lcm(int x, int y) { return x * (y / gcd(x, y)); } int n, m, q; int T; int a, b; long long nums[1050][1050]; int whox[2000]; int whoy[2000]; long long addtox[2000]; long long addtoy[2000]; int type; int main() { scanf("%d", &T); while (T--) { scanf("%d%d%d", &n, &m, &q); for (int i = 0; i <= n; i++) { whoy[i] = i; addtoy[i] = 0; } for (int i = 0; i <= m; i++) { whox[i] = i; addtox[i] = 0; } for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { scanf("%I64d", &nums[i][j]); } } for (int i = 0; i < q; i++) { scanf("%d", &type); if (type == 1) { scanf("%d%d", &a, &b); swap(whoy[a], whoy[b]); } else if (type == 2) { scanf("%d%d", &a, &b); swap(whox[a], whox[b]); } else if (type == 3) { scanf("%d%d", &a, &b); addtoy[whoy[a]] += b; } else if (type == 4) { scanf("%d%d", &a, &b); addtox[whox[a]] += b; } } for (int i = 1; i <= n; i++) { long long * nowy = nums[whoy[i]]; for (int j = 1; j <= m; j++) { if (j != 1) printf(" "); printf("%I64d", nowy[whox[j]] + addtoy[whoy[i]] + addtox[whox[j]]); } printf("\n"); } } return 0; }