from collections import * import heapq import bisect INF = float("inf") T = int(input()) for _ in range(T): x, y = map(int, input().split()) for i in range(y, 61): if (x >> i) & 1 == 0: break print((1 << i) - 1)