J=lambda:map(int,input().split()) import math for t in range(sum(J())):X,N,D=J();print("inf"if math.gcd(X,D)>1else[((X-2)//N+D)*X-D,-1][X<2])