#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; constexpr int mod = 998244353; void mpl(int &x,int y) { x += y; if(x >= mod) x -= mod; } vector> Mul(vector> A,vector> B) { vector>ans(A.size(),vector(A.size())); for(int i = 0; i < A.size(); i++) { for(int j = 0; j < A.size(); j++) { for(int k = 0; k < A.size(); k++) { ans[i][j] += 1ll*A[i][k]*B[k][j]%mod; if(ans[i][j] >= mod) ans[i][j] -= mod; } } } return ans; } vector> Pow(vector> A,long long B,int a,int b) { vector>ans(A.size(),vector(A.size())); for(int i = 0; i < A.size(); i++) { ans[i][i] = 1; } ans[0][0] = a; ans[1][1] = b; while (B) { if(1 & B) { ans = Mul(ans,A); } A = Mul(A,A); B /= 2; } return ans; } int dp[10010010]; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int t; cin >> t; dp[0] = 1; for(int i = 0; i <= 10000000; i++) { mpl(dp[i+1],2ll*dp[i]*(i+1)%mod); mpl(dp[i+2],1ll*dp[i]*(i+1)%mod); } while(t--) { long long n,m; cin >> n >> m; if(n > m) { swap(n,m); } if(n == 0) { cout << 1 << "\n"; continue; } if(n == m) { cout << (1ll*dp[n]*dp[n]%mod+1ll*dp[n-1]*dp[n-1]%mod*n%mod)%mod << "\n"; } vector>res(2,vector(2)); res[0][0] = 2*n+1; res[0][1] = n; res[1][0] = 1; res = Pow(res,m-n,dp[n],1ll*dp[n-1]*n%mod); cout << (1ll*(res[0][0]+res[1][0])*dp[n]%mod+1ll*(res[0][1]+res[1][1])*dp[n-1]%mod)%mod << "\n"; } }