#include #include #include typedef long long ll; using namespace std; const int M=1010; int cas,n,m,q,i,j,opt,x,y; int b[M],c[M]; ll a[M][M],B[M],C[M]; int main(){ scanf("%d",&cas); while (cas--){ scanf("%d%d%d",&n,&m,&q); for (i=1;i<=n;i++) for (j=1;j<=m;j++)scanf("%I64d",&a[i][j]); for (i=1;i<=n;i++)b[i]=i; for (i=1;i<=m;i++)c[i]=i; memset(B,0,sizeof B); memset(C,0,sizeof C); while (q--){ scanf("%d%d%d",&opt,&x,&y); if (opt==1)swap(b[x],b[y]); if (opt==2)swap(c[x],c[y]); if (opt==3)B[b[x]]+=y; if (opt==4)C[c[x]]+=y; } for (i=1;i<=n;i++){ for (j=1;j