#include #define rep(i,a,n) for(int i=a;i=b;i--) #define all(a) a.begin(),a.end() #define o(a) cout< vi; typedef vector vvi; typedef pair pii; int a[210][210]; int dy[4]={1,-1,0,0}; int dx[4]={0,0,1,-1}; int h,w,q; bool f[210][210]; void dfs(int r,int c,int color,int x){ f[r][c]=true; a[r][c]=x; rep(i,0,4){ int ny=r+dy[i]; int nx=c+dx[i]; if(0<=ny && ny>h>>w; rep(i,0,h) rep(j,0,w) cin>>a[i][j]; cin>>q; rep(i,0,q){ int r,c,x; cin>>r>>c>>x; r--; c--; int color=a[r][c]; rep(i,0,h) rep(j,0,w) f[i][j]=false; dfs(r,c,color,x); } rep(i,0,h){ rep(j,0,w){ cout<<(j?" ":"")<