ll@t; rep(t){ ll@x,@a,@b; sortE(a,b); ll m=a/gcd(a,b); wt(x%b+x%a?((m-x/b%m)*2+(x%a&&(x+1)/+a*a<(x+1)/+b*b))%998244353:1); }