#!/usr/bin/env python3 # %% import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines # %% Q = int(readline()) m = map(int, read().split()) ABC = zip(m, m, m) # %% def solve(A, C): if A < C: return 1 if A < C + C - 1: return 2 q, r = divmod(A, C) return solve(q, C) + 1 + (r > 0) # %% for a, b, c in ABC: if c == 1: print(-1) else: print(b * solve(a, c))