# import pypyjit;pypyjit.set_param("max_unroll_recursion=-1") # from bisect import * # from collections import * # from heapq import * # from itertools import * # from math import * # from datetime import * # from decimal import * # PyPyだと遅い # from string import ascii_lowercase,ascii_uppercase # import numpy as np import sys # sys.setrecursionlimit(10**6) # PyPyだと遅い INF = 10**20 MOD = 998244353 # MOD = 10**9 + 7 File = sys.stdin def input(): return File.readline()[:-1] # /////////////////////////////////////////////////////////////////////////// for _ in range(int(input())): x, y = map(int, input().split()) idx_y = x // (2**y) // 2 + 1 cnt = 0 # print(idx_y, end=" ") while idx_y % 2 == 0: idx_y /= 2 cnt += 1 print(2 ** (y + 1 + cnt) - 1)