MOD=998244353 def matrix_mul(a,b,MOD=None): ret=[[0]*len(b[0]) for i in range(len(a))] for i in range(len(a)): for j in range(len(b[0])): for k in range(len(b)): ret[i][j]+=a[i][k]*b[k][j] if MOD: ret[i][j]%=MOD return ret def matrix_pow(x,p,MOD=None): if p==0: for i in range(len(x)): for j in range(len(x)): if i==j: x[i][j]=1 else: x[i][j]=0 return x if p==1: return x if p%2==1: return matrix_mul(matrix_pow(x,p-1,MOD),x,MOD) half=matrix_pow(x,p//2,MOD) return matrix_mul(half,half,MOD) def rep(x): return (giant_r[x//backet]*baby[x%backet]+baby_r[x%backet])%(MOD*15) def power(x): return (giant[x//backet]*baby[x%backet])%(MOD*15) backet=1000000 baby=[1]*(backet+1) for i in range(backet): baby[i+1]=(baby[i]*10)%(MOD*15) giant=[1]*(backet+1) for i in range(backet): giant[i+1]=(giant[i]*baby[-1])%(MOD*15) baby_r=[0]*(backet+1) for i in range(backet): baby_r[i+1]=(baby_r[i]*10+1)%(MOD*15) giant_r=[0]*(backet+1) for i in range(backet): giant_r[i+1]=(giant_r[i]*baby[-1]+baby_r[-1])%(MOD*15) M=int(input()) num=[tuple(map(int,input().split())) for i in range(M)] S=0 N=0 for v,l in num: S+=l N*=power(l) N+=rep(l)*v N%=MOD*15 if S<=1: ans=0 for i in range(1,N+1): if i%15==0: ans+=8 elif i%5==0: ans+=4 elif i%3==0: ans+=4 else: ans+=len(str(i)) print(ans) exit() bet=matrix_pow([[10,10,0],[0,10,0],[1,4,1]],S-2,MOD)[-1] bet[0]*=96 bet[1]*=48 bet[2]*=0 fb=[8,S,S,4,S,4,4,S,S,4,4,S,4,S,S] sz=(N+1-pow(10,S-1,MOD*15))%(MOD*15) ans=sum(bet)+(8*S+32)*(sz//15)+21 for i in range(sz%15): ans+=fb[(i+10)%15] print(ans%MOD)