#include #include #include #include #include #include #include #include #include #include #include #include #include #include #define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl; #define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; typedef long long ll; template vector> vec2d(int n, int m, T v){ return vector>(n, vector(m, v)); } template vector>> vec3d(int n, int m, int k, T v){ return vector>>(n, vector>(m, vector(k, v))); } template void print_vector(vector v, char delimiter=' '){ if(v.empty()) { cout << endl; return; } for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter; cout << v.back() << endl; } using mint = atcoder::modint1000000007; ostream& operator<<(ostream& os, const mint& m){ os << m.val(); return os; } mint pow(mint a, ll n) { assert(n >= 0); mint ans = 1; while (n > 0) { if (n&1) ans = ans*a; a = a*a; n >>= 1; } return ans; } ll mod_pow(ll a, ll n, ll mod) { ll ans = 1; while (n > 0) { if (n&1) ans = (ans*a)%mod; a = (a*a)% mod; n >>= 1; } return ans; } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; int k; cin >> k; vector d(k), l(k); for(int i = 0; i < k; i++){ cin >> d[i] >> l[i]; } auto dp = vec3d(k+1, 6, 7, mint(0)); dp[k][0][0] = 1; vector rem(6); for(int i = 0; i < 6; i++) rem[i] = mod_pow(10, i, 7); for(int i = k-1; i >= 0; i--){ int len = l[i]%6; int cur = d[i]%7; for(int j = 1; j < len; j++){ cur = cur*10+d[i]; cur %= 7; } for(int j = 0; j < 6; j++){ for(int p = 0; p <= 6; p++){ // 使わない dp[i][j][p] += dp[i+1][j][p]; // 使う int rr = (p+cur*rem[j])%7; dp[i][(j+len)%6][rr] += dp[i+1][j][p]; } } } mint ans = 0; for(int j = 0; j < 6; j++){ for(int k = 0; k < 7; k++){ ans += dp[0][j][k]*k; } } cout << ans << endl; }