t = int(input()) for x in range(t): a, b= map(int, input().split()) if a==b: print(-1) elif a%b ==0: print(a) else: print(a-(b-int(a//b)))