program washington;
Uses Math;
const
MAXT = 10000;
type coordinate = record
quadrante:string;
ascissa:char;
ascissanumerica:longint;
ordinata:string;
ordinatanumerica:longint;
end;
var
L, T, i, j, err: LongInt;
q, ord: string;
asc:char;
line: AnsiString;
street:array[1..2] of coordinate;
procedure readcard(var s: ansistring; var quadr:string; var x: char; var y:string);
begin
quadr:=s[1]+s[2];
x:=s[4];
if s[7]=' ' then begin y:=s[6]; s := copy(s, 8, length(s)); end
else begin y:=s[6]+s[7] ; s := copy(s, 9, length(s));end;
end;
begin
{
uncomment the two following lines if you want to read/write from files
assign(input, 'input.txt'); reset(input);
assign(output, 'output.txt'); rewrite(output);
}
ReadLn(T);
for i:=0 to T-1 do
begin
line:='';
readln(line);
for j:=1 to 2 do
begin
readcard(line, q, asc,ord);
street[j].quadrante:=q;
street[j].ascissa:=asc;
street[j].ordinata:=ord;
val(street[j].ordinata, street[j].ordinatanumerica,err);
case street[j].ascissa of
'A' : begin street[j].ascissanumerica:=0; end;
'B' : begin street[j].ascissanumerica:=1; end;
'C' : begin street[j].ascissanumerica:=2; end;
'D' : begin street[j].ascissanumerica:=3; end;
'E' : begin street[j].ascissanumerica:=4; end;
'F' : begin street[j].ascissanumerica:=5; end;
'G' : begin street[j].ascissanumerica:=6; end;
'H' : begin street[j].ascissanumerica:=7; end;
'I' : begin street[j].ascissanumerica:=8; end;
'J' : begin street[j].ascissanumerica:=9; end;
'K' : begin street[j].ascissanumerica:=10; end;
'L' : begin street[j].ascissanumerica:=11; end;
'M' : begin street[j].ascissanumerica:=12; end;
'N' : begin street[j].ascissanumerica:=13; end;
'O' : begin street[j].ascissanumerica:=14; end;
'P' : begin street[j].ascissanumerica:=15; end;
'Q' : begin street[j].ascissanumerica:=16; end;
'R' : begin street[j].ascissanumerica:=17; end;
'S' : begin street[j].ascissanumerica:=18; end;
'T' : begin street[j].ascissanumerica:=19; end;
'U' : begin street[j].ascissanumerica:=20; end;
'V' : begin street[j].ascissanumerica:=21; end;
'W' : begin street[j].ascissanumerica:=22; end;
'X' : begin street[j].ascissanumerica:=23; end;
'Y' : begin street[j].ascissanumerica:=24; end;
'Z' : begin street[j].ascissanumerica:=25; end;
end;
if street[j].quadrante='NW' then street[j].ascissanumerica:=(-1)*street[j].ascissanumerica
else
if street[j].quadrante='SW' then
begin
street[j].ascissanumerica:=(-1)*street[j].ascissanumerica;
if street[j].ordinatanumerica<>0 then street[j].ordinatanumerica:= street[j].ordinatanumerica-26;
end
else
if street[j].quadrante='SE' then if street[j].ordinatanumerica<>0 then street[j].ordinatanumerica:= street[j].ordinatanumerica-26;
end;
L := abs(street[2].ascissanumerica -street[1].ascissanumerica)+ abs(street[2].ordinatanumerica-street[1].ordinatanumerica);
WriteLn(L);
end;
end.