from math import*;i=input;p=print for _ in[0]*int(i()): x,n,d=map(int,i().split()) if(gcd(x,d)>1):p("inf") else:p(((x-2)//n+1)*x+(d-1)*(x-1)-1)