Q = int(input()) for i in range(Q): A, B, C = map(int, input().split()) if C == 1: print(-1) continue cnt = 0 while True: if A < 2*C: A -= C-1 cnt += 1 else: A, b = A//C, A%C if b > 0: cnt += 1 if A > 0: cnt += 1 if A <= 0: break print(B*cnt)