program DIALOGUE_CHECK;
uses
  testlib;

const
  maxn = 1000;

var
  wa: boolean;
  wm: string;
  finf: array[1..maxn] of string[12];
  n, i: longint;
  kouf, kans: longint;
  souf, sans: string;
  j: integer;
  ok: boolean;

begin
  wa:= false;

  n:= inf.readLongint;
  inf.nextline;
  for i:= 1 to n do
    finf[i]:= inf.readString;

  kouf:= ouf.readLongint; ouf.nextLine;
  kans:= ans.readLongint; ans.nextLine;

  if kouf <> kans then begin
    wa:= true;
    wm:= 'Wrong answer size: ';
  end;

  for i:= 1 to kouf do begin
    souf:= ouf.readString;
    sans:= ans.readString;

    ok:= false;
    for j:= 1 to n do
      if souf = finf[j] then begin
        ok:= true;
        break;
      end;
    if not ok then
      Quit(_PE, 'Not a file name: ' + souf);

    if not wa and (souf <> sans) then begin
      wa:= true;
      wm:= 'Wrong answer: ' + souf + ' <> ' + sans;
    end;
  end;

  if not ouf.seekeof then Quit(_PE, 'Extra data in file');
  if wa then Quit(_WA, wm);
  Quit(_OK, 'Ok');
end.