program order_last; {$APPTYPE CONSOLE} var f1,f2: text; i,j,l,n,m,k,k1,k2,kil,ch,prom:longint; fl:byte; a: array [1..1050000] of longint; b: array [1..100] of byte; c: array [1..100] of char; begin assign(f1,'order.dat'); assign(f2,'order.sol'); reset(f1); readln(f1,n); for i:=1 to n do begin read(f1,m); k:=0; for j:=1 to m-1 do begin read(f1,a[j]); end; readln(f1,a[m]); for j:=1 to m do begin while a[j]<>j do begin prom:=a[j]; a[j]:=a[prom]; a[prom]:=prom; k:=k+1; end; end; if k=0 then begin b[i]:=0; end; if k mod 2 =0 then begin b[i]:=0 end else b[i]:=1; for j:=1 to m do begin a[j]:=0; end; end; close(f1); k1:= n mod 4; k2:= n div 4; kil:=0; if k1<>0 then begin if k1=3 then begin kil:=kil+b[3]* 1; kil:=kil+b[2]* 2; kil:=kil+b[1]* 4; end; if k1=2 then begin kil:=kil+b[2]* 1; kil:=kil+b[1]* 2; end; if k1=1 then begin kil:=kil+b[1]* 1; end; if kil=0 then begin c[1]:='0' end else if kil=1 then begin c[1]:='1' end else if kil=2 then begin c[1]:='2' end else if kil=3 then begin c[1]:='3' end else if kil=4 then begin c[1]:='4' end else if kil=5 then begin c[1]:='5' end else if kil=6 then begin c[1]:='6' end else if kil=7 then begin c[1]:='7' end else if kil=8 then begin c[1]:='8' end else if kil=9 then begin c[1]:='9' end else if kil=10 then begin c[1]:='A' end else if kil=11 then begin c[1]:='B' end else if kil=12 then begin c[1]:='C' end else if kil=13 then begin c[1]:='D' end else if kil=14 then begin c[1]:='E' end else if kil=15 then begin c[1]:='F' end; end; if k2<>0 then begin if k1>0 then i:=1 else i:=0; ch:=k1; fl:=0; while fl<>1 do begin inc(i); ch:=ch+4; kil:=0; kil:=kil+b[ch]* 1; kil:=kil+b[ch-1]* 2; kil:=kil+b[ch-2]* 2*2; kil:=kil+b[ch-3]* 2*2*2; if ch=n then begin fl:=1 end; if kil=0 then begin c[i]:='0' end; if kil=1 then begin c[i]:='1' end; if kil=2 then begin c[i]:='2' end; if kil=3 then begin c[i]:='3' end; if kil=4 then begin c[i]:='4' end; if kil=5 then begin c[i]:='5' end; if kil=6 then begin c[i]:='6' end; if kil=7 then begin c[i]:='7' end; if kil=8 then begin c[i]:='8' end; if kil=9 then begin c[i]:='9' end; if kil=10 then begin c[i]:='A' end; if kil=11 then begin c[i]:='B' end; if kil=12 then begin c[i]:='C' end; if kil=13 then begin c[i]:='D' end; if kil=14 then begin c[i]:='E' end; if kil=15 then begin c[i]:='F' end; end; end; rewrite(f2); if c[1]='0' then j:=2 else begin j:=1; end; for l:=j to i-1 do begin write(f2,c[l]); end; writeln(f2,c[i]); close(f2); end.