#include #include using namespace std; using namespace atcoder; using mint = modint998244353; const int mod = 998244353; //using mint = modint1000000007; //const int mod = 1000000007; //const int INF = 1e9; //const long long LINF = 1e18; #define rep(i, n) for (int i = 0; i < (n); ++i) #define rep2(i,l,r)for(int i=(l);i<(r);++i) #define rrep(i, n) for (int i = (n-1); i >= 0; --i) #define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i) #define all(x) (x).begin(),(x).end() #define allR(x) (x).rbegin(),(x).rend() #define P pair template inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; } template inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; } template vector> mul(vector>&A, vector>&B) { vector> C(A.size(), vector(B[0].size())); for (int i = 0; i < (int)A.size(); ++i) { for (int j = 0; j < (int)B.size(); ++j) { for (int k = 0; k < (int)C.size(); ++k) C[i][j] += A[i][k] * B[k][j]; } } return C; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int t; cin >> t; vectorf(10000007); f[0] = 1; f[1] = 2; rep2(i, 2, 10000007) f[i] = 2 * i * f[i - 1] + (i - 1) * f[i - 2]; while (t--) { long long n, m; cin >> n >> m; if (n > m)swap(n, m); if (0 == n) { cout << 1 << endl; continue; } // ans = f[m] * f[n] + f[m-1] * f[n-1] * n; vector> mans(2, vector(2)); rep(i, 2)mans[0][i] = f[n - 1]; rep(i, 2)mans[1][i] = f[n]; vector> mpow(2, vector(2)); mpow[0][0] = 0, mpow[0][1] = 1; mpow[1][0] = n, mpow[1][1] = 2 * n + 1; //mpow初期化 long long x = m - n; while (x > 0) { if (1 == x % 2) mans = mul(mpow, mans); mpow = mul(mpow, mpow); x /= 2; } mint ans = 0; ans += mans[1][1] * f[n]; ans += mans[0][0] * f[n - 1] * n; cout << ans.val() << endl; } return 0; }