k = int(input()) DL = [list(map(int,input().split())) for i in range(k)] mod = 10**9+7 ans = 0 dp = [0]*7 for d,l in DL: p7 = pow(10,l,7) ndp = [0]*7 ad = d*(p7-1)*4%7 ans += ad ndp[ad] += 1 for i in range(7): if dp[i]: nad = (i*p7+ad)%7 ans += dp[i]*nad ndp[nad] += dp[i] ndp[nad] %= mod ndp[i] += dp[i] ndp[i] %= mod dp = ndp print(ans)