#include using namespace std; constexpr int mod = 998244353; long long binary_gcd(long long a,long long b) { if(a == 0 || b == 0) return a+b; int k = 0; while(!((a&1)|(b&1))) { k++; a >>= 1; b >>= 1; } while (a != b) { while(!(a&1)) a >>= 1; while(!(b&1)) b >>= 1; if(a > b) a -= b; else if(a < b) b -= a; } return a << k; } int main() { int t; cin >> t; while(t--) { long long x,a,b; cin >> x >> a >> b; if(x%a == 0 && x%b == 0) { cout << 1 << "\n"; continue; } if(a == b) { cout << 2 << "\n"; continue; } if(a > b) swap(a,b); long long ma = (x-1)/a*a+a; long long mb = (x-1)/b*b+b; if(ma == mb) { cout << 2 << "\n"; continue; } long long g = binary_gcd(a,b); a /= g; if(x/a >= b) { long long k = a*b; long long mk = (x/k+1)*k; long long ans = (mk-mb)/b+1; ans *= 2; if(ma < mb) ans++; if(min(ma,mb) == x) ans--; cout << ans%mod << "\n"; } else { long long ans = (a-mb/b)+1; ans *= 2; if(ma < mb) ans++; if(min(ma,mb) == x) ans--; cout << ans%mod << "\n"; } } }