import sys input = sys.stdin.readline mod=10**9+7 K=int(input()) DL=[tuple(map(int,input().split())) for i in range(K)] DL.reverse() DP=[[0]*7 for i in range(6)] # DP[i][j]で、桁数 mod 6がi個、答え mod 7がjとなるものの個数 DP[0][0]=1 P=pow(9,5,7) Q=[pow(10,i,7) for i in range(10)] for D,L in DL: NDP=[[0]*7 for i in range(6)] x=D*(pow(10,L,7)-1)*P%7 for i in range(6): for j in range(7): NDP[i][j]+=DP[i][j] NDP[(i+L)%6][(j+x*Q[i])%7]+=DP[i][j] for i in range(6): for j in range(7): DP[i][j]=NDP[i][j]%mod ANS=0 for i in range(6): for j in range(7): ANS+=DP[i][j]*j ANS%=mod print(ANS)