{$APPTYPE CONSOLE}
uses testlib;

var
  pa:LongInt;
  njury,i:LongInt;
  first,second: Array [1..10] of LongInt;

Begin
  njury:=ans.ReadLongint;
  for i:=1 to njury do begin
    first[i]:=ans.ReadLongint;
    second[i]:=ans.ReadLongint;
  end;
  pa:=ouf.readlongint;

  if (pa < 0) or (pa > 3) then Quit(_PE,'wrong word at tht begin of the output');
  if (pa > 0) and (njury=0) then Quit(_WA,'jury can not split trees');
  if (pa = 0) and (njury>0) then Quit(_WA,'jury can split trees');
  if (pa = 0) and (njury=0) then Quit(_OK,'it is really impossible');
  assert(pa > 0);
  for i:=1 to njury do
    if (first[i] <> pa) and (second[i] <> pa) then
        Quit(_OK,'it is really possible');
  Quit(_WA,'no such pair of trees');
End.
