#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
const long long INF = (1e+18) + 7;
const long double eps = 1e-6;
const long double pi = acos(-1.0);
long long mod_pow(long long a, long long n) {
  long long res = 1;
  while (n) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}
struct modint {
  long long n;
  modint() : n(0) { ; }
  modint(long long m) : n(m) {
    if (n >= mod)
      n %= mod;
    else if (n < 0)
      n = (n % mod + mod) % mod;
  }
  operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) {
  a.n += b.n;
  if (a.n >= mod) a.n -= mod;
  return a;
}
modint operator-=(modint &a, modint b) {
  a.n -= b.n;
  if (a.n < 0) a.n += mod;
  return a;
}
modint operator*=(modint &a, modint b) {
  a.n = ((long long)a.n * b.n) % mod;
  return a;
}
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
  if (n == 0) return modint(1);
  modint res = (a * a) ^ (n / 2);
  if (n % 2) res = res * a;
  return res;
}
long long inv(long long a, long long p) {
  return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }
const int max_n = 500;
modint fact[max_n], factinv[max_n];
void init_f() {
  fact[0] = modint(1);
  for (int i = 0; i < max_n - 1; i++) {
    fact[i + 1] = fact[i] * modint(i + 1);
  }
  factinv[max_n - 1] = modint(1) / fact[max_n - 1];
  for (int i = max_n - 2; i >= 0; i--) {
    factinv[i] = factinv[i + 1] * modint(i + 1);
  }
}
modint comb(int a, int b) {
  if (a < 0 || b < 0 || a < b) return 0;
  return fact[a] * factinv[b] * factinv[a - b];
}
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
bool exi[50][2500];
modint dp[51][2500];
modint rdp[51][2501];
modint num[2500][51];
void solve() {
  int n;
  cin >> n;
  vector<long long> l(n), r(n);
  for (int i = 0; i < n; i++) {
    cin >> l[i] >> r[i];
  }
  vector<pair<long long, long long> > seg;
  for (int i = 0; i < n; i++) {
    vector<pair<long long, long long> > nex;
    long long le = l[i], ri = r[i] + 1;
    for (pair<long long, long long> p : seg) {
      if (p.second <= l[i]) {
        nex.push_back(p);
      } else if (p.first >= r[i] + 1) {
        nex.push_back(p);
      } else {
        if (p.first < le) {
          nex.push_back({p.first, le});
        } else {
          if (le != p.first) nex.push_back({le, p.first});
          le = p.first;
        }
        if (p.second < ri) {
          if (le != p.second) nex.push_back({le, p.second});
          le = p.second;
        } else {
          if (le != ri) nex.push_back({le, ri});
          if (ri != p.second) nex.push_back({ri, p.second});
          le = ri;
        }
      }
    }
    if (le != ri) nex.push_back({le, ri});
    sort((nex).begin(), (nex).end());
    nex.erase(unique((nex).begin(), (nex).end()), nex.end());
    swap(nex, seg);
  }
  seg.push_back({INF, INF + 1});
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < seg.size(); j++) {
      if (l[i] <= seg[j].first && seg[j].second <= r[i] + 1) exi[i][j] = true;
    }
  }
  int len = seg.size();
  for (int j = 0; j < len; j++) {
    for (int k = j + 1; k < len; k++) {
      long long ma = max(seg[j].first, seg[k].first);
      long long mi = min(seg[j].second, seg[k].second);
      long long len = (mi - ma);
      assert(len <= 0);
    }
  }
  dp[0][len - 1] = 1;
  for (int j = 0; j < len; j++) {
    modint w = seg[j].second - seg[j].first;
    for (int l = 1; l <= n; l++) {
      num[j][l] = 1;
      for (modint i = 1; (int)i <= l; i += 1) {
        num[j][l] = num[j][l] * (w + (modint)l - i);
        num[j][l] = num[j][l] / i;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < len; j++) rdp[i][j + 1] = rdp[i][j] + dp[i][j];
    modint leng = r[i] - l[i] + 1;
    for (int j = 0; j < len; j++) {
      if (!exi[i][j]) continue;
      modint w = seg[j].second - seg[j].first;
      modint b = 1;
      for (int to = i; to < n; to++) {
        if (!exi[to][j]) break;
        modint s = num[j][to - i + 1];
        b = b * (modint)(r[to] - l[to] + 1);
        s = s / b;
        dp[to + 1][j] += (rdp[i][len] - rdp[i][j + 1]) * s;
      }
    }
  }
  modint ans = 0;
  for (int j = 0; j < len; j++) ans += dp[n][j];
  cout << ans << endl;
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  solve();
  char nyaa;
  cin >> nyaa;
  return 0;
}
