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