T = int(input()) for _ in range(T): X, Y = map(int, input().split()) c = X i = 0 while X >= 2 ** (i + 1): i += 1 # print(X, i) y = 2 ** (i + 1) - X x = Y if y <= 2**x: print(2 ** (i + 1) - 1) continue ok = False for k in range(1, i): if y <= 2**x + 2**k and y >= 2**k: print(2**k - 1) ok = True break if ok: continue print(1)