from sys import stdin input=lambda :stdin.readline()[:-1] def solve(): x,y=map(int,input().split()) while (x>>(y+1))&1: y+=1 print((1<<(y+1))-1) for _ in range(int(input())): solve()