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