#include using namespace std; long long solve(long long X,long long N,long long D){ vector OK(10000); for(int i=1; i<=10000; i++){ int x = i*X; for(int k=0; k<=N*i; k++,x+=D){ if(x >= 10000) break; OK.at(x) = true; } } for(int i=10000; i--;) if(!OK.at(i)) return i; return -1; } int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); int Q; cin >> Q; while(Q--){ long long X,N,D; cin >> X >> N >> D; if(gcd(X,D) > 1){cout << "inf\n"; continue;} if(X == 1){cout << "-1\n"; continue;} long long need = (X-1+N-1)/N; cout << X*(need-1)+(X-1)*D << "\n"; } }