#include #include #include using namespace std; #define REP(i, n) for(int i = 0; i < n; i++) int w = 0; int h = 0; vector > v; int dx[] = {1, 0, -1, 0}; int dy[] = {0, 1, 0, -1}; void paint(int cx, int cy, int q) { if(v[cy][cx] == q) return; v[cy][cx] = q; REP(i, 4) { int tx = cx + dx[i]; int ty = cy + dy[i]; if(tx < 0 || tx >= w || ty < 0 || ty >= h) continue; paint(tx, ty, q); } } int main(void) { cin >> h; cin >> w; v.resize(h); REP(i, h) REP(j, w) { int p; cin >> p; v[i].push_back(p); } int n; cin >> n; REP(i, n) { int r, c, x; cin >> r >> c >> x; r--; c--; paint(c, r, x); } REP(i, h) { REP(j, w) { cout << v[i][j]; if(j < w - 1) cout << " "; } cout << endl; } return 0; }