T = int(input()) for _ in range(T): L,R = map(int,input().split()) B = 1<<(R.bit_length()-1) if L <= B-1: print(B*(B-1)) else: print(-1)