N=int(input()) u15=[0]*60 v15=[0]*60 v15[0]=10 mod=998244353 for j in range(1,60): x,y=(u15[j-1]**2%mod)*15+2*v15[j-1]*u15[j-1],v15[j-1]**2 if y>=15: x+=y//15 y%=15 x%=mod y%=mod u15[j],v15[j]=x,y u5=[0]*60 v5=[0]*60 u5[0]=2 gg=[1]*60 for j in range(1,60): gg[j]=gg[j-1]*2 for j in range(1,60): x,y=(u5[j-1]**2%mod)*5+2*v5[j-1]*u5[j-1],v5[j-1]**2 if y>=5: x+=y//5 y%=5 x%=mod y%=mod u5[j],v5[j]=x,y u0=[0]*60 v0=[0]*60 v0[0]=10 for j in range(1,60): v0[j]=v0[j-1]**2 v0[j]%=mod u3=[0]*60 v3=[0]*60 u3[0]=3 v3[0]=1 for j in range(1,60): x,y=(u3[j-1]**2%mod)*3+2*v3[j-1]*u3[j-1],v3[j-1]**2 if y>=3: x+=y//3 y%=3 x%=mod y%=mod u3[j],v3[j]=x,y def g(l,c): x,y=0,1 if c==15: for k in range(60): if gg[k]>l: break if (l>>k)&1: a,b=u15[k],v15[k] x2,y2=(x*a%mod)*15+y*a+b*x,b*y x2%=mod y2%=mod if y2>=15: x2+=y2//15 y2%=15 x,y=x2,y2 elif c==5: for k in range(60): if gg[k]>l: break if (l>>k)&1: a,b=u5[k],v5[k] x2,y2=(x*a%mod)*5+y*a+b*x,b*y x2%=mod y2%=mod if y2>=5: x2+=y//5 y2%=5 x,y=x2,y2 elif c==3: for k in range(60): if gg[k]>l: break if (l>>k)&1: a,b=u3[k],v3[k] x2,y2=(x*a%mod)*3+y*a+b*x,b*y x2%=mod y2%=mod if y2>=3: x2+=y//3 y2%=3 x,y=x2,y2 else: for k in range(60): if gg[k]>l: break if (l>>k)&1: y*=v0[k] y%=mod return x,y def f(a,l,c): if l==1: return a//c,a%c if l&1: k1,k2=f(a,l-1,c) x,y=10*k1,10*k2+a if y>=c: x+=y//c y%=c x%=mod return x,y else: k1,k2=f(a,l//2,c) a1,a2=g(l//2,c) x,y=((k1*a1)%mod)*c+k2*a1+(a2+1)*k1,k2*(a2+1) if y>=c: x+=y//c y%=c return x,y def h(n): if n==0: return 0 ans=1-(n+1)*pow(10,n,mod)+n*pow(10,n+1,mod) ans%=mod ans*=pow(81,-1,mod) ans%=mod ans*=480 ans%=mod w=10*(pow(10,n,mod)-1) w%=mod w*=pow(9,-1,mod) w%=mod w*=96 result=ans+w result%=mod return result count=0 ans='' L=[] for i in range(N): v,l=map(int,input().split()) if count+l<=2: ans+=str(v)*l count+=l L.append((v,l)) def t(a,l,count,c): x1,y1=f(a,l,c) x2,y2=g(count,c) x,y=((x1*x2)%mod)*c+y1*x2+x1*y2,y1*y2 if y>=c: x+=y//c y%=c return x,y if count<=2: result=0 x=int(ans) for y in range(1,x+1): if y%15==0: result+=8 elif y%5==0: result+=4 elif y%3==0: result+=4 else: z=str(y) result+=len(z) print(result) exit() a0,a1=0,0 b0,b1=0,0 c0,c1=0,0 d=0 count=0 for i in range(N-1,-1,-1): v,l=L[i][:] a2,a3=t(v,l,count,15) a0+=a2 a1+=a3 a0+=a1//15 a1%=15 b2,b3=t(v,l,count,5) b0+=b2 b1+=b3 b0+=b1//5 b1%=5 c2,c3=t(v,l,count,3) c0+=c2 c1+=c3 c0+=c1//3 c1%=3 d2,d3=t(v,l,count,mod) d+=d3 d%=mod count+=l u=10**9+7 result=a0*8+(b0-a0)*4+(c0-a0)*4 result%=mod d-=a0+(b0-a0)+(c0-a0) _,k=f(9,count-1,mod) k1,_=f(9,count-1,15) k2,_=f(9,count-1,5) k3,_=f(9,count-1,3) w=k-(k1+(k2-k1)+(k3-k1)) d-=w result+=d*count result+=h(count-3) result%=mod for x in range(1,100): if x%5!=0 and x%3!=0: y=str(x) result+=len(y) result%=mod print(result)