#include using namespace std; using ll=long long; using pii=pair; #define all(a) a.begin(),a.end() #define pb push_back #define sz(a) ((int)a.size()) template struct Modint{ int val; Modint(int _val=0){val=_val%mod;if(val<0) val+=mod;} Modint(ll _val){val=_val%mod;if(val<0) val+=mod;} Modint operator +(const Modint& o) const { Modint res; res.val=val+o.val; if(res.val>=mod) res.val-=mod; return res; } Modint operator +(const int& o) const {return Modint(val+o);} Modint operator +(const ll& o) const {return Modint(val+o);} Modint operator -() const { Modint res; res.val=-val; if(res.val<0) res.val+=mod; return res; } Modint operator -(const Modint& o) const { Modint res; res.val=val-o.val; if(res.val<0) res.val+=mod; return res; } Modint operator -(const int& o) const {return Modint(val-o);} Modint operator -(const ll& o) const {return Modint(val-o);} Modint operator *(const Modint& o) const {return ((ll)val)*o.val%mod;} Modint operator *(const int& o) const {return Modint((ll(val))*o);} Modint operator *(const ll& o) const {return Modint((ll(val))*(o%mod));} Modint operator +=(const Modint& o){return *this=(*this)+o;} Modint operator -=(const Modint& o){return *this=(*this)-o;} Modint operator *=(const Modint& o){return *this=(*this)*o;} Modint Pow(ll b) const {Modint res(1); for(Modint tmp(val); b; tmp*=tmp,b>>=1) if(b&1) res*=tmp; return res;} Modint Pow(const Modint& a, ll b) const {return a.Pow(b);} inline Modint inv() const {return (*this).Pow(mod-2);} Modint operator /(const Modint& o) const {return *this*o.inv();} Modint operator /(const ll& o) const {return *this*Modint(o).inv();} bool operator ==(const Modint& o) const {return val==o.val;} bool operator !=(const Modint& o) const {return val!=o.val;} }; template ostream& operator << (ostream& o, Modint x){return o << x.val;} template Modint operator +(const int& x, const Modint& y){return Modint(x+y.val);} template Modint operator +(const ll& x, const Modint& y){return Modint(x+y.val);} template Modint operator -(const int& x, const Modint& y){return Modint(x-y.val);} template Modint operator -(const ll& x, const Modint& y){return Modint(x-y.val);} template Modint operator *(const int& x, const Modint& y){return Modint(x*y.val);} template Modint operator *(const ll& x, const Modint& y){return Modint(x%mod*y.val);} const int MOD=998244353; using modint=Modint; vector inv,fac,invfac; void init_comb(int N){ inv.resize(N),fac.resize(N),invfac.resize(N); inv[1]=1,fac[0]=1,invfac[0]=1; for(int i=2; in||m<0?modint(0):fac[n]*invfac[m]*invfac[n-m];} template struct matrix: array,N>{ matrix(){for(int i=0; i=0); matrix res=id(),cur=*this; for(; x; cur=cur*cur,x>>=1) if(x&1) res=res*cur; return res; } }; template ostream& operator << (ostream& o, matrix x){ for(int i=0; i> n >> m; if(n>m) swap(n,m); int res=0; if(n==0){ cout << "1\n"; } else if(n==m&&false){ cout << dp[n]*(n+1)*dp[n]*(n+1)+dp[n-1]*dp[n-1]*n*n*n << "\n"; } else{ //z=x*n+y*(2*n+1) matrix mat; mat[1][0]=1,mat[1][1]=0; mat[0][0]=2*n+1,mat[0][1]=n; mat=mat^(m-n); modint x=mat[1][0]*dp[n]+mat[1][1]*dp[n-1]; modint y=mat[0][0]*dp[n]+mat[0][1]*dp[n-1]; modint res=0; res+=y*dp[n-1]*n*2; res+=x*dp[n-1]*n; if(n>1) res+=y*dp[n-2]*(n-1); cout << res << "\n"; } } signed main(){ ios_base::sync_with_stdio(0),cin.tie(0); dp[0]=1,dp[1]=2; for(int i=2; i> t; while(t--) ahcorz(); }