#include #define lzm0107 using namespace std; using ll = long long; using aii = array; using cd = complex; using ull = unsigned long long; const int Q = 2e5, N = 2e5, P = 998244353, B = 447, INV_2 = 499122177; int fact[N + 10], finv[N + 10]; int pow2[N + 10]; int q; array qry[Q + 10]; int ans[Q + 10]; int qpow(int a, int b) { int res = 1; for (; b; b >>= 1, a = static_cast(a) * a % P) { if (b & 1) { res = static_cast(res) * a % P; } } return res; } int C(int a, int b) { return static_cast(fact[a]) * finv[b] % P * finv[a - b] % P; } void inc(int &a, int b) { if ((a += b) - P >= 0) { a -= P; } } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); fact[0] = 1; for (int i = 1; i <= N; ++i) { fact[i] = static_cast(fact[i - 1]) * i % P; } finv[N] = qpow(fact[N], P - 2); for (int i = N - 1; i >= 0; --i) { finv[i] = static_cast(finv[i + 1]) * (i + 1) % P; } pow2[0] = 1; for (int i = 1; i <= N; ++i) { if ((pow2[i] = pow2[i - 1] << 1) - P >= 0) { pow2[i] -= P; } } cin >> q; for (int i = 1; i <= q; ++i) { cin >> qry[i][0] >> qry[i][1]; --qry[i][0]; --qry[i][1]; qry[i][2] = i; } sort(qry + 1, qry + q + 1, [](auto lhs, auto rhs) -> bool { if (lhs[0] / B != rhs[0] / B) { return lhs[0] < rhs[0]; } else if (lhs[0] / B & 1) { return lhs[1] > rhs[1]; } else { return lhs[1] < rhs[1]; } }); int n = 0, m = 0, res = 1; for (int i = 1; i <= q; ++i) { while (n < qry[i][0]) { if ((res <<= 1) - P >= 0) { res -= P; } inc(res, P - C(n, m)); ++n; } while (m < qry[i][1]) { ++m; inc(res, C(n, m)); } while (m > qry[i][1]) { inc(res, P - C(n, m)); --m; } while (n > qry[i][0]) { --n; inc(res, C(n, m)); res = static_cast(INV_2) * res % P; } int tmp = pow2[qry[i][0] + 1]; inc(tmp, P - 1); ans[qry[i][2]] = static_cast(res) * tmp % P; } for (int i = 1; i <= q; ++i) { cout << ans[i] << '\n'; } return 0; }