uses
	testlib, sysutils;

const
	maxn = 200;

var
	i, j, k, n: longint;
	s, z: array [1..maxn] of string;
	pa: string;
	found: boolean;

function circular(a, b: string): boolean;
var
	i: longint;
begin
	for i := 1 to length(a) do begin
		if a = copy(b, i, length(b) - i + 1) + copy(b, 1, i - 1) then begin
			circular := true;
			exit;
		end;
	end;
	circular := false;
end;

begin
	n := inf.readlongint;
	inf.nextline;

	for i := 1 to n do begin
		s[i] := inf.readstring;
	end;

	pa := ouf.readstring;
	if (pa <> 'Yes') and (pa <> 'No') then
		quit(_pe, 'Yes or No expected, "' + pa + '" found');
	if pa = 'No' then
		quit(_wa, 'No unexpected');

	for i := 1 to n do begin
		z[i] := ouf.readstring;
		if length(z[i]) <> n then
			quit(_wa, format('Line %d: invalid length', [i]));
		if not circular(s[i], z[i]) then
			quit(_wa, format('Line %d: "%s" cannot be obtained from "%s"', [i, z[i], s[i]]));
	end;

	for i := 1 to n do begin
		for j := i + 1 to n do begin
			found := false;
			for k := 1 to n do begin
				if z[k][i] <> z[k][j] then begin
					found := true;
					break;
				end;
			end;
			if not found then
				quit(_wa, format('columns %d and %d are the same', [i, j]));
		end;
	end;

	quit(_ok, '');
end.