#include #define int long long //#define USE_FREOPEN //#define MUL_TEST #define FILENAME "tetris" using namespace std; void solve() { int h, w, n; cin >> h >> w >> n; vector a(w); for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { char c; cin >> c; if (c == '#') a[x]++; } } vector c(n); vector > cid(w - 2); for (int i = 0; i < n; i++) { cin >> c[i]; cid[c[i]].push_back(i); } vector > b(n); for (int x = 0; x < w - 2; x++) { for (auto i : cid[x]) { for (int dx = 0; dx < 3; dx++) { if (a[x + dx]) { a[x + dx]--; b[i][dx]++; break; } } } } for (int x = 0; x < w; x++) { for (int dx = 0; dx < 3; dx++) { if (0 <= x - dx && x - dx < w - 2) { for (auto i : cid[x - dx]) { while (a[x] && b[i][dx] < 3) { a[x]--; b[i][dx]++; } } } } } for (auto it : b) { for (int y = 0; y < 3; y++) { for (int x = 0; x < 3; x++) { cout << ((2 - y < it[x]) ? '#' : '.'); } cout << '\n'; } } } signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); #ifdef USE_FREOPEN freopen(FILENAME ".in", "r", stdin); freopen(FILENAME ".out", "w", stdout); #endif int _ = 1; #ifdef MUL_TEST cin >> _; #endif while (_--) solve(); _^=_; return 0^_^0; }