import sys, time, random from collections import deque, Counter, defaultdict input = lambda: sys.stdin.readline().rstrip() ii = lambda: int(input()) mi = lambda: map(int, input().split()) li = lambda: list(mi()) inf = 2 ** 63 - 1 mod = 998244353 t = ii() for _ in range(t): x, y = mi() x |= (2 ** y - 1) ans = 0 for bit in range(0, 60): if 1 & (x >> bit): ans += 1 << bit print(ans)