T = int(input()) for _ in range(T): x, y = map(int, input().split()) for i in range(y, 60): if (x >> i) & 1 == 0: break print((1 << i) - 1)