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