4
14723
5512
100
28436
33903
100
84816
75747
100
92281
31380
100 1
45819
95605
83
1848
1357
3031
2097 3824
t=input()
from fractions import gcd
for x in range(t):
	n1=input()
	n2=input()
	k=input()
	ans=0
	for i in range(-k, k+1):
		if i+n1<1:
			continue
		absi=abs(i)
		for j in range(-k+absi, k-absi+1):
			if j+n2<1:
				continue
			y=gcd(n1+i, n2+j)
			if y>ans:
				ans=y
	print ans