#include using namespace std; #define _p(...) (void)printf(__VA_ARGS__) #define forr(x,arr) for(auto&& x:arr) #define _overload3(_1,_2,_3,name,...) name #define _rep2(i,n) _rep3(i,0,n) #define _rep3(i,a,b) for(int i=int(a);i=int(a);i--) #define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2,)(__VA_ARGS__) #define all(x) (x).begin(), (x).end() #define bit(n) (1LL<<(n)) #define sz(x) ((int)(x).size()) #define fst first #define snd second using ll=long long;using pii=pair; using vb=vector;using vs=vector; using vi=vector;using vvi=vector;using vvvi=vector; using vl=vector;using vvl=vector;using vvvl=vector; using vd=vector;using vvd=vector;using vvvd=vector; using vpii=vector;using vvpii=vector;using vvvpii=vector; templateT read(){T t;cin>>t;return t;} templateostream&operator<<(ostream&o,const pair&p){o<<'('<(); int w = read(); int n = read(); vs B; rep(i, h) B.emplace_back(read()); vi C(n); vvi T(w); rep(i, n) { int c = C[i] = read(); T[c+0].push_back(i); T[c+1].push_back(i); T[c+2].push_back(i); } vi V(w); rep(j, w) while (V[j] < h && B[h-1-V[j]][j] == '#') V[j]++; vi cnt(n); vvi ans(n, vi(3)); rep(j, w) { int v = V[j]; vector> S; forr(t, T[j]) { int a = cnt[t]; int c = C[t]; S.emplace_back(a, c, t); } sort(all(S)); int m = sz(S); int div = v / m; int rem = v % m; rep(i, m) { int idx = get<2>(S[i]); cnt[idx] += div; ans[idx][j-C[idx]] += div; if (i < rem) { cnt[idx]++; ans[idx][j-C[idx]]++; } } } rep(i, n) { rep(y, 3) { if (ans[i][0] > y) cout << '#'; else cout << '.'; if (ans[i][1] > y) cout << '#'; else cout << '.'; if (ans[i][2] > y) cout << '#'; else cout << '.'; cout << endl; } } } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); Main(); return 0; }