#!/usr/bin/env PyPy3 from collections import Counter, defaultdict, deque import itertools import re import math from functools import reduce import operator import bisect from heapq import * import functools mod=10 ** 9 + 7 import sys input=sys.stdin.readline k = int(input()) li = [0,1,4,6,5,2] dp = [[0] * 7 for _ in range(k+1)] ans = 0 for i in range(k): d,l = map(int,input().split()) p10 = pow(10,l,7) xx = li[l % 6] * d % 7 dp[i+1][xx] += 1 for j in range(7): dp[i+1][(j * p10 + xx) % 7] += dp[i][j] dp[i+1][(j * p10 + xx) % 7] %= mod for j in range(7): ans += dp[i+1][j] * j % mod dp[i+1][j] += dp[i][j] print(ans)