program Blokus;

var v:array[1..10,1..10]of integer;

    int,out:text;

    c1,c5,c6,c7:char;

    i,j,k,l,m,n,p,p1:integer;

begin

assign(int,'date.in');

assign(out,'date.out');

reset(int);

rewrite(out);

for i:=1 to 5 do

    begin

readln(int,c5,c6,c7,c1,p1,n,m);

if c1='A' then p:=10;

if c1='B' then p:=9;

if c1='C' then p:=8;

if c1='D' then p:=7;

if c1='E' then p:=6;

if c1='F' then p:=5;

if c1='G' then p:=4;

if c1='H' then p:=3;

if c1='I' then p:=2;

if c1='J' then p:=1;

write(out,i,'. ');

if n=2 then

   begin

   if m=1 then

              begin

              if p1+1 <= 8 then write(out,'A B ');

              if (p1+1 <= 8) and (p <= 8) then write(out,'C ');

              if (p1+1 <= 9) and (p <= 7) then write(out,'D ');

              end;

    if m=2 then

               begin

               if (p1+1 <= 7) and (p <= 9) then write(out,'C ');

               if (p1+1 <= 8) and (p <= 8) then write(out,'D ');

               end;

    if m=4 then

               if (p1+1 <= 8) and (p >= 4) then write(out,'D ');

    end;

if n=1 then

   begin

   if m=1 then

              begin

              if (p1 >= 3) and (p <= 8) then write(out,'C ');

              if (p1 >= 2) and (p <= 7) then write(out,'D ');

              end;

   if m=2 then

              begin

              if p1 >= 3 then write(out,'A ');

              if (p1 >= 3) and (p <= 8) then write(out,'B ');

              end;

   end;

writeln(out);

end;

close(int);

close(out);

end.