R=range J=lambda:list(map(int,input().split())) N=0 a=f=l=1 P=998244353 for k in R(sum(J())): L,M=J();N+=L*M;g=1 while l