/Barbalaua  Tudor Vianu

/Jr Division #4

 

 

program Reverse;

var v:array[1..8,1..8] of char;

    int,out:text;

    po:string;

    n,m,i,j,h,q:integer;

    x,c1,c2,c3,c,r,y,t:char;

 

procedure litera(x:char;var j:integer);

          begin

          if x='A' then j:=1;

          if x='B' then j:=2;

          if x='C' then j:=3;

          if x='D' then j:=4;

          if x='E' then j:=5;

          if x='F' then j:=6;

          if x='G' then j:=7;

          if x='H' then j:=8;

          end;

 

procedure cifra(c:char;var i:integer);

          begin

          if c='1' then i:=1;

          if c='2' then i:=2;

          if c='3' then i:=3;

          if c='4' then i:=4;

          if c='5' then i:=5;

          if c='6' then i:=6;

          if c='7' then i:=7;

          if c='8' then i:=8;

          end;

 

function verificare(n,m:integer):boolean;

          begin

          if v[i+n][j+m]='O' then verificare:=true

                             else verificare:=false;

          end;

 

function afisare(x:integer):char;

         begin

         afisare:=chr(x+64);

         end;

 

function o(i,j:integer):boolean;

begin

o:=false;

if (v[i,j]<>'X') and (v[i,j]<>'O') then begin

   if (v[i-1,j-1]='O') and (v[i-2,j-2]='X') then o:=true;

   if (v[i-1,j]='O') and (v[i-2,j]='X') then o:=true;

   if (v[i-1,j+1]='O') and (v[i-2,j+2]='X') then o:=true;

   if (v[i,j-1]='O') and (v[i,j-2]='X') then o:=true;

   if (v[i,j+1]='O') and (v[i,j+2]='X') then o:=true;

   if (v[i+1,j-1]='O') and (v[i+2,j-2]='X') then o:=true;

   if (v[i+1,j]='O') and (v[i+2,j]='X') then o:=true;

   if (v[i+1,j+1]='O') and (v[i+2,j+2]='X') then o:=true;

   end;

end;

 

begin

assign(int,'date.in');

assign(out,'date.out');

reset(int);rewrite(out);

for i:=1 to 8 do

    for j:=1 to 8 do v[i][j]:=' ';

for q:=1 to 5 do

begin

read(int,r,t,y,n,c1);

for h:=1 to n do

    begin

    read(int,c,x,c1);

    litera(x,j);

    cifra(c,i);

    v[9-i][j]:='X';

    end;

read(int,m);

for h:=1 to m do

    begin

    read(int,c,x,c1);

    litera(c1,j);

    cifra(x,i);

    v[9-i][j]:='O';

    end;

readln(int,po);

write(out,q,'. ');

for i:=8 downto 1 do

    for j:=1 to 8 do

        begin

        if v[i][j]=' ' then

           begin

           if o(i,j) then write(out,i,afisare(j),' ');

           end;

        end;

writeln(out);

end;

close(int);

close(out);

end.