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):
    if x==1:
        return 1
    if x%2==1:
        return (rep(x-1)*10+1)%MOD
    else:
        half=rep(x//2)
        return (half*pow(10,x//2,MOD)+half)%MOD

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*=pow(10,l,MOD*15)
    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)