Q = int(input()) for i in range(Q): A,B,C = [int(x) for x in input().split()] ans = 0 if C==1: print(-1) continue if AC: #print(A) if A<=2*(C-1): ans+=2 A=1 break if A%C!=0: A = A-A%C ans+=1 if A==C: ans+=2 A=1 break A = A/C ans+=1 if A==C: ans+=2 elif A!=1: ans+=1 print(ans*B)