uses
	testlib, SysUtils;
const
	MAXN = 1000;
var
	n, m, i, x, y, j : integer;
	ansj, ansp : string;
	a : array[1..MAXN, 1..MAXN] of boolean;	
	p : array[1..MAXN] of integer;
	u : array[1..MAXN] of boolean;
begin
	n := inf.readlongint;
	ansp := ouf.readstring;
    ansj := ans.readstring;
    if (ansp <> ansj) then begin
    	quit(_wa, ansj + ' expected, but ' + ansp + ' found');
    end;
    if ((ansp = 'NO') and (ansj = 'NO')) then begin
    	quit(_ok, IntToStr(n) + ' - NO');
    end;
    m := ouf.readlongint;
    if (m <> n * (n - 1) div 4) then begin
    	quit(_wa, IntToStr(n * (n - 1) div 4) + ' edges expected, but ' + IntToStr(m) + ' edges found');
    end;
    fillchar(a, sizeof(a), 0);	
    for i := 1 to m do begin
		x := ouf.readlongint;
		y := ouf.readlongint;
		a[x][y] := true;
		a[y][x] := true;
    end;
    fillchar(u, sizeof(u), 0);	
	for i := 1 to n do begin
		p[i] := ouf.readlongint;
		if (u[p[i]]) then begin
			quit(_wa, 'bad permutation');
		end;
		u[p[i]] := true;
	end;
    for i := 1 to n do begin
    	for j := 1 to n do begin
    		if (i = j) then 
    			continue;
    		if (a[i][j] = a[p[i]][p[j]]) then begin
    			quit(_wa, 'not isomorph: ' + IntToStr(i) + ' ' + IntToStr(j));
    		end;
    	end;
    end;
    quit(_ok, IntToStr(n));
end.