import sys input = sys.stdin.readline T=int(input()) for tests in range(T): L,R=list(map(int,input().split())) y=-1 for i in range(40): x=2**i if L<=x<=R: y=x if y==-1: print(-1) else: if L<=y-1<=R: ANS=y*(y-1) else: ANS=-1 print(ANS)