#include <cstdio>
#include <cstdint>
#include <cassert>
#include <cctype>
#include <vector>
#include <algorithm>
#include <string>

constexpr intmax_t mod = 1e9+7;

std::vector<std::string> const ops{"+-", "*"};

intmax_t apply(intmax_t lhs, char op, intmax_t rhs) {
  if ((lhs %= mod) < 0) lhs += mod;
  if ((rhs %= mod) < 0) rhs += mod;
  if (op == '+') return (lhs + rhs) % mod;
  if (op == '-') return (lhs + mod - rhs) % mod;
  if (op == '*') return (lhs * rhs) % mod;
  assert(false);
}

intmax_t parse_int(std::string const& s, size_t& i) {
  assert(isdigit(s[i]));
  intmax_t res = s[i]-'0';
  while (isdigit(s[++i]))
    (res = res*10+s[i]-'0') %= mod;
  res %= mod;
  return res;
}

intmax_t modpow(intmax_t base, intmax_t iexp) {
  intmax_t res = 1;
  base %= mod;
  for (intmax_t dbl = base; iexp; iexp >>= 1) {
    if (iexp & 1) res = res * dbl % mod;
    dbl = dbl * dbl % mod;
  }
  return res;
}

intmax_t modinv(intmax_t n) { return modpow(n, mod-2); }
intmax_t moddiv(intmax_t n, intmax_t d) { return (n % mod) * modinv(d) % mod; }

intmax_t modrep(intmax_t n, intmax_t len, intmax_t irep) {
  intmax_t tenpow = modpow(10, len);

  intmax_t res = n % mod;
  (res *= modpow(tenpow, irep) + mod-1) %= mod;
  (res *= modinv(tenpow + mod-1)) %= mod;
  return res;
}

intmax_t modcat(intmax_t b0, intmax_t b1, intmax_t l1) {
  b0 %= mod;
  return (b0 * modpow(10, l1) % mod + b1) % mod;
}

intmax_t parse(std::string const& s, size_t& i, size_t preced = 0) {
  if (preced == ops.size()) {
    intmax_t base = 0;
    while (isdigit(s[i]) || s[i] == '(') {
      intmax_t b0, l0;
      if (s[i] == '(') {
        size_t si = ++i;
        b0 = parse_int(s, i);
        assert(s[i] == ',');
        l0 = i - si;
        intmax_t rep = parse_int(s, ++i);
        assert(s[i] == ')');
        ++i;
        {
          // rep
          b0 = modrep(b0, l0, rep);
          l0 *= rep;
        }
      } else {
        size_t si = i;
        b0 = parse_int(s, i);
        l0 = i - si;
      }
      {
        // merge
        base = modcat(base, b0, l0);
      }
    }
    return base;
  }

  intmax_t res = parse(s, i, preced+1);
  while (i < s.length()) {
    char op = s[i];
    if (!std::count(ops[preced].begin(), ops[preced].end(), op)) break;
    intmax_t cur = parse(s, ++i, preced+1);
    res = apply(res, op, cur);
  }
  if ((res %= mod) < 0) res += mod;
  return res;
}

std::string neko(std::vector<intmax_t> const& r,
                 std::vector<std::string> const& s) {

  std::string res;
  size_t n = r.size();
  for (size_t i = 0; i < n; ++i) {
    intmax_t rr = r[i];
    std::string ss = s[i];

    if (rr == 1) {
      res += ss;
      continue;
    }

    size_t plus = ss.find('+');  // std::min(ss.find('+'), ss.find('-'));
    if (plus+1 != 0) {
      // found
      std::string s0 = ss.substr(0, plus);
      std::string s1 = ss.substr(plus);

      res += s0;
      size_t j = 1;
      intmax_t cur = parse(s1+s0, j) % mod;
      res += ss[plus] + std::to_string(cur * (rr-1) % mod);
      res += s1;
      continue;
    }

    size_t minus = ss.find('-');
    if (minus+1 != 0) {
      // found
      std::string s0 = ss.substr(0, minus);
      std::string s1 = ss.substr(minus);

      res += s0;
      std::string tt = s1+s0;
      size_t additive = std::min(tt.find('+', 1), tt.find('-', 1));
      if (additive+1 != 0) {
        // found
        assert(tt[0] == '-');
        std::string t0(tt.begin()+1, tt.begin()+additive);
        std::string t1 = "0" + tt.substr(additive);
        size_t j = 0;
        intmax_t cur = -parse(t0, j);
        j = 0;
        cur += parse(t1, j);
        if ((cur %= mod) < 0) cur += mod;
        (cur *= (rr-1)) %= mod;
        res += "+" + std::to_string(cur);
      } else {
        // not found
        size_t j = 1;
        intmax_t cur = parse(tt, j);
        if ((cur %= mod) < 0) cur += mod;
        (cur *= (rr-1)) %= mod;
        res += "-" + std::to_string(cur);
      }
      res += s1;
      continue;
    }

    size_t star = ss.find('*');
    if (star+1 != 0) {
      // found
      std::string s0 = ss.substr(0, star);
      std::string s1 = ss.substr(star);

      res += s0;
      size_t j = 1;
      intmax_t cur = parse(s1+s0, j) % mod;
      res += ss[star] + std::to_string(modpow(cur, rr-1));
      res += s1;
      continue;
    }

    {
      // tsurai?
      res += "(" + ss + "," + std::to_string(rr) + ")";
    }
  }
  return res;
}

int main() {
  size_t n;
  scanf("%zu", &n);

  std::vector<intmax_t> r(n);
  std::vector<std::string> s(n);
  for (size_t i = 0; i < n; ++i) {
    char buf[16];
    scanf("%jd %s", &r[i], buf);
    s[i] = buf;
  }

  std::string t = neko(r, s);
  // fprintf(stderr, "t: %s\n", t.c_str());

  size_t i = 0;
  intmax_t res = parse(t, i);
  assert(i == t.length());
  printf("%jd\n", res);
}



Measured memory_bytes: 3668