#include using namespace std; const int MOD = 998244353; istream& operator >>(istream& is, __int128_t &x){ string S; is >> S; x = 0; for (char c : S){ x = x * 10 + (c - '0'); } return is; } __int128_t gcd(__int128_t A, __int128_t B){ if (B == 0){ return A; } else { return gcd(B, A % B); } } __int128_t lcm(__int128_t A, __int128_t B){ return A / gcd(A, B) * B; } int main(){ int T; cin >> T; for (int i = 0; i < T; i++){ __int128_t X, A, B; cin >> X >> A >> B; if (A == B){ if (X % A == 0){ cout << 1 << endl; } else { cout << 2 << endl; } } else { if (A > B){ swap(A, B); } __int128_t L = lcm(A, B); X %= L; if (X == 0){ cout << 1 << endl; } else { __int128_t cntB = (L - X) / B + 1; __int128_t cntA = cntB; if ((X + A - 1) / A * A - X < (X + B - 1) / B * B){ cntA++; } __int128_t ans = cntA + cntB - 1; if (X % A != 0 && X % B != 0){ ans++; } cout << (int) (ans % MOD) << endl; } } } }