#include using namespace std; #define ii pair #define app push_back #define all(a) a.begin(), a.end() #define bp __builtin_popcountll #define ll long long #define mp make_pair #define f first #define s second #define Time (double)clock()/CLOCKS_PER_SEC #define debug(x) std::cout << #x << ": " << x << '\n'; #define pb push_back struct Dinic{ struct edge{ int to, flow, cap; }; const static int N = 5007; //count of vertices vector e; vector g[N + 7]; int dp[N + 7]; int ptr[N + 7]; void clear(){ for (int i = 0; i < N + 7; i++) g[i].clear(); e.clear(); } void addEdge(int a, int b, int cap){ g[a].pb(e.size()); e.pb({b, 0, cap}); g[b].pb(e.size()); e.pb({a, 0, 0}); } int minFlow, start, finish; bool bfs(){ for (int i = 0; i < N; i++) dp[i] = -1; dp[start] = 0; vector st; int uk = 0; st.pb(start); while(uk < st.size()){ int v = st[uk++]; for (int to : g[v]){ auto ed = e[to]; if (ed.cap - ed.flow >= minFlow && dp[ed.to] == -1){ dp[ed.to] = dp[v] + 1; st.pb(ed.to); } } } return dp[finish] != -1; } int dfs(int v, int flow){ if (v == finish) return flow; for (; ptr[v] < g[v].size(); ptr[v]++){ int to = g[v][ptr[v]]; edge ed = e[to]; if (ed.cap - ed.flow >= minFlow && dp[ed.to] == dp[v] + 1){ int add = dfs(ed.to, min(flow, ed.cap - ed.flow)); if (add){ e[to].flow += add; e[to ^ 1].flow -= add; return add; } } } return 0; } int dinic(int start, int finish){ Dinic::start = start; Dinic::finish = finish; int flow = 0; for (minFlow = (1 << 30); minFlow; minFlow >>= 1){ while(bfs()){ for (int i = 0; i < N; i++) ptr[i] = 0; while(int now = dfs(start, (int)2e9 + 7)) flow += now; } } return flow; } } d; const int N = 2007; bool ban[N][N]; bool f[N][N]; int num[N][N]; signed main() { #ifdef HOME freopen("input.txt", "r", stdin); #else #define endl '\n' ios_base::sync_with_stdio(0); cin.tie(0); #endif int n, m; cin >> n >> m; vector a(n), b(m); int suma = 0; for (int i = 0; i < n; ++i) { cin >> a[i]; suma += a[i]; } int sumb = 0; for (int i = 0; i < m; ++i) { cin >> b[i]; sumb += b[i]; } if (suma != sumb) { cout << ":(" << endl; exit(0); } const int S = d.N - 2, T = d.N - 1; for (int i = 0; i < n; ++i) { d.addEdge(S, i, a[i]); } for (int i = 0; i < m; ++i) { d.addEdge(i + n, T, b[i]); } int k; cin >> k; for (int i = 0; i < k; ++i) { int x, y; cin >> x >> y; --x; --y; ban[x][y] = 1; } for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { if (!ban[i][j]) { num[i][j] = d.e.size(); d.addEdge(i, j + n, 1); } } } if (d.dinic(S, T) == suma) { cout << "Yay!" << endl; for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { if (ban[i][j]) { cout << 'x'; } else if (d.e[num[i][j]].flow) { cout << 'o'; } else { cout << '.'; } } cout << endl; } } else { cout << ":(" << endl; } }