def euklides(t, partie):
wyniki = []
for a, b in partie:
while a != b:
if a > b:
a = a - b
else:
b = b - a
wyniki.append(a + b)
return wyniki
t = int(input())
partie = []
for _ in range(t):
a, b = map(int, input().split())
partie.append((a, b))
wyniki =euklides(t, partie)
for wynik in wyniki:
print(wynik)
ZGVmIGV1a2xpZGVzKHQsIHBhcnRpZSk6CiAgICB3eW5pa2kgPSBbXQogICAgZm9yIGEsIGIgaW4gcGFydGllOgogICAgICAgIHdoaWxlIGEgIT0gYjoKICAgICAgICAgICAgaWYgYSA+IGI6CiAgICAgICAgICAgICAgICBhID0gYSAtIGIKICAgICAgICAgICAgZWxzZToKICAgICAgICAgICAgICAgIGIgPSBiIC0gYQogICAgICAgIHd5bmlraS5hcHBlbmQoYSArIGIpCiAgICByZXR1cm4gd3luaWtpCgp0ID0gaW50KGlucHV0KCkpCnBhcnRpZSA9IFtdCmZvciBfIGluIHJhbmdlKHQpOgogICAgYSwgYiA9IG1hcChpbnQsIGlucHV0KCkuc3BsaXQoKSkKICAgIHBhcnRpZS5hcHBlbmQoKGEsIGIpKQoKd3luaWtpID1ldWtsaWRlcyh0LCBwYXJ0aWUpCgpmb3Igd3luaWsgaW4gd3luaWtpOgogICAgcHJpbnQod3luaWspCg==