K = int(input()) D = [] L = [] for _ in range(K): d,l = map(int,input().split()) D.append(d) L.append(l) P = 10 ** 9 + 7 inv = pow(9,5,7) beki = [pow(10,i,7) for i in range(6)] dp = [[0] * 7 for _ in range(6)] dp[0][0] = 1 ans = 0 for i in range(K - 1,-1,-1): d,l = D[i],L[i] nx = [[0] * 7 for _ in range(6)] for j in range(6): for k in range(7): u = (j + l) % 6 tmp = beki[u] - beki[j] tmp = (tmp * inv * d + k) % 7 ans += tmp * dp[j][k] % P ans %= P nx[j][k] += dp[j][k] nx[(j + l) % 6][tmp] += dp[j][k] for j in range(6): for k in range(7): nx[j][k] %= P #print(ans) dp = nx print(ans) t = 0 for i in range(6): for j in range(7): t += dp[i][j] #print(t)