#include const int Mod = 998244353; long long gcd(long long a, long long b) { if (a == 0) return b; else return gcd(b % a, a); } int solve(long long X, long long A, long long B) { if (A == B) { if (X % A == 0) return 1; else return 2; } else if (A > B) { A ^= B; B ^= A; A ^= B; } long long G = gcd(A, B), L = A / G, ans = 1, Y = (X + A - 1) / A * A, Z = (X + B - 1) / B * B; if (Y <= Z || X == Z) { if (X != Y) { ans++; X = Y; } } if (X == Z) return ans; ans++; X = Z / B; Y = (X + L - 1) / L * L; ans += (Y - X) * 2; return ans % Mod; } int main() { int T; long long X, A, B; scanf("%d", &T); while (T--) { scanf("%lld %lld %lld", &X, &A, &B); printf("%d\n", solve(X, A, B)); } fflush(stdout); return 0; }