#include using namespace std; using ll = long long; int main() { ios::sync_with_stdio(false); cin.tie(0); int T; cin >> T; while(T--){ ll x, n, d; cin >> x >> n >> d; ll g = gcd(x, d); if(g != 1){ cout << "inf\n"; continue; } if(x == 1){ cout << "-1\n"; continue; } // x の倍数 // d の倍数 // は作れる? // dの個数は A <= d <= N * A以内の制約 // フロベニウスっぽい問題 ll k = (x - 2) / n + 1, ans = k * x + (d - 1) * (x - 1) - 1; cout << ans << '\n'; } }