ll@q; rep(q){ ll@(x,n,d); if(gcd(x,d)!=1){ wt("inf"); }else if(x==1){ wt("-1"); }else{ wt(x*((x-2)/n+d)-d); } }