import java.util.ArrayList;
import java.util.Arrays;

import ru.ifmo.testlib.InStream;
import ru.ifmo.testlib.Outcome;
import static ru.ifmo.testlib.Outcome.Type.*;
import static ru.ifmo.testlib.Outcome.*;



public class Check implements ru.ifmo.testlib.Checker {

	@Override
	public Outcome test(InStream inf, InStream ouf, InStream ans) {
		int k = inf.nextInt();
		int[] a = new int[k];
		b = new int[k];
		for (int i = 0; i < k; i++) {
			a[i] = inf.nextInt();
			b[i] = inf.nextInt();
		}
		int n = inf.nextInt();
		c = new int[n];
		for (int i = 0; i < n; i++) {
			c[i] = inf.nextInt();
		}
		String pans = ouf.nextToken();
		if (!"Yes".equals(pans) && !"No".equals(pans)) {
			quit(PE, "'Yes' or 'No' expected, '%s' found", pans);
		}
		String jans = ans.nextToken();
		if (!jans.equals(pans)) {
			quit(WA, "%s expected, %s found", jans, pans);
		}
		if ("No".equals(pans)) {
			quit(OK, "No solution");
		}
		int[] f = new int[k];
		out = new int[k];
		Arrays.fill(out, -1);
		int first = -1; 
		for (int i = 0; i < k; i++) {
			f[i] = ouf.nextInt();
			if (f[i] == 0) {
				if (first != -1) {
					quit(WA, "Two filters are connected to the socket");
				}
				first = i;
			} else if (f[i] > 0) {
				if (f[i] > k) {
					quit(WA, "Filter number %d is connected to non-existent filter number %d", (i + 1), f[i]);
				}
				if (out[f[i] - 1] != -1) {
					quit(WA, "Two filters are connected to filter number " + f[i]);
				}
				out[f[i] - 1] = i;
			} else if (f[i] != -1) {
				quit(WA, "Filter number %d is connected to %d", (i + 1), f[i]);
			}
		}
		boolean oneDevice = false;
		int[] d = new int[n];
		rd = new ArrayList[k];
		for (int i = 0; i < k; i++) {
			rd[i] = new ArrayList<Integer>();
		}
		for (int i = 0; i < n; i++) {
			d[i] = ouf.nextInt();
			if (d[i] == 0) {
				if (first != -1) {
					quit(WA, "Filter and device or two devices are connected to the socket");
				}
				oneDevice = true;
				first = i;
			} else {
				if (d[i] > k || d[i] < 0) {
					quit(WA, "Device number %d is connected to non-existent filter number %d", (i + 1), d[i]);
				}
				if (rd[d[i] - 1].size() + (out[d[i] - 1] != -1 ? 1 : 0) + 1 > a[d[i] - 1]) {
					quit(WA, "Too many devices are connected to filter number " + d[i]);
				}
				rd[d[i] - 1].add(i);
			}
		}
		if (first == -1) {
			quit(WA, "Nothing is connected to the socket");
		}
		// К розетке что-то подключено
		if (oneDevice) { // Случай, если это единственное устройство
			if (n > 1) {
				quit(WA, "Some devices are not connected to electricity");
			}
			for (int i = 0; i < k; i++) {
				if (f[i] != -1) {
					quit(WA, "Some filters are connected, but not to the main network");
				}
			}
			quit(OK, "OK");
		}
		// К розетке подключен пилот
		uf = new boolean[k];
		ud = new boolean[n];
		dfs(first);
		for (int i = 0; i < n; i++) {
			if (!ud[i]) {
				quit(WA, "Device number %d is not connected to the main network", (i + 1));
			}
		}
		for (int i = 0; i < k; i++) {
			if (!uf[i] && f[i] != -1) {
				quit(WA, "Pilot number is not connected to electricity");
			}
		}
		quit(OK, "OK");
		return null;
	}
	
	boolean[] uf, ud;
	ArrayList<Integer>[] rd;
	int[] out, b, c;
	
	private long dfs(int i) {
		uf[i] = true;
		long sum = 0;
		for (int j : rd[i]) {
			ud[j] = true;
			sum += c[j];
		}
		if (out[i] != -1) {
			sum += dfs(out[i]);
		}
		if (sum > b[i]) {
			quit(WA, "Too big load on filter number " + (i + 1));
		}
		if (sum == 0) {
			quit(WA, "Nothing is connected to the filter number " + (i + 1));
		}
		return sum;
	}

}
