#include using namespace std; int H,W; vector> A; int dx[] = {0,1,0,-1}; int dy[] = {1,0,-1,0}; void drop(int r,int c,int q){ if(A[r][c] != q)A[r][c] = q; else return; for(int i=0;i<4;i++){ int nr = r + dy[i]; int nc = c + dx[i]; if(nr<0 || nc<0 || nr>=H || nc>=W)continue; if(A[nr][nc] == q)continue; drop(nr, nc, q); } } int main(void){ cin >> H >> W; A = vector>(H,vector(W)); for(int i=0;i> A[i][j]; } } int Q; cin >> Q; for(int i=0;i> r >> c >> q; r--;c--; drop(r,c,q); } for(int i=0;i