""" 111111 mod 7か… 10^L 倍 + """ import sys from sys import stdin def DL_seven(D,L): #DDDDDDDDDDD ← L個をmod7で求める ret = [D % 7] while True: nex = (ret[-1] * 10 + D) % 7 if nex == ret[0]: break ret.append(nex) #print (ret) return ret[(L-1) % len(ret)] #print (DL_seven(1,4)) K = int(stdin.readline()) dp = [0] * 7 dp[0] = 1 mod = 10**9+7 for loop in range(K): D,L = map(int,stdin.readline().split()) ndp = [ i % mod for i in dp ] ndl = DL_seven(D,L) #追加する場合 for i in range(7): nex = (i * pow(10,L,7) + ndl) % 7 ndp[nex] += dp[i] dp = ndp dp[0] -= 1 ans = 0 for i in range(7): ans += dp[i] * i ans %= mod print (ans)