#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; const int N = 1010, M = 30005; typedef long long ll; int n,a[N][N],m,q,han[N],lie[N],hanadd[N],lieadd[N],fx[N],f[N]; int main() { int T; scanf("%d",&T); 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++) { han[i] = i;f[i] =i; hanadd[i] = 0; } for(int i=1;i<=m;i++) { lie[i] = i;fx[i] = i; lieadd[i] = 0; } for(int i=1;i<=q;i++) { int op,x,y; scanf("%d%d%d",&op,&x,&y); if(op == 1) { f[x] = han[y]; f[y] = han[x]; swap(han[x],han[y]); } else if(op == 2) { fx[x] = lie[y]; fx[y] = lie[x]; swap(lie[x],lie[y]); } else if(op == 3) { hanadd[han[x]]+=y; } else lieadd[lie[x]]+=y; } for(int i=1;i<=n;i++) { int j; for(j=1;j