#include <iostream>
using namespace std;
typedef long long ll;

const ll MOD = 998244353;

ll modpow(ll x, ll n){
    ll res = 1, r = x;
    while(n){
        if(n & 1) res = res * r % MOD;
        r = r * r % MOD;
        n >>= 1;
    }
    return res;
}

ll calc(ll k, ll n){
    n %= MOD;
    return k * (k + 1) % MOD *
        ((MOD -
          k * (k + 1) % MOD * modpow(8, MOD - 2) % MOD +
          n * (k * 2 + 1) % MOD * modpow(12, MOD - 2) % MOD +
          (n + 1) * modpow(4, MOD - 2)) % MOD) % MOD;
}

int main()
{
    int n;
    cin >> n;
    ll t[300005], v[300005];
    for(int i = 0; i < n; i++) cin >> t[i] >> v[i];
    v[n] = 0;
    ll s[300005];
    s[0] = 0;
    for(int i = 1; i <= n; i++) s[i] = (s[i - 1] + t[i - 1]) % MOD;
    ll ans = 0;
    for(int i = n; i > 0; i--){
        ans = (ans + calc(s[i], s[n]) * (v[i - 1] + MOD - v[i])) % MOD;
    }
    cout << ans << endl;
}