#include using namespace std; typedef long long LL; typedef pair PII; const int N = 2e5 + 10, Base = 131, mod = 998244353; const int INF = 0x3f3f3f3f; struct Query { int x, y, id; } q[N]; int n, len; int fact[N], infact[N]; int s[N], ans[N]; int qmi(int a, int k) { int res = 1; while (k) { if (k & 1) res = (LL)res * a % mod; a = (LL)a * a % mod; k >>= 1; } return res; } void init() { fact[0] = 1; for (int i = 1; i < N; i ++ ) fact[i] = (LL)fact[i - 1] * i % mod; infact[N - 1] = qmi(fact[N - 1], mod - 2); for (int i = N - 2; i >= 0; i -- ) infact[i] = (LL)infact[i + 1] * (i + 1) % mod; int tmp = 2; s[0] = 1; for (int i = 1; i < N; i ++ , tmp = tmp * 2 % mod) s[i] = (s[i - 1] + tmp) % mod; } int C(int b, int a) { if (a > b || a < 0 || b < 0) return 0; return (LL)fact[b] * infact[a] % mod * infact[b - a] % mod; } bool cmp(Query a, Query b) { if (a.x / len == b.x / len) return a.y < b.y; return a.x / len < b.x / len; } int modu(LL x) { return (x % mod + mod) % mod; } signed main() { // freopen("bigdata.in", "r", stdin); // freopen("bigdata.out", "w", stdout); init(); scanf("%d", &n); for (int i = 1; i <= n; i ++ ) { int a, b; scanf("%d%d", &a, &b); q[i] = {b - 1, a - 1, i}; } len = sqrt(n); sort(q + 1, q + 1 + n, cmp); int _2 = qmi(2, mod - 2); for (int i = 1, l = 0, r = 1, res = 1; i <= n; i ++ ) { int x = q[i].x, y = q[i].y; while (l > x) res = modu(res - C(r, l)), l -- ; while (l < x) l ++ , res = modu(res + C(r, l)); while (r > y) r -- , res = (LL)(res + C(r, l)) * _2 % mod; while (r < y) r ++ , res = modu((LL)res * 2 - C(r - 1, l)); ans[q[i].id] = (LL)res * s[y] % mod; } for (int i = 1; i <= n; i ++ ) printf("%d\n", ans[i]); cerr << clock() << endl; return 0; }