var n,i,j,m,t:longint;
a:array[0..10]of longint;
procedure swap(var a,b:longint);
var t:longint;
begin
t:=a; a:=b; b:=t;
end;
procedure work1;
var s,th:string;
i,aa,bb:longint;
begin
th:=''; s:='';
if a[1]=0 then swap(a[1],a[2]);
for i:=1 to n div 2+1 do begin
str(a[i],th);
s:=s+th;
end;
val(s,aa);
s:='';
for i:=n downto n div 2+2 do begin
str(a[i],th);
s:=s+th;
end;
val(s,bb);
writeln(abs(aa-bb));
exit;
end;
procedure work2;
var i,j,l,r,min,aa,bb:longint;
u:array[1..10]of boolean;
s1,s2,th:string;
begin
min:=maxlongint;
for i:=2 to n do begin
if a[i-1]<>0 then begin
s1:=''; s2:=''; fillchar(u,sizeof(u),false);
str(a[i],s1); str(a[i-1],s2);
u[i]:=true; u[i-1]:=true;
l:=1; r:=n;
for j:=1 to (n-2) div 2 do begin
while u[l] do inc(l);
while u[r] do dec(r);
str(a[l],th); s1:=s1+th; u[l]:=true;
str(a[r],th); s2:=s2+th; u[r]:=true;
end;
val(s1,aa); val(s2,bb);
if abs(aa-bb)<min then min:=abs(aa-bb);
end;
end;
writeln(min);
end;
begin
readln(t);
for m:=1 to t do begin
readln(n);
fillchar(a,sizeof(a),0);
for i:=1 to n do read(a[i]);
for i:=1 to n-1 do
for j:=i+1 to n do
if a[i]>a[j] then swap(a[i],a[j]);
if n=2 then begin writeln(abs(a[1]-a[2])); continue; end;
if n mod 2=1 then work1
else if n mod 2=0 then work2;
end;
end.