uses crt;
 var f : text;
     s1,s2 : string;
      t,t2,t3 : longint;
      code : integer;
    a_g    : integer;
    inw    : array [1..15] of longint;
    grenz  : integer;
    elkaar : array[1..15,1..15] of boolean;
    f2 : file of longint;
    a_r : longint;


 procedure kijkbestand;
  begin
    for t:=1 to 15 do inw[t]:=0;
    for t:=1 to 100 do elkaar[t,t]:=false;
    s1:='';
    s2:='';
    a_g:=0;
    grenz:=0;

    assign(f,'gebied.in');
    reset(f);
    readln(f,s1);
    val(s1,a_g,code);


    for t:=1 to a_g do
             begin
              readln(f,s1);
              val(s1,t2,code);
              inw[t]:=t2;
             end;

    readln(f,s1);
    val(s1,t2,code);
    grenz:=t2;
    for t:=1 to grenz do
             begin
              readln(f,s1);
              val(s1[1],t2,code);
              val(s1[3],t3,code);
              elkaar[t2,t3]:=True;
             end;
    t:=0;
    sound(1000);delay(100);nosound;
    close(f);

  end;

 procedure kijkregio;
  begin
   a_r:=0;
   assign(f2,'reg.uit');
   rewrite(f2);
   for t:=1 to a_g do
            begin
             if inw[t]>=100000 then
              begin
               write(f2,t);
               for t2:=1 to 15 do begin elkaar[t,t2]:=false;elkaar[t2,t]:=false;
               inc(a_r)
              end;
            end;


   close(f2);
  end;


begin
 clrscr;
 kijkbestand;
 kijkregio;
end.