uses
	testlib, sysutils;

const
	maxn = 500;

var
	js, ps: string;
	m, i, n: longint;
	x, y: array [1..maxn] of longint;
	t: array [1..maxn] of longint;
	cnt: array [1..maxn] of longint;
	ind: array [1..maxn, 1..3] of longint;

function nei(i, j: longint): boolean;
begin
	nei := 
		((y[i] = y[j]) and (abs(x[i] - x[j]) = 1)) or
		((y[i] = y[j] + 1) and (x[i] mod 2 = 0) and (x[i] + y[i] = x[j] + y[j])) or
		((y[j] = y[i] + 1) and (x[j] mod 2 = 0) and (x[i] + y[i] = x[j] + y[j]));
end;

begin
	js := ans.readstring;
	ps := ouf.readstring;

	if ps = 'No solution' then begin
		if js = 'No solution' then
			quit(_ok, 'No solution');
		quit(_wa, 'No solution unexpected');
	end;

	ouf.reset;

	n := inf.readlongint;
	for i := 1 to n do begin
		x[i] := inf.readlongint;
		y[i] := inf.readlongint;
	end;

	m := ouf.readlongint;
	if (m < 0) or (m > n div 2) then begin
		quit(_wa, 'wrong count of tiles');
	end;

	for i := 1 to n do begin
		t[i] := ouf.readlongint;
		if (t[i] < 1) or (t[i] > m) then
			quit(_wa, format('invalid tile number: %d', [t[i]]));
		if cnt[t[i]] = 3 then
			quit(_wa, format('tile %d has more than 3 triangles', [t[i]]));
		inc(cnt[t[i]]);

		ind[t[i]][cnt[t[i]]] := i;
	end;

	for i := 1 to m do begin
		if (cnt[i] <> 2) and (cnt[i] <> 3) then begin
			quit(_wa, format('tile %d has %d triangles', [i, cnt[i]]));
		end;

		if cnt[i] = 2 then begin
			if not nei(ind[i][1], ind[i][2]) then
				quit(_wa, format('triangles that form tile %d are not neighbours', [i]));
		end else begin
			if ord(nei(ind[i][1], ind[i][2])) + ord(nei(ind[i][1], ind[i][3])) + ord(nei(ind[i][2], ind[i][3])) <> 2 then
				quit(_wa, format('triangles that form tile %d are not neighbours', [i]));
		end;
	end;

	if js = 'No solution' then
		quit(_fail, 'No solution expected');

	quit(_ok, '');
end.