#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include //eolibraries #define lnf 3999999999999999999 #define inf 999999999 #define fi first #define se second #define pb push_back #define ll long long #define all(c) (c).begin(),(c).end() #define sz(c) (ll)(c).size() #define make_unique(a) sort(all(a)),a.erase(unique(all(a)),a.end()) #define pii pair #define rep(i,n) for(ll i = 0 ; i < n ; i++) #define drep(i,n) for(ll i = n-1 ; i >= 0 ; i--) #define crep(i,x,n) for(ll i = x ; i < n ; i++) #define vi vector #define vec(...) vector<__VA_ARGS__> #define fcin ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0); //eodefine using namespace std; const ll max_n = 103002; ll mod=998244353; ll sub(ll a , ll b){ a%=mod; b%=mod; return (((a-b)%mod)+mod)%mod; } ll prod(ll a , ll b){ a%=mod; b%=mod; return ((a*b)%mod); } ll add(ll a , ll b){ a%=mod; b%=mod; return (a+b)%mod; } ll binpow(ll a, ll b) { a %= mod; ll res = 1; while (b) { if (b%2) res = res * a % mod; a = a * a % mod; b /= 2; } return res % mod; } ll f(ll n,ll m) { ll p0 = prod(n,add(prod(n,n),add(prod(3,n),2))); // ll p1 = sub(prod(4,m),add(prod(3,n),3)); ll p1=sub(prod(4,m),add(3,prod(3,n))); return (prod(p0,4*m-3*n+3))*binpow(24,mod-2)%mod; } ll n; int main(){ fcin; cin>>n; vec(pii) a; ll m=0; rep(_,n) { ll t,v; cin>>t>>v; a.pb({t,v}); m+=t; } ll ans=0,j=0; rep(i,n) { ll x=f(j+a[i].fi,m); x = sub(x,f(j,m)); ans=add(ans,prod(x,a[i].se)); j+=a[i].fi; } cout<