#include using namespace std; #define int long long #define MAXN 200005 #define bl(x) (((x)-1)/B+1) const int MOD(998244353); const int inv2(499122177); int t, B, res(1); int fac[MAXN], ifac[MAXN], pw[MAXN], ans[MAXN]; struct Que{int l, r, id;}que[MAXN]; int qpow(int x, int k=MOD-2){int res(1); for (; k; k>>=1, (x*=x)%=MOD) if (k&1) (res*=x)%=MOD; return res;} int C(int n, int m){assert(n >= m); return fac[n]*ifac[m]%MOD*ifac[n-m]%MOD;} signed main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); fac[0] = ifac[0] = pw[0] = 1; for (int i(1); i> t; for (int i(1); i<=t; ++i) cin >> que[i].r >> que[i].l, ans[que[i].id=i] = (pw[que[i].r]-1+MOD)%MOD; B = MAXN/sqrt(t); // cerr << bl(que[1].l) << ' ' << bl(que[2].l) << '\n'; sort(que+1, que+t+1, [](Que a, Que b){return bl(a.l) == bl(b.l) ? (bl(a.l) & 1 ? a.r < b.r : a.r > b.r) : bl(a.l) < bl(b.l);}); for (int i(1), l(1), r(1); i<=t; ++i){ while (l > que[i].l) (res += MOD-C(r-1, --l)) %= MOD; while (r < que[i].r) (res += res+MOD-C(r++, l-1)) %= MOD; // cerr << res << '\n'; while (l < que[i].l) (res += C(r-1, l++)) %= MOD; while (r > que[i].r) res = (res+C((--r)-1, l-1))*inv2%MOD; (ans[que[i].id] *= res) %= MOD; } for (int i(1); i<=t; ++i) cout << ans[i] << '\n'; return 0; }