n=int(input()) nod=[] mod=998244353 sumt=0 for _ in range(n): t,v=map(int,input().split()) sumt+=t sumt%=mod nod.append((t,v)) s=1 ans=0 rev2=pow(2,mod-2,mod) def f1(x): return (x*(x+1)//2)%mod def f2(x): return (x*(x+1)%mod*(2*x+1)//6)%mod def f3(x): return (f1(x)**2)%mod n=sumt%mod for t,v in nod: g=s+t-1 g%=mod subans=0 subans+=n*(f2(g)-f2(s-1)) subans+=-(f3(g)-f3(s-1)) subans+=(n+1)*(f1(g)-f1(s-1)) subans*=v*rev2 ans+=subans ans%=mod s+=t s%=mod print(ans%mod)