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