K = int(input()) D = [0]*K L = [0]*K for i in range(K): D[i],L[i] = map(int,input().split()) mod = int(1e9+7) div = int(pow(9,5,7)) dp = [[[0]*7 for j in range(7)] for i in range(K+1)] dp[K][0][1] = 1 for i in reversed(range(K)): mem = pow(10,L[i],7) for j in range(7): for k in range(7): dp[i][j][k] += dp[i+1][j][k] dp[i][j][k] %= mod S = (mem*k%7-k)*div%7*D[i]%7+j S %= 7 if S < 0: S += 7 T = mem*k%7 dp[i][S][T] += dp[i+1][j][k] dp[i][S][T] %= mod ans = 0 for i in range(7): for j in range(7): ans += dp[0][i][j]*i ans %= mod print(ans)