def hailstone(n, max):

    if n > max:
        max = n

    if n % 2 == 0:
        if isPowerOfTwo(n):
            return max
        return hailstone(n / 2, max)
    elif n is not 1:
        return hailstone(3 * n + 1, max)
    else:
        return max

def isPowerOfTwo(n):
    return n is not 0 and not (n & (n - 1))

def mainFunc():
    cases = input()
    for i in range(cases):
        (num, n) = tuple(int(x) for x in raw_input().split(' '))
        print num, hailstone(n, 1)

mainFunc()