Program divisor;
var
A, B, G, K, T, i,test,radq, somma, contadivisori, increment1, increment2 : LongInt;
divis1, divis2: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
begin
if A mod divis1[i]=0 then increment1:= 0 else increment1:=divis1[i] - (A mod divis1[i]);
if B mod divis1[i]=0 then increment2:= 0 else increment2:=divis1[i] - (B mod divis1[i]);
if (increment1+increment2)>K then continue
else
if (increment1+increment2)<=K then if divis1[i]>G then G:=divis1[i];
end;
writeln(G);
end;
end.
UHJvZ3JhbSBkaXZpc29yOwoKdmFyCiAgICBBLCBCLCBHLCBLLCBULCBpLHRlc3QscmFkcSwgc29tbWEsIGNvbnRhZGl2aXNvcmksIGluY3JlbWVudDEsIGluY3JlbWVudDIgOiBMb25nSW50OwogICAgZGl2aXMxLCBkaXZpczI6YXJyYXlbMS4uMTAwMDAwXSBvZiBsb25naW50OwogICAgCnByb2NlZHVyZSB0cm92YWRpdmlzb3JpICh4OmxvbmdpbnQpOwp2YXIgeSxoOmxvbmdpbnQ7CiAgICAKYmVnaW4KICAgeTo9MjsgaDo9MjsKICAgcmVwZWF0CiAgIAkgICAgaWYgICh4IG1vZCB5ID0wKSB0aGVuIGJlZ2luIGRpdmlzMVtoXTo9IHggZGl2IHk7IGRpdmlzMltoXTo9eTsgaDo9aCsxOyBlbmQ7CiAgIAkgICAgeTo9eSsxOwogIHVudGlsIHk+dHJ1bmMoc3FydCh4KSk7CiAgY29udGFkaXZpc29yaTo9aC0xOwplbmQ7CgpiZWdpbgp7ICAgYXNzaWduKGlucHV0LCAgJ2lucHV0LnR4dCcpOyAgcmVzZXQoaW5wdXQpOwogICAgYXNzaWduKG91dHB1dCwgJ291dHB1dC50eHQnKTsgcmV3cml0ZShvdXRwdXQpOwp9CgogICAgUmVhZExuKFQpOwogICAgZm9yIHRlc3Q6PTEgdG8gVCBkbyBiZWdpbgogICAgICAgIFJlYWRMbihBLCBCLCBLKTsKICAgICAgICBzb21tYTo9QStCK0s7CiAgICAgICAgcmFkcTo9dHJ1bmMoc3FydChzb21tYSkpOwogICAgICAgIGRpdmlzMlsxXTo9MTsgZGl2aXMxWzFdOj1zb21tYTsKICAgICAgICB0cm92YWRpdmlzb3JpKHNvbW1hKTsKICAgICAgICBHIDo9IDA7CiAgICAgICAgZm9yIGk6PTEgdG8gY29udGFkaXZpc29yaSBkbwogICAgICAgICAgICAgICAgICAgICAgICAgICBiZWdpbgogICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIEEgbW9kIGRpdmlzMVtpXT0wIHRoZW4gaW5jcmVtZW50MTo9IDAgZWxzZSBpbmNyZW1lbnQxOj1kaXZpczFbaV0gLSAoQSBtb2QgZGl2aXMxW2ldKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiBCIG1vZCBkaXZpczFbaV09MCB0aGVuIGluY3JlbWVudDI6PSAwIGVsc2UgaW5jcmVtZW50Mjo9ZGl2aXMxW2ldIC0gKEIgbW9kIGRpdmlzMVtpXSk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGluY3JlbWVudDEraW5jcmVtZW50Mik+SyB0aGVuIGNvbnRpbnVlCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBlbHNlCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChpbmNyZW1lbnQxK2luY3JlbWVudDIpPD1LIHRoZW4gaWYgZGl2aXMxW2ldPkcgdGhlbiAgRzo9ZGl2aXMxW2ldOwogICAgICAgICAgICAgICAgICAgICAgICAgICBlbmQ7IAogICAgd3JpdGVsbihHKTsKICAgIGVuZDsKZW5kLgo=