for _ in range(int(input())):x,y=map(int,input().split());print(2**bin((x|2**y-1)+1)[::-1].find('1')-1)