// #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define For(i, a, b) for (int i = (int)(a); (i) < (int)(b); ++(i)) #define rFor(i, a, b) for (int i = (int)(a)-1; (i) >= (int)(b); --(i)) #define rep(i, n) For(i, 0, n) #define rrep(i, n) rFor(i, n, 0) #define fi first #define se second #include #include #include namespace rklib { template struct Factorial { public: Factorial() : Factorial(0) {} Factorial(int n) { fc.resize(n + 1); inv_fc.resize(n + 1); fc[0] = 1; for (int i = 0; i < n; ++i) fc[i + 1] = fc[i] * (i + 1); inv_fc[n] = 1 / fc[n]; for (int i = n - 1; i >= 0; --i) inv_fc[i] = inv_fc[i + 1] * (i + 1); } T fact(int n) { if (n >= (int)fc.size()) extend(n); return fc[n]; } T inv_fact(int n) { if (n >= (int)fc.size()) extend(n); return inv_fc[n]; } T inv(int n) { assert(n > 0); if (n >= (int)fc.size()) extend(n); return inv_fc[n] * fc[n - 1]; } T comb(int n, int r) { if (n < r || r < 0) return 0; if (n >= (int)fc.size()) extend(n); return fc[n] * inv_fc[r] * inv_fc[n - r]; } T perm(int n, int r) { if (n < r || r < 0) return 0; if (n >= (int)fc.size()) extend(n); return fc[n] * inv_fc[n - r]; } private: std::vector fc; std::vector inv_fc; void extend(int n) { int l = fc.size(); int r = l; while (r <= n) r *= 2; fc.resize(r); inv_fc.resize(r); for (int i = l; i < r; ++i) fc[i] = fc[i - 1] * i; inv_fc[r - 1] = 1 / fc[r - 1]; for (int i = r - 2; i >= l; --i) inv_fc[i] = inv_fc[i + 1] * (i + 1); } }; } // namespace rklib #include #include #include namespace rklib { template bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; } template bool chmin_non_negative(T &a, const T &b) { if (a < 0 || a > b) { a = b; return true; } return false; } template T div_floor(T a, T b) { if (b < 0) a *= -1, b *= -1; return a >= 0 ? a / b : (a + 1) / b - 1; } template T div_ceil(T a, T b) { if (b < 0) a *= -1, b *= -1; return a > 0 ? (a - 1) / b + 1 : a / b; } } // namespace rklib using namespace std; using namespace rklib; using lint = long long; using pii = pair; using pll = pair; using mint = atcoder::modint998244353; constexpr int MAX = 200005; constexpr int W = 1500; vector> table(MAX); int main() { int t; scanf("%d", &t); Factorial fc(MAX); rep(i, MAX) { if (i % W != 0) continue; table[i].resize(i + 1, 1); For(j, 1, i + 1) table[i][j] = table[i][j - 1] + fc.comb(i, j); } auto f = [&](int n, int m) { int a = n / W * W; int b = min(m, a); mint res = table[a][b]; For(i, a, n) res = res * 2 - fc.comb(i, b); For(j, b + 1, m + 1) res += fc.comb(n, j); return res; }; rep(tt, t) { int n, m; scanf("%d%d", &n, &m); mint ans = f(n - 1, m - 1); ans *= (mint(2).pow(n) - 1); printf("%u\n", ans.val()); } }