#Problem ID: SINS
#Problem Name: The Deadly Sin

import math
for _ in range(int(input())):
    x, y = map(int, input().split())

    if x==y:
        print(x+y)
    else:
        print(2*math.gcd(x,y))
