T = int(input())
for i in range(T) :
A,B = list(map(int,input().split()))
k = []
x=[]
for i in range(1,100):
if A%i==0 :
k = k+ [i]
for i in range(1,100):
if B%i==0 :
x = x+ [i]
v=set(k)
w=set(x)
z=v.intersection(w)
p = max(z)
print(p)