样例输入
3 3 3 3 3 1 1 1 1 12 5 13 1
样例输出
24 4 21
uses math;
var
a,b,c,s1,s2,s3,s4,y1,y2,y3,ans,h,o,e:longint;
v:array[1..4]of longint;
begin
readln(a);
for b:=1 to a do
begin
h:=0;
ans:=0;
readln(v[1]);
readln(v[2]);
readln(v[3]);
readln(v[4]);
for s1:=1 to 4 do
begin
for y1:=1 to 4 do
begin
for s2:=1 to 4 do
begin
if s1=s2 then continue;
for y2:=1 to 4 do
begin
for s3:=1 to 4 do
begin
if (s1=s3)or(s2=s3) then continue;
for y3:=1 to 4 do
begin
for s4:=1 to 4 do
begin
if (s1=s4)or(s2=s4)or(s3=s4) then continue;
ans:=0;
if y1=1 then ans:=v[s1]+v[s2];
if y1=2 then ans:=v[s1]-v[s2];
if y1=3 then ans:=v[s1]*v[s2];
if y1=4 then
if (v[s2]<>0)and(v[s1] mod v[s2]=0) then
ans:=v[s1] div v[s2] else continue;
if y2=1 then ans:=ans+v[s3];
if y2=2 then ans:=ans-v[s3];
if y2=3 then ans:=ans*v[s3];
if y2=4 then
if (v[s3]<>0)and(ans mod v[s3]=0) then
ans:=ans div v[s3] else continue;
if y3=1 then ans:=ans+v[s4];
if y3=2 then ans:=ans-v[s4];
if y3=3 then ans:=ans*v[s4];
if y3=4 then
if (v[s4]<>0)and(ans mod v[s4]=0) then
ans:=ans div v[s4] else continue;
if ans<=24 then h:=max(ans,h);
end;
end;
end;
end;
end;
end;
end;
for s1:=1 to 4 do
begin
for y1:=1 to 4 do
begin
for s2:=1 to 4 do
begin
if s1=s2 then continue;
for y2:=1 to 4 do
begin
for s3:=1 to 4 do
begin
if (s1=s3)or(s2=s3) then continue;
for y3:=1 to 4 do
begin
for s4:=1 to 4 do
begin
if (s1=s4)or(s2=s4)or(s3=s4) then continue;
ans:=0;
if y1=1 then o:=v[s1]+v[s2];
if y1=2 then o:=v[s1]-v[s2];
if y1=3 then o:=v[s1]*v[s2];
if y1=4 then
if (v[s2]<>0)and(v[s1] mod v[s2]=0) then
o:=v[s1] div v[s2] else continue;
if y2=1 then e:=v[s3]+v[s4];
if y2=2 then e:=v[s3]-v[s4];
if y2=3 then e:=v[s3]*v[s4];
if y2=4 then
if (v[s4]<>0)and(v[s3] mod v[s4]=0) then
e:=v[s3] div v[s4] else continue;
if y3=1 then ans:=o+e;
if y3=2 then ans:=o-e;
if y3=3 then ans:=o*e;
if y3=4 then
if (e<>0)and(o mod e=0) then
ans:=o div e else continue;
if ans<=24 then h:=max(ans,h);
end;
end;
end;
end;
end;
end;
end;
writeln(h);
end;
end.