var m,j,i,q,n:longint; res:int64; a:array [1..1048580] of longint; b:array [1..100] of byte; reply:string; tr:boolean; begin assign(input,'order.dat');reset(input); assign(output,'order.sol');rewrite(output); readln(m); for j:=1 to m do begin read(n); for i:=1 to n do read(a[i]); res:=0; for q:=1 to n-1 do for i:=q+1 to n do if a[q]>a[i] then inc(res); // writeln(res,' ',res mod 2); b[j]:=res mod 2; end; { for i:=1 to m do write(b[i]); writeln;writeln;} i:=m; while i>0 do begin q:=0; if b[i]=1 then q:=q+1; if (i-1>0)and(b[i-1]=1) then q:=q+2; if (i-2>0)and(b[i-2]=1) then q:=q+4; if (i-3>0)and(b[i-3]=1) then q:=q+8; case q of 0:reply:='0'+reply; 1:reply:='1'+reply; 2:reply:='2'+reply; 3:reply:='3'+reply; 4:reply:='4'+reply; 5:reply:='5'+reply; 6:reply:='6'+reply; 7:reply:='7'+reply; 8:reply:='8'+reply; 9:reply:='9'+reply; 10:reply:='A'+reply; 11:reply:='B'+reply; 12:reply:='C'+reply; 13:reply:='D'+reply; 14:reply:='E'+reply; 15:reply:='F'+reply end; dec(i,4); end; tr:=true; for i:=1 to length(reply) do if ((reply[i]<>'0'))or((reply[i]='0')and(not tr)) then begin write(reply[i]); tr:=false end; if reply='0' then write(0); writeln; close(input); close(output); end.