#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9+7;

string origine;

int modExp(long long a, long long b, int p) {
	int ret = 1;
	for (a = (a%p+p)%p; b; b >>= 1, a = a*a%p) if (b&1) ret = ret*a%p;
	return ret;
}

bool isDig(char c) {
	return '0' <= c && c <= '9';
}

long long calcExp(string exp) {
	if (!exp.size()) return 0;
	int cur = 0;
	if (exp[0] == '-' || exp[0] == '+') cur++;
	long long ret = 0;
	while (cur < exp.size()) {
		int sig = 1;
		if (cur && exp[cur - 1] == '-') sig = -1;
		long long val = 1, now = 0;
		while (cur < exp.size()) {
			if (exp[cur] == '*') {
				val = val * now % MOD;
				now = 0;
			}
			if (isDig(exp[cur])) now = (now * 10 + exp[cur] - '0') % MOD;
			if (exp[cur] == '+' || exp[cur] == '-') {
				++cur;
				break;
			}
			++cur;
		}
		val = val * now % MOD;
		ret = (ret + val * sig) % MOD;
	}
	ret = (ret % MOD + MOD) % MOD;
	return ret;
}

string toStr(long long val) {
	string ret;
	if (!val) {
		ret.push_back('0');
		return ret;
	}
	int flg = 0;
	if (val < 0) flg = 1, val *= -1;
	while (val) {
		ret.push_back('0' + val % 10);
		val /= 10;
	}
	if (flg) ret.push_back('-');
	reverse(ret.begin(), ret.end());
	return ret;
}

long long getVal(string str) {
	long long ret = 0, pw = 1;
	while (str.size()) {
		ret = (ret + pw * (str.back() - '0')) % MOD;
		str.pop_back();
		pw = pw * 10 % MOD;
	}
	return ret;
}

string convert(string exp, int times) {
	if (times == 1) return exp;
	int sz = exp.size();
	int pos = -1;
	string head, tail;
	for (int i = 0; i < sz; i++) {
		if (exp[i] == '+' || exp[i] == '-') {
			pos = i;
			break;
		}
		head.push_back(exp[i]);
	}
	if (pos >= 0) {
		for (int i = pos; i < sz; i++) tail.push_back(exp[i]);
		long long val = calcExp(tail + head);
		val = (val * (times - 1)) % MOD;
		return head + "+" + toStr(val) + tail;
	}
	pos = -1;
	head.clear();
	for (int i = 0; i < sz; i++) {
		if (exp[i] == '*') {
			pos = i;
			break;
		}
		head.push_back(exp[i]);
	}
	if (pos >= 0) {
		for (int i = pos + 1; i < sz; i++) tail.push_back(exp[i]);
		long long val = calcExp(tail + head);
		val = modExp(val, (times - 1), MOD);
		return head + "*" + toStr(val) + "*" + tail;
	}
	string empty;
	return empty;
}

void append(string str, int times) {
	string res = convert(str, times);
	if (res.size()) {
		origine += res;
		return;
	}
	string tail;
	while (origine.size() && isDig(origine.back())) tail.push_back(origine.back()), origine.pop_back();
	reverse(tail.begin(), tail.end());
	long long head = getVal(tail);
	long long val = getVal(str);
	int l = str.size();
	long long inst = head * modExp(10, 1LL * l * times, MOD) % MOD + val * (modExp(10, 1LL * l * times, MOD) - 1) % MOD * modExp((modExp(10, 1LL * l, MOD) - 1) % MOD, MOD - 2, MOD) % MOD;
	inst = ((inst % MOD) + MOD) % MOD;
	origine += toStr(inst);
}

int main() {
	ios_base::sync_with_stdio(0);
	int n; cin >> n;
	while (n--) {
		int times; string tmp; 
		cin >> times >> tmp;
		append(tmp, times);
	}
	cout << calcExp(origine) << endl;
	return 0;
}

