#include #define LL long long using namespace std; const int N = 2e5 + 5, mod = 998244353; LL t, ans[N], qwq[N][2], d; struct zs { LL n, m, k, i; } a[N]; bool cmp (zs &x, zs &y) { if (x.k == y.k) return x.m < y.m; return x.k < y.k; } LL qpow (LL x, LL y) { LL ret = 1; for (; y; y >>= 1) { if (y & 1) { (ret *= x) %= mod; } (x *= x) %= mod; } return ret; } LL C (LL x, LL y) { return qwq[x][0] * qwq[y][1] % mod * qwq[x - y][1] % mod; } int main () { ios::sync_with_stdio(0), cin.tie(0); qwq[0][0] = qwq[0][1] = 1; for (int i = 1; i <= 2e5; i++) { qwq[i][0] = qwq[i - 1][0] * i % mod; qwq[i][1] = qpow(qwq[i][0], mod - 2); } cin >> t; d = sqrt(t); for (int i = 1; i <= t; i++) { cin >> a[i].n >> a[i].m; a[i].i = i; a[i].n--, a[i].m--; a[i].k = a[i].n / d; } sort(a + 1, a + t + 1, cmp); ans[0] = 1; for (int i = 1, n = 0, m = 0; i <= t; i++) { for (; n < a[i].n; ans[0] = (ans[0] * 2 % mod - C(n++, m) + mod) % mod); for (; m > a[i].m; ans[0] = (ans[0] - C(n, m--) + mod) % mod); for (; m < a[i].m; ans[0] = (ans[0] + C(n, ++m)) % mod); for (; n > a[i].n; ans[0] = (ans[0] + C(--n, m)) % mod * qwq[2][1] % mod); ans[a[i].i] = ans[0] * (qpow(2, a[i].n + 1) - 1) % mod; } for (int i = 1; i <= t; i++) { cout << ans[i] << '\n'; } return 0; }