#include using namespace std; 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;} if(D == 1){ long long need = (X+N-1)/N; cout << X*need-1 << "\n"; continue; } long long low = 0,high = 2e9; while(high-low > 1){ long long mid = (high+low)/2; __int128_t x = X*mid+(__int128_t)D*N*mid; __int128_t y = X*(mid+D-1); if(x > y) high = mid; else low = mid; } { long long y = X*(high+D-1); cout << y-D << "\n"; } } }