t = int(input()) for i in range(t): x,y = map(int,input().split()) x >>= y while x & 1 == 1: x //= 2 y += 1 print(2**y-1)