#include using namespace std; #define int long long const int N = 30010; int h, w, n, res[N][3]; vector > a; vector > ha[N]; bool cmp (pair a, pair b) { int i = a.first, j = b.first; return res[i][0] + res[i][1] + res[i][2] < res[j][0] + res[j][1] + res[j][2]; } signed main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> h >> w >> n; a.resize(h); for (int i = 0; i < h; i ++ ) { a[i].resize(w); for (int j = 0; j < w; j ++ ) cin >> a[i][j]; } for (int i = 1, x; i <= n; i ++ ) { cin >> x; ha[x].push_back({i, 0}); ha[x + 1].push_back({i, 1}); ha[x + 2].push_back({i, 2}); } for (int i = 0; i < w; i ++ ) { int s = ha[i].size(); if (s == 0) continue; sort(ha[i].begin(), ha[i].end(), cmp); int tot = 0; for (int j = 0; j < h; j ++ ) tot += a[j][i] != '.'; for (int j = 0; j < tot % s; j ++ ) res[ha[i][j].first][ha[i][j].second] = tot / s + 1; for (int j = tot % s; j < s; j ++ ) res[ha[i][j].first][ha[i][j].second] = tot / s; } for (int i = 1; i <= n; i ++ ) for (int x = 0; x < 3; x ++ , cout << "\n") for (int y = 0; y < 3; y ++ ) if (x <= res[i][y] - 1) cout << '#'; else cout << "."; return 0; }