#include #include using namespace std; using mint=atcoder::modint998244353; long gcd(long a,long b) { while(b) { long t=a%b; a=b; b=t; } return a; } main() { int T;cin>>T; for(;T--;) { long X,A,B; cin>>X>>A>>B; if(A>B)swap(A,B); mint ans=1; if(X%A!=0&&X%B!=0) { ans++; X=min((X+A-1)/A*A,(X+B-1)/B*B); } if(X%B!=0) { ans++; X=(X+B-1)/B*B; } long k=X/B; long t=A/gcd(A,B); ans+=(-k%t+t)%t*mint(2); cout<