// TLE: T(n+m) #include #include #include #include using mint = atcoder::modint998244353; mint solve(uint32_t n, uint64_t m) { if (n > m) { uint64_t tmp = n; n = m, m = tmp; } std::vector f(n + m + 1); f[0] = 1; for (uint64_t i = 1; i <= n + m; ++i) { if (i <= n) { f[i] += f[i - 1] * 2 * i; if (i >= 2) f[i] += f[i - 2] * (i - 1); } else if (i <= m) { f[i] += f[i - 1] * (2 * n + 1); if (i >= 2) f[i] += f[i - 2] * n; } else { f[i] += f[i - 1] * 2 * (n + m + 1 - i); if (i >= 2) f[i] += f[i - 2] * (n + m + 1 - i); } } return f[n + m]; } int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); uint32_t t; std::cin >> t; for (uint32_t case_id = 0; case_id < t; ++case_id) { uint32_t n; uint64_t m; std::cin >> n >> m; std::cout << solve(n, m).val() << '\n'; } }