uses
  testlib, SysUtils;

function changeCase(s : string) : string;
begin
	result := copy(s, 1, length(s));
	if (ord('a') <= ord(result[1])) and (ord(result[1]) <= ord('z')) then
		result[1] := chr(ord(result[1]) + ord('A') - ord('a'))
	else
		result[1] := chr(ord(result[1]) + ord('a') - ord('A')); 
end;

var
  ja, pa, s: string;
  i, n, j, k, l : longint;
  cc, ic : array[1..50] of string;

	function compare(const js, ps : string) : boolean;
	var
		i, j : longint;
		tjs, tps : string;
		fw : boolean;
	begin
		result := false;
		if (length(ps) <> length(js)) then	exit;	
		i := 1;
		while (i <= length(ps)) do begin
			fw := false;
			for j := 1 to n do begin
				if (i + length(cc[j]) - 1 <= length(js)) then begin
					tjs := copy(js, i, length(cc[j]));
					if (tjs = cc[j]) or (tjs = ic[j]) then begin
						tps := copy(ps, i, length(cc[j]));
						if (tps = cc[j]) or (tps = ic[j]) then begin
							i := i + length(tjs);
							fw := true;
						end;
					end;
				end;
				if (fw) then break;
			end;
			if (fw) then continue;
			if (js[i] <> ps[i]) then exit;
			inc(i);
		end;
		result := true;
	end;

begin 
  n := inf.readInteger;
  inf.readString();
  for i := 1 to n do begin
  	s := inf.readString();
  	cc[i] := '[[' + s + '|';
  	ic[i] := '[[' + changeCase(s)  + '|';
  	j := inf.readInteger();
  	for k := 0 to j do inf.readString();
  	j := inf.readInteger();
  	for k := 0 to j do inf.readString();
  end;

  l := 0;
  while (not ans.eof) and (not ans.eof) do begin
  	inc(l);
  	ja := ans.readString();
  	pa := ouf.readString();
  	if (not compare(ja, pa)) then quit(_wa, 'At line ' + inttostr(l) + ': expected: "' + ja + '", found: "' + pa + '"');
  end;

  if ouf.seekEof and not ans.seekEof then
    quit(_wa, 'Not enough lines! "' + ans.readString + '" expected' );
  if ans.seekEof and not ouf.seekEof then
    quit(_wa, 'Extra lines! "' + ouf.readString + '" encountered' );
  quit( _ok, 'Ok' );
end.