T = int(input()) for _ in range(T): x, y = map(int, input().split()) x |= (1 << y) - 1 print(x & (x ^ (x + 1)))