{$apptype console}
{$o-,r+,q+}
uses
  SysUtils, TestLib;

const
  MAX_SIZE = 100000;

type
  int = longint;

var
  n, m: int;
  s, t: array[1..MAX_SIZE] of int;
  i: int;
  ansj, ansp: int;
  distp, distj: int;

begin
  n := inf.readInteger;
  for i := 1 to n do
  begin
    s[i] := inf.readInteger;
  end;
  m := inf.readInteger;
  for i := 1 to m do
  begin
    t[i] := inf.readInteger;
  end;
  for i := 1 to n do
  begin
    ansj := ans.readInteger;
    ansp := ouf.readInteger;
    if (ansp < 1) or (ansp > m) then
    begin
      quit(_wa, 'Expected number from 1 to ' + inttostr(m) + ', found: ' + inttostr(ansp));
    end;
    distj := abs(s[i] - t[ansj]);
    distp := abs(s[i] - t[ansp]);
    if (distp < distj) then
    begin
      quit(_fail, 'Participant has better answer for city #' + inttostr(i) + ': ' + inttostr(distp) + ' < ' + inttostr(distj));
    end else if (distp > distj) then
    begin
      quit(_wa, 'Jury has better answer for city #' + inttostr(i) + ': ' + inttostr(distp) + ' > ' + inttostr(distj));
    end;
  end;
  quit(_ok, 'n = ' + inttostr(n) + ', m = ' + inttostr(m));
end.
