Program divisor;
var
A, B, G, K, T, i,test,radq, somma, contadivisori, increment1, increment2 : LongInt;
divis1, divis2, divisori:array[1..100000] of longint;
procedure trovadivisori (x:longint);
var y,h:longint;
begin
y:=2; h:=2;
repeat
if (x mod y =0) then begin divis1[h]:= x div y; divis2[h]:=y; h:=h+1; end;
y:=y+1;
until y>trunc(sqrt(x));
contadivisori:=h-1;
end;
begin
{ assign(input, 'input.txt'); reset(input);
assign(output, 'output.txt'); rewrite(output);
}
ReadLn(T);
for test:=1 to T do begin
ReadLn(A, B, K);
somma:=A+B+K;
radq:=trunc(sqrt(somma));
divis2[1]:=1; divis1[1]:=somma;
trovadivisori(somma);
G := 0;
for i:=1 to contadivisori do divisori[i]:=divis1[i];
for i:=contadivisori+1 to contadivisori*2 do divisori[i]:=divis2[2*contadivisori-i+1];
for i:=1 to contadivisori*2 do write(divisori[i],' '); writeln;
for i:=1 to contadivisori*2 do
begin
if (A mod divisori[i]) =0 then increment1:=0
else increment1:=divisori[i] - (A mod divisori[i]);
if (B mod divisori[i]) =0 then increment2:=0
else increment2:=divisori[i] - (B mod divisori[i]);
if (increment1+increment2)>K then continue
else if (increment1+increment2)<K then begin if ((K-(increment1+increment2)) mod (divisori[i])) =0 then if divisori[i]>G then G:=divisori[i]
else continue; end
else if (increment1+increment2)=K then begin if divisori[i]>G then G:=divisori[i]
else continue; end;
end;
writeln(G);
end;
end.
UHJvZ3JhbSBkaXZpc29yOwoKdmFyCiAgICBBLCBCLCBHLCBLLCBULCBpLHRlc3QscmFkcSwgc29tbWEsIGNvbnRhZGl2aXNvcmksIGluY3JlbWVudDEsIGluY3JlbWVudDIgOiBMb25nSW50OwogICAgZGl2aXMxLCBkaXZpczIsIGRpdmlzb3JpOmFycmF5WzEuLjEwMDAwMF0gb2YgbG9uZ2ludDsKICAgIApwcm9jZWR1cmUgdHJvdmFkaXZpc29yaSAoeDpsb25naW50KTsKdmFyIHksaDpsb25naW50OwogICAgCmJlZ2luCiAgIHk6PTI7IGg6PTI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ldKSA9MCB0aGVuIGluY3JlbWVudDE6PTAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBlbHNlIGluY3JlbWVudDE6PWRpdmlzb3JpW2ldIC0gKEEgbW9kIGRpdmlzb3JpW2ldKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoQiBtb2QgZGl2aXNvcmlbaV0pID0wICB0aGVuIGluY3JlbWVudDI6PTAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBlbHNlIGluY3JlbWVudDI6PWRpdmlzb3JpW2ldIC0gKEIgbW9kIGRpdmlzb3JpW2ldKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoaW5jcmVtZW50MStpbmNyZW1lbnQyKT5LIHRoZW4gY29udGludWUKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGVsc2UgaWYgKGluY3JlbWVudDEraW5jcmVtZW50Mik8SyB0aGVuIGJlZ2luIGlmICgoSy0oaW5jcmVtZW50MStpbmNyZW1lbnQyKSkgbW9kIChkaXZpc29yaVtpXSkpID0wIHRoZW4gaWYgZGl2aXNvcmlbaV0+RyB0aGVuICBHOj1kaXZpc29yaVtpXQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGVsc2UgY29udGludWU7IGVuZAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZWxzZSBpZiAoaW5jcmVtZW50MStpbmNyZW1lbnQyKT1LIHRoZW4gYmVnaW4gaWYgZGl2aXNvcmlbaV0+RyB0aGVuICBHOj1kaXZpc29yaVtpXQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBlbHNlIGNvbnRpbnVlOyBlbmQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgIGVuZDsgCiAgICB3cml0ZWxuKEcpOwogICAgZW5kOwplbmQuCg==