import std.conv, std.functional, std.range, std.stdio, std.string; import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons; import core.bitop; class EOFException : Throwable { this() { super("EOF"); } } string[] tokens; string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; } int readInt() { return readToken.to!int; } long readLong() { return readToken.to!long; } real readReal() { return readToken.to!real; } bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } } bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } } int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; } int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); } int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); } int H, W; int[] A, B; int K; int[] X, Y; char[][] ans; int[] prev0, prev1; void dfs0(int x) { foreach (y; 0 .. W) { if (ans[x][y] == '.') { if (prev1[y] == -1) { prev1[y] = x; dfs1(y); } } } } void dfs1(int y) { foreach (x; 0 .. H) { if (ans[x][y] == 'o') { if (prev0[x] == -1) { prev0[x] = y; dfs0(x); } } } } bool solve() { ans = new char[][](H, W); foreach (x; 0 .. H) { ans[x][] = '.'; } auto axs = new Tuple!(int, int)[H]; foreach (x; 0 .. H) { axs[x] = tuple(A[x], x); } axs.sort; auto bs = B.dup; foreach_reverse (ax; axs) { const x = ax[1]; auto yss = new int[][H + 1]; foreach (y; 0 .. W) { yss[bs[y]] ~= y; } int a = A[x]; foreach_reverse (b; 1 .. H + 1) { foreach (y; yss[b]) { if (a > 0) { ans[x][y] = 'o'; --a; --bs[y]; } } } if (a != 0) { return false; } } if (!bs.all!"a == 0") { return false; } debug { writeln("ans = ", ans); } prev0 = new int[H]; prev1 = new int[W]; foreach (k; 0 .. K) { if (ans[X[k]][Y[k]] == 'o') { ans[X[k]][Y[k]] = 'x'; prev0[] = -1; prev1[] = -1; dfs0(X[k]); if (prev1[Y[k]] == -1) { return false; } for (int y = Y[k]; ; ) { const x = prev1[y]; ans[x][y] = 'o'; if (x == X[k]) { break; } y = prev0[x]; ans[x][y] = '.'; } } else { ans[X[k]][Y[k]] = 'x'; } } return true; } void main() { try { for (; ; ) { H = readInt(); W = readInt(); A = new int[H]; foreach (x; 0 .. H) { A[x] = readInt(); } B = new int[W]; foreach (y; 0 .. W) { B[y] = readInt(); } K = readInt(); X = new int[K]; Y = new int[K]; foreach (k; 0 .. K) { X[k] = readInt() - 1; Y[k] = readInt() - 1; } const res = solve(); if (res) { writeln("Yay!"); foreach (x; 0 .. H) { writeln(ans[x]); } } else { writeln(":("); } } } catch (EOFException e) { } }