#include <bits/stdc++.h>
using namespace std;
const int N = 51;
const long long mod = 998244353;
int L[N], R[N];
vector<vector<int> > g[N];
vector<int> p[N], H[N];
long long U = 1, D = 1, inv[120], Lag[120];
long long quick(long long a, long long b) {
  long long res = 1;
  while (b) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return res;
}
void pre() {
  inv[0] = 1, inv[1] = 1;
  for (int i = (2); i < (60); ++i) {
    int k = mod / i, r = mod % i;
    inv[i] = -inv[r] * k % mod;
    inv[i] += mod;
  }
  for (int i = (2); i < (60); ++i) inv[i] = inv[i] * inv[i - 1] % mod;
}
long long Lagrange(int h, vector<int> vec, long long sum, int id, int fir,
                   int las) {
  if (id) H[id].push_back(h + 1);
  vector<int> v;
  v.clear();
  int sz = vec.size();
  if (h + 2 <= sz) {
    for (int i = (0); i < (h + 2); ++i) Lag[i + 1] = (vec[i] + Lag[i]) % mod;
    for (int i = (1); i < (h + 3); ++i) Lag[i] = (Lag[i] + sum) % mod;
    int tot = 0;
    for (int i = (fir); i < (las); ++i) {
      if (tot == h + 3) break;
      ++tot;
      long long jie = 1;
      if (i <= h + 2) {
        v.push_back(Lag[i]);
        continue;
      }
      for (int j = (1); j < (h + 3); ++j) jie = jie * (i - j) % mod;
      long long res = 0;
      for (int j = (1); j < (h + 3); ++j) {
        res = (res + Lag[j] * inv[j - 1] % mod * inv[h + 2 - j] % mod * jie %
                         mod * quick(i - j, mod - 2) % mod *
                         (((h + 2 - j) & 1) ? -1 : 1)) %
              mod;
      }
      if (res < 0) res += mod;
      v.push_back(res);
    }
    if (id) g[id].push_back(v);
    long long res = 0;
    if (las - 1 <= h + 2) return Lag[las - 1];
    int i = las - 1;
    long long jie = 1;
    for (int j = (1); j < (h + 3); ++j) jie = jie * (i - j) % mod;
    for (int j = (1); j < (h + 3); ++j)
      res = (res + Lag[j] * inv[j - 1] % mod * inv[h + 2 - j] % mod * jie %
                       mod * quick(i - j, mod - 2) % mod *
                       (((h + 2 - j) & 1) ? -1 : 1)) %
            mod;
    if (res < 0) res += mod;
    return res;
  } else {
    for (int i = (0); i < (sz); ++i) Lag[i + 1] = (vec[i] + Lag[i]) % mod;
    for (int i = (1); i < (sz + 1); ++i) Lag[i] = (Lag[i] + sum) % mod;
    if (id) {
      for (int i = (fir); i < (las); ++i) v.push_back(Lag[i]);
      g[id].push_back(v);
    }
    return Lag[las - 1];
  }
}
int main() {
  pre();
  int n;
  scanf("%d", &n);
  for (int i = (n + 1) - 1; i >= (1); --i)
    scanf("%d%d", &L[i], &R[i]), D = D * (R[i] - L[i] + 1) % mod;
  for (int i = (2); i < (n + 1); ++i) L[i] = max(L[i], L[i - 1]);
  for (int i = (n)-1; i >= (1); --i) R[i] = min(R[i], R[i + 1]);
  L[n + 1] = R[n + 1] = R[n];
  for (int i = (1); i < (n + 1); ++i) {
    if (L[i] > R[i]) {
      printf("0");
      return 0;
    }
  }
  vector<int> v;
  v.clear();
  if (R[1] == L[1])
    v.push_back(1);
  else
    v.push_back(1), v.push_back(1);
  g[1].push_back(v);
  v.clear();
  p[1].push_back(L[1]);
  v.push_back(0);
  g[1].push_back(v);
  p[1].push_back(R[1] + 1);
  H[1].push_back(0);
  long long sum;
  for (int i = (1); i < (n + 1); ++i) {
    sum = 0;
    int sz = p[i].size(), id = 0;
    --sz;
    while (id < sz && p[i][id + 1] <= L[i + 1])
      sum = (Lagrange(H[i][id], g[i][id], sum, 0,
                      max(L[i + 1], p[i][id]) - p[i][id] + 1,
                      p[i][id + 1] - p[i][id] + 1)) %
            mod,
      ++id;
    for (; id < sz; ++id) {
      sum = (Lagrange(H[i][id], g[i][id], sum, i + 1,
                      max(L[i + 1], p[i][id]) - p[i][id] + 1,
                      p[i][id + 1] - p[i][id] + 1)) %
            mod;
      p[i + 1].push_back(max(L[i + 1], p[i][id]));
    }
    if (R[i + 1] < p[i][id]) {
      v.clear();
      v.push_back(0);
      g[i + 1].push_back(v);
      p[i + 1].push_back(R[i + 1] + 1);
    } else {
      v.clear();
      if (R[i + 1] == p[i][id])
        v.push_back(sum);
      else
        v.push_back(sum), v.push_back(sum);
      g[i + 1].push_back(v);
      H[i + 1].push_back(0);
      p[i + 1].push_back(max(L[i + 1], p[i][id]));
      v.clear();
      v.push_back(0);
      g[i + 1].push_back(v);
      p[i + 1].push_back(R[i + 1] + 1);
    }
  }
  long long ans = sum * quick(D, mod - 2) % mod;
  printf("%lld", ans);
}
