def solve(x, y): while x >> y & 1: y += 1 return (1 << y) - 1 for _ in range(int(input())): print(solve(*map(int, input().split())))