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