#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

const ll mod = 1e9+7;

ll mod_pow(ll x, ll p){
  ll res = 1;

  while(p){
    if(p&1LL) res = res * x % mod;
    x = x * x % mod;
    p >>= 1;
  }

  return res;
}

mat mat_prod(mat A, mat B){
  size_t h = A.size(), w = B.size();
  mat res(h, vec(w,0));
  for(size_t i=0;i<h;i++){
    for(size_t j=0;j<w;j++){
      for(size_t k=0;k<A[i].size();k++){
	res[i][j] += A[i][k] * B[k][j] % mod;
	res[i][j] %= mod;
      }
    }
  }
  return res;
}	  

mat mat_pow(mat A, ll p){
  int n = A.size();
  mat res(n, vec(n,0));
  for(int i=0;i<n;i++) res[i][i] = 1;

  while(p){
    if(p&1LL) res = mat_prod(res, A);
    A = mat_prod(A,A);
    p >>= 1;
  }

  return res;
}

inline ll calc(const string s, ll &prod, ll &rem){
  ll res = 0;
  for(char c : s){
    if(c == '*'){
      prod *= rem;
      prod %= mod;
      rem = 0;
    }else if(c == '+'){
      res += (prod * rem) % mod;
      res %= mod;
      prod = 1; rem = 0;
    }else if(c == '-'){
      res += (prod * rem) % mod;
      res %= mod;
      prod = mod-1; rem = 0;
    }else{
      rem = rem*10 + (ll)(c-'0');
      rem %= mod;
    }
  }

  return res;
}

int main(){
  ll n;
  cin >> n;

  //temporary result can be represented as "add + prod * rem"
  ll add=0, prod=1, rem=0;

  //tuple<ll,ll> : <times, add before par, prod before par>
  stack< tuple<ll,ll,ll> > open;

  while(n--){
    ll r; string s;
    cin >> r >> s;

    if(s.find("(") != string::npos){
      size_t p = s.find("(");
      string pre = s.substr(0,p), suf = s.substr(p+1);
      add += calc(pre, prod, rem) % mod;
      add %= mod;
      
      open.push( make_tuple(1LL, add, prod) );
      add = 0, prod = 1;

      if(r-1>0){
	add += calc(suf + pre, prod, rem) % mod;
	add %= mod;
	
	open.push( make_tuple(r-1, add, prod) );
	add = 0, prod = 1;
      }

      add += calc(suf, prod, rem) % mod;
      add %= mod;
    }else if(s.find(")") != string::npos){
      size_t p = s.find(")");
      string pre = s.substr(0,p), suf = s.substr(p+1);

      add += calc(pre, prod, rem) % mod;
      add %= mod;

      ll x = (add + (prod*rem%mod)) % mod, t;

      if(r-1>0){
	r--;
	string m = suf + pre;
	size_t k = 0;
	ll cp = 1;
	while(k<m.size() && m[k] == '*'){
	  ll tmp = 0;
	  k++;
	  while(k<m.size() && isdigit(m[k])){
	    tmp = tmp*10 + (ll)(m[k]-'0');
	    tmp %= mod;
	    k++;
	  }
	  cp *= tmp;
	}
	
	ll ca = 0, tp = 1, trem = 0;
	ca += calc(m.substr(k), tp, trem) % mod;
	ca %= mod;
	
	ca = (ca + (tp*trem%mod)) % mod;
	
	while(r){
	  assert( !open.empty() );
	  ll oa,op;
	  tie(t,oa,op) = open.top(); open.pop();
	  
	  if(t > r) open.push( make_tuple(t-r, oa, op) );
	  
	  t = min(t, r);
	  r -= t;
	  
	  //calc f^t(x), where f(x) = cp*op*x + ca+oa
	  (op *= cp) %= mod;
	  (oa += ca) %= mod;
	  
	  mat A = { {op, oa}, {0,1} };
	  A = mat_pow(A, t);
	  x = A[0][0] * x + A[0][1];
	  x %= mod;
	}      	
      }

      tie(t,add,prod) = open.top(); open.pop();
      if(t-1>0) open.push( make_tuple(t-1, add, prod) );
      rem = x;
      
      add += calc(suf, prod, rem) % mod;
      add %= mod;
    }else if(s.find("+") != string::npos || s.find("-") != string::npos ){
      size_t p = min( s.find("+"), s.find("-") );
      string pre = s.substr(0,p+1), suf = s.substr(p+1);
      add += calc(pre, prod, rem) % mod;
      add %= mod;

      add += (r-1) * calc(suf + pre, prod, rem) % mod;
      add %= mod;

      add += calc(suf, prod, rem) % mod;
      add %= mod;
    }else if(s.find("*") != string::npos){
      size_t p = s.find("*");
      string pre = s.substr(0,p+1), suf = s.substr(p+1);
      calc(pre, prod, rem);
 
      ll x = 1;
      calc(suf + pre, x, rem);
      prod *= mod_pow(x, r-1);
      prod %= mod;
      
      calc(suf, prod, rem);
    }else{
      ll x = 0, dummy = 1;
      calc(s, dummy, x);

      mat A = { {mod_pow(10, s.size()), x}, {0,1} };
      A = mat_pow(A, r);
      rem = A[0][0] * rem + A[0][1];
      rem %= mod;
    }
  }

  assert(open.empty());

  add += calc("+0", prod, rem) % mod;
  add %= mod;
  cout << add << endl;
}

Measured memory_bytes: 3232