import sys input=sys.stdin.readline N=int(input()) T=[0]*N V=[0]*N Mod=998244353 for i in range(N): T[i],V[i]=map(int,input().split()) P=[0]*N Q=[0]*N P[0]=1 Q[0]=T[0] for i in range(1,N): P[i]=Q[i-1]+1 Q[i]=P[i]+T[i]-1 P[i]%=Mod Q[i]%=Mod M=sum(T)%Mod twenty_four_inv=pow(24,Mod-2,Mod) def S(b): x=b x*=b+1 x%=Mod x*=b+2 x%=Mod x*=4*M+3-3*b return x%Mod X=0 for v,p,q in zip(V,P,Q): X+=v*(S(q)-S(p-1)) X%=Mod print((twenty_four_inv*X)%Mod)