n=int(input()) q=[0]*7 q[0]=1 M=10**9+7 for _ in range(n): nq=q.copy() d,l=map(int,input().split()) for i in range(7): j=(i*pow(10,l,7)+d*(pow(10,l,7)-1)*pow(9,7-2,7))%7 nq[j]+=q[i] nq[j]%=M q=nq print(sum(i*q[i] for i in range(7))%M)