#include using namespace std; template struct EKarp { int n; vector> capacity; vector> adj; EKarp(int _n) : n(_n), capacity(_n, vector(_n)), adj(_n) {} void addEdge(T w, int u, int v) { adj[u].push_back(v); adj[v].push_back(u); capacity[u][v] += w; } T bfs(int s, int t, vector &parent) { fill(parent.begin(), parent.end(), -1); parent[s] = -2; queue> que; que.push({ s, INF }); while (que.size()) { auto [cur, flow] = que.front(); que.pop(); for (int nxt : adj[cur]) { if (parent[nxt] == -1 && capacity[cur][nxt]) { parent[nxt] = cur; T nflow = min(flow, capacity[cur][nxt]); if (nxt == t) return nflow; que.push({ nxt, nflow }); } } } return (T) 0; } T maxflow(int s, int t) { T flow = 0; vector parent(n); T nflow; while (nflow = bfs(s, t, parent)) { flow += nflow; int cur = t; while (cur != s) { int pre = parent[cur]; capacity[pre][cur] -= nflow; capacity[cur][pre] += nflow; cur = pre; } } return flow; } }; int main() { ios::sync_with_stdio(false); int H, W; { cin >> H >> W; } vector A(H); { for (int i = 0; i < H; ++i) cin >> A[i]; } vector B(W); { for (int i = 0; i < W; ++i) cin >> B[i]; } int K; { cin >> K; } vector X(K), Y(K); { for (int i = 0; i < K; ++i) cin >> X[i] >> Y[i], --X[i], --Y[i]; } set> badBag; { for (int i = 0; i < K; ++i) badBag.emplace(X[i], Y[i]); } EKarp ekarp(H + W + 2); { for (int i = 0; i < H; ++i) ekarp.addEdge(A[i], H + W, i); for (int i = 0; i < W; ++i) ekarp.addEdge(B[i], H + i, H + W + 1); for (int i = 0; i < H; ++i) { for (int j = 0; j < W; ++j) { int w = !badBag.count(make_pair(i, j)); ekarp.addEdge(w, i, H + j); } } } int mf = ekarp.maxflow(H + W, H + W + 1); int sumA = accumulate(A.begin(), A.end(), 0); int sumB = accumulate(B.begin(), B.end(), 0); if (mf != max(sumA, sumB)) { cout << ":(" << endl; } else { cout << "Yay!" << endl; vector res(H, string(W, '.')); { for (int i = 0; i < K; ++i) { res[X[i]][Y[i]] = 'x'; } for (int i = 0; i < H; ++i) { for (int j = 0; j < W; ++j) { if (ekarp.capacity[H + j][i] == 1) res[i][j] = 'o'; } } } for (int i = 0; i < H; ++i) cout << res[i] << "\n"; } }