#ifndef ONLINE_JUDGE #define _GLIBCXX_DEBUG #endif #include #include #include using namespace std; using namespace atcoder; using ll = long long; using mint = modint998244353; //using mint = modint1000000007; #include #include namespace mp = boost::multiprecision; using Bint = mp::cpp_int; using Real = mp::number>; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define repu(i, s, t) for (int i = (int)(s); i < (int)(t); i++) #define repd(i, s, t) for (int i = (int)(s)-1; i >= (int)(t); i--) #define all(v) v.begin(), v.end() void _u() { cerr << endl; } template void _u(H&& h, T&&... t) { cerr << h << ", "; _u(move(t)...); } #define U(...) { cerr << #__VA_ARGS__ << ": "; _u(__VA_ARGS__); } template bool chmax(T &a, const T b) { if(a >= b) return false; a = b; return true; } template bool chmin(T &a, const T b) { if(a <= b) return false; a = b; return true; } template istream& operator>>(istream &in, vector &a) { for(T &x: a) in >> x; return in; } template ostream& operator<<(ostream &out, const vector &a) { for(const T &x: a) out << x << ' '; return out; } const int di[] = {1, 0, -1, 0, 1, 1, -1, -1, 0}; const int dj[] = {0, 1, 0, -1, -1, 1, 1, -1, 0}; struct PQ { Bint p, q; PQ(const Bint p_=0, const Bint q_=1): p(p_), q(q_) { assert(q != 0); reduce(); }; PQ(const PQ &f): p(f.p), q(f.q) {}; void operator=(const PQ &other) { p = other.p; q = other.q; } bool operator==(const PQ &other) const { return p*other.q == other.p*q; } bool operator<(const PQ &other) const { return p*other.q < other.p*q; } bool operator<=(const PQ &other) const { return p*other.q <= other.p*q; } bool operator>(const PQ &other) const { return p*other.q > other.p*q; } bool operator>=(const PQ &other) const { return p*other.q >= other.p*q; } PQ &operator+=(const PQ &other) { Bint tp = p*other.q + q*other.p; q *= other.q; p = tp; reduce(); return *this; } PQ &operator-=(const PQ &other) { Bint tp = p*other.q - q*other.p; q *= other.q; p = tp; reduce(); return *this; } PQ &operator*=(const PQ &other) { p *= other.p, q *= other.q; reduce(); return *this; } PQ &operator/=(const PQ &other) { p *= other.q, q *= other.p; reduce(); return *this; } PQ operator+(const PQ &other) const { return PQ(*this) += other; } PQ operator-(const PQ &other) const { return PQ(*this) -= other; } PQ operator*(const PQ &other) const { return PQ(*this) *= other; } PQ operator/(const PQ &other) const { return PQ(*this) /= other; } PQ operator-() const { return PQ(*this) *= Bint(-1); } void reduce() { Bint tmp = gcd(abs(p), abs(q)); p/=tmp, q/=tmp; if(q < 0) p *= -1, q *= -1; } }; const Bint M = 998244353; Bint solve() { Bint a, b, c; cin >> a >> b >> c; PQ res(0, 1); Bint t = a; rep(i, 135) { Bint tmp = t, cnt = 0; while(tmp % c == 0) tmp /= c, cnt++; chmax(res, PQ(cnt, i+1)); t *= a; } return (res.p * b / res.q) % M; } int main() { int t; cin >> t; rep(i, t) cout << solve() << '\n'; return 0; }