#include using namespace std; using ll = long long; using pii = pair; template using V = vector; template using VV = V>; #define pb push_back #define eb emplace_back #define mp make_pair #define fi first #define se second #define rep(i, n) rep2(i, 0, n) #define rep2(i, m, n) for (int i = m; i < (n); i++) #define per(i, b) per2(i, 0, b) #define per2(i, a, b) for (int i = int(b) - 1; i >= int(a); i--) #define ALL(c) (c).begin(), (c).end() constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); } template void chmin(T& t, const U& u) { if (t > u) t = u; } template void chmax(T& t, const U& u) { if (t < u) t = u; } template ostream& operator<<(ostream& os, const pair& p) { os << "(" << p.first << "," << p.second << ")"; return os; } template ostream& operator<<(ostream& os, const vector& v) { os << "{"; rep(i, v.size()) { if (i) os << ","; os << v[i]; } os << "}"; return os; } #ifdef LOCAL void debug_out() { cerr << endl; } template void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...); } #define debug(...) \ cerr << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl #else #define debug(...) (void(0)) #define dump(x) (void(0)) #endif struct FordFulkerson { static constexpr int INF = TEN(9); struct edge { int to, cap, rev; }; int n; VV g; V used; FordFulkerson(int n) : n(n), g(n), used(n) {} void add_edge(int from, int to, int cap, int rcap) { g[from].push_back((edge){to, cap, (int)g[to].size()}); g[to].push_back((edge){from, rcap, (int)g[from].size() - 1}); } int dfs(int v, int t, int f) { if (v == t) return f; used[v] = true; for (auto& e : g[v]) { if (!used[e.to] && e.cap > 0) { int d = dfs(e.to, t, min(f, e.cap)); if (d > 0) { e.cap -= d; g[e.to][e.rev].cap += d; return d; } } } return 0; } int max_flow(int s, int t) { int flow = 0; while (1) { fill(used.begin(), used.end(), false); int f = dfs(s, t, INF); if (f == 0) return flow; flow += f; } } }; int state[2010][2010]; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int H, W; cin >> H >> W; V A(H), B(W), ga, gb; rep(i, H) cin >> A[i]; rep(i, W) cin >> B[i]; ga = A, gb = B; ll s1 = 0, s2 = 0; rep(i, H) s1 += A[i]; rep(i, W) s2 += B[i]; if (s1 != s2) { cout << ":(" << endl; return 0; } { V xid(H); iota(ALL(xid), 0); sort(ALL(xid), [&](int a, int b) { return A[a] > A[b]; }); for (int x : xid) { V yid(W); iota(ALL(yid), 0); sort(ALL(yid), [&](int a, int b) { return B[a] > B[b]; }); int p = 0; while (A[x]) { if (B[yid[p]] == 0) { cout << ":(" << endl; return 0; } state[x][yid[p]] = 1; B[yid[p]]--; p++; A[x]--; } } } V ans(H, string(W, '.')); int K; cin >> K; int dec = 0; rep(i, K) { int x, y; cin >> x >> y; --x, --y; if (state[x][y] == 1) { A[x]++; B[y]++; dec++; } state[x][y] = -1; ans[x][y] = 'x'; } int node_cnt = H + W + 2; int s = node_cnt - 2, t = node_cnt - 1; FordFulkerson flow(node_cnt); rep(i, H) flow.add_edge(s, i, A[i], ga[i] - A[i]); rep(j, W) flow.add_edge(H + j, t, B[j], gb[j] - B[j]); rep(i, H) { rep(j, W) { if (state[i][j] != -1) { flow.add_edge(i, j + H, 1 - state[i][j], state[i][j]); } } } auto fl = flow.max_flow(s, t); if (fl != dec) { cout << ":(" << endl; return 0; } rep(i, H) { for (auto e : flow.g[i]) { if (e.to >= H && e.to < H + W && state[i][e.to - H] != -1 && e.cap == 0) { ans[i][e.to - H] = 'o'; } } } cout << "Yay!" << endl; rep(i, H) cout << ans[i] << '\n'; return 0; }