#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



int N;
char buf[11];

typedef vector<ll> V;
typedef vector<V> MATRIX;

int SIZE = 2;
ll MOD_POW[11];


ll mod_pow(ll x,ll n, ll mod){

	if(n == 0)return 1;
	ll ret = mod_pow(x*x%mod,n/2,mod);
	if(n%2 == 1)ret = ret*x%mod;
	return ret;
}


MATRIX calc(MATRIX left,MATRIX right){

	MATRIX ret(SIZE,V(SIZE));

	for(int i = 0; i < SIZE; i++){
		for(int k = 0; k < SIZE; k++)ret[i][k] = 0;
	}

	for(int row = 0; row < SIZE; row++){
		for(int col = 0; col < SIZE; col++){
			for(int a = 0; a < SIZE; a++){
				ret[row][col] += left[row][a]*right[a][col]%MOD;
			}
		}
	}

	return ret;

}

//MULTのT乗を計算する
MATRIX POW(MATRIX MULT,int count){

	MATRIX ret(SIZE,V(SIZE));

	for(int row = 0; row < SIZE; row++){
		for(int col = 0; col < SIZE; col++){
			if(row == col)ret[row][col] = 1;
			else{
				ret[row][col] = 0;
			}
		}
	}

	while(count > 0){
		if(count%2 == 1)ret = calc(ret,MULT);
		MULT = calc(MULT,MULT);
		count /= 2;
	}

	return ret;
}

int main(){

	MOD_POW[0] = 1;

	for(int i = 1; i <= 10; i++){

		MOD_POW[i] = (MOD_POW[i-1]*10)%MOD;
	}

	scanf("%d",&N);

	queue<ll> NUM,MULT;
	queue<char> OP;

	NUM.push(0);
	OP.push('+');

	int rep_num;
	ll last_num = 0,length;
	bool is_last_num = false;
	char last_op = '+';

	bool is_op,is_plus_minus;

	for(int loop = 0; loop < N; loop++){

		scanf("%d %s",&rep_num,buf);

		is_op = false;
		is_plus_minus = false;

		for(length = 0; buf[length] != '\0'; length++){

			switch(buf[length]){
			case '+':
			case '-':
				is_op = true;
				is_plus_minus = true;
				break;
			case '*':
				is_op = true;
				break;
			default: //数字
				//Do nothing
				break;
			}
		}

		if(!is_op){ //数字のみの場合

			ll num = 0;

			for(int i = 0; i < length; i++){

				num = 10*num+(buf[i]-'0');
				num %= MOD;
			}

			MATRIX first(2,V(1));

			if(is_last_num){ //文字列の最後が数字の場合

				first[0][0] = last_num;

			}else{ //文字列の最後が演算子の場合

				first[0][0] = 0;
			}

			first[0][1] = 1;

			MATRIX A(SIZE,V(SIZE));
			A[0][0] = MOD_POW[length];
			A[0][1] = num;

			A[1][0] = 0;
			A[1][1] = 1;

			A = POW(A,rep_num);

			last_num = (A[0][0]*first[0][0]+A[0][1])%MOD;

			is_last_num = true;

		}else{

			if(!is_plus_minus){ //*のみの場合

				int first_loc;

				for(int i = 0; i < length; i++){

					if(buf[i] == '*'){

						first_loc = i;
						break;
					}
				}

				ll L;

				if(first_loc > 0){ //最初の*の左の数字

					ll tmp = 0;
					for(int i = 0; i < first_loc; i++){

						tmp = 10*tmp + (buf[i]-'0');
						tmp %= MOD;
					}

					if(is_last_num){

						tmp = last_num*MOD_POW[first_loc]+tmp; //左にシフトさせて足す
						tmp %= MOD;

						L = tmp;

					}else{ //前の文字列の最後が演算子

						if(last_op == '*'){ //数字確定

							MULT.push(tmp);
							L = 1;

						}else{ //★注意★

							L = tmp;
						}
					}

				}else{ //first_loc == 0

					L = last_num; //必ずis_last_num == trueであるはず
				}

				ll tmp = 0;
				stack<ll> tmp_MULT;

				if(rep_num == 1){

					MULT.push(L);

					ll work = 0;

					int last_loc;
					for(int i = length-1; i >= 0; i--){
						if(buf[i] == '*'){
							last_loc = i;
							break;
						}
					}

					for(int i = first_loc+1; i < last_loc; i++){

						if(buf[i] == '*'){
							MULT.push(work);
							work = 0;
						}else{

							work = 10*work+(buf[i]-'0');
							work %= MOD;

							if(i+1 == last_loc){

								MULT.push(work);
							}
						}
					}

					last_num = 0;
					for(int i = last_loc+1; i < length; i++){

						last_num = 10*last_num+(buf[i]-'0');
						last_num %= MOD;
					}

					if(last_loc == length-1){

						is_last_num = false;
					}else{

						is_last_num = true;
					}

					last_op = '*';
					continue;
				}

				for(int i = first_loc+1; i < length; i++){

					if(buf[i] == '*'){

						tmp_MULT.push(tmp);
						tmp = 0;

					}else{

						tmp = 10*tmp+(buf[i]-'0');
						tmp %= MOD;
					}
				}

				for(int i = 0; i < first_loc; i++){

					tmp = 10*tmp+(buf[i]-'0');
					tmp %= MOD;
				}
				tmp_MULT.push(tmp);

				ll A = 1;

				while(!tmp_MULT.empty()){

					A *= tmp_MULT.top();
					A %= MOD;
					tmp_MULT.pop();
				}

				if(rep_num > 1){

					A = mod_pow(A,rep_num-1,MOD);
					A *= L;
					A %= MOD;
					MULT.push(A); //最後のopは'*'なので
				}

				//★first_loc+1からlengthまでに*があるか調べる
				int last_loc;
				for(int i = length-1; i >= 0; i--){
					if(buf[i] == '*'){

						last_loc = i;
						break;
					}
				}

				if(last_loc == first_loc){

					if(buf[length-1] == '*'){ //first_loc==last_loc == length-1

						last_num = A;
						is_last_num = false;
					}else{

						last_num = 0;
						for(int i = last_loc+1; i < length; i++){

							last_num = 10*last_num+(buf[i]-'0');
							last_num %= MOD;
						}

						is_last_num = true;
					}

				}else{ //last_loc != first_loc

					ll work = 0;
					stack<ll> work_num;

					for(int i = first_loc+1; i < last_loc; i++){

						if(buf[i] == '*'){

							work_num.push(work);
							work = 0;
						}else{

							work = 10*work+(buf[i]-'0');
							work %= MOD;
							if(i+1 == last_loc){

								work_num.push(work);
							}
						}
					}

					ll D = work_num.top();
					work_num.pop();

					while(!work_num.empty()){

						D *= work_num.top();
						D %= MOD;
						work_num.pop();
					}

					MULT.push(D);

					last_num = 0;

					for(int i = last_loc+1; i < length; i++){

						last_num = 10*last_num+(buf[i]-'0');
						last_num %= MOD;
					}

					if('0' <= buf[length-1] && '9' >= buf[length-1]){

						is_last_num = true;
					}else{

						is_last_num = false;
					}
				}

				last_op = '*';

			}else{ //+か-が出現する場合

				int first_loc;

				for(int i = 0; i < length; i++){

					if(buf[i] == '+' || buf[i] == '-'){

						first_loc = i;
						break;
					}
				}

				//★★*が混ざっている可能性あり★★
				ll L,work = 0;
				stack<ll> work_num;

				for(int i = 0; i < first_loc; i++){

					if(buf[i] == '*'){

						if(work_num.empty()){ //初めての'*'

							if(is_last_num){ //数字が前から続いている場合

								work = last_num*MOD_POW[i]+work;
								work %= MOD;
								work_num.push(work);

							}else{ //前の文字列が演算子で終了している場合

								work_num.push(work);
							}

						}else{ //2つめ以降の'*';

							work_num.push(work);
						}

						work = 0;

					}else{

						//first_locの左は必ず数字であるはず
						work = 10*work+(buf[i]-'0');
						work %= MOD;

						if(i+1 == first_loc){

							if(work_num.empty()){ //★★

								if(is_last_num){ //数字が前から続いている場合

									work = last_num*MOD_POW[i+1]+work;
									work %= MOD;
								}
							}
						}
					}
				}

				while(!work_num.empty()){

					work *= work_num.top();
					work %= MOD;
					work_num.pop();
				}

				if(first_loc == 0){

					work = last_num; //★★
				}

				if(last_op == '*'){ //数字を連結させる

					MULT.push(work);

					ll tmp = 1;

					while(!MULT.empty()){

						tmp *= MULT.front();
						tmp %= MOD;
						MULT.pop();
					}

					NUM.push(tmp);

				}else{ //プラスかマイナス

					NUM.push(work);
				}

				if(rep_num > 1){

					OP.push('+'); //★★掛け算の準備★★
				}else{

					int last_loc;
					for(int i = length-1; i >= 0; i--){
						if(buf[i] == '+' || buf[i] == '-'){
							last_loc = i;
							break;
						}
					}

					if(last_loc == first_loc){

						OP.push(buf[first_loc]);
					}else{

						OP.push('+'); //追いかけの数字は'-'を反映させる
					}
				}

				//first_loc間の計算値を求め、掛け算に持ち込む

				char work_buf[11];
				int work_index = 0;

				stack<char> work_op;
				stack<ll> calc_num;
				stack<char> calc_op;

				int last_loc;

				for(int i = length-1; i >= 0; i--){

					if(buf[i] == '+' || buf[i] == '-'){
						last_loc = i;
						break;
					}
				}

				if(rep_num > 1){

					for(int i = first_loc+1; i < length; i++){

						work_buf[work_index++] = buf[i];
					}
					for(int i = 0; i < first_loc; i++){

						work_buf[work_index++] = buf[i];
					}

					work_num.push(0);
					work_op.push(buf[first_loc]);

					work = 0;

					for(int i = 0; i < work_index; i++){

						if(work_buf[i] == '*' || work_buf[i] == '+' || work_buf[i] == '-'){

							if(work_op.empty() == false && work_op.top() == '*'){

								work *= work_num.top();
								work %= MOD;
								work_num.pop();
								work_op.pop();
							}

							work_num.push(work);
							work_op.push(work_buf[i]);
							work = 0;

						}else{

							work = 10*work+(work_buf[i]-'0');
							work %= MOD;

							if(i+1 == work_index){

								if(work_op.empty() == false && work_op.top() == '*'){

									work *= work_num.top();
									work %= MOD;
									work_num.pop();
									work_op.pop();
								}

								work_num.push(work);
							}
						}
					}
					//このままだと右結合になってしまうので左結合にする

					while(!work_num.empty()){

						calc_num.push(work_num.top());
						work_num.pop();
					}

					while(!work_op.empty()){

						calc_op.push(work_op.top());
						work_op.pop();
					}

					ll A = calc_num.top();
					calc_num.pop();

					while(!calc_op.empty()){
						if(calc_op.top() == '+'){

							A += calc_num.top();
							A %= MOD;

						}else{

							A -= calc_num.top();
							if(A < 0)A += MOD;
						}
						calc_op.pop();
						calc_num.pop();
					}

					A *= rep_num-1;
					A %= MOD;

					NUM.push(A);

					if(last_loc != first_loc){
						OP.push('+');  //★★注意→追いかけで突っ込む数字はマイナスを反映させる★★
					}else{
						OP.push(buf[first_loc]);
					}
				}

				if(first_loc < last_loc){ //途中の数式を積む

					work = 0;

					work_num.push(0);
					work_op.push(buf[first_loc]);

					if(buf[first_loc] == '-'){


					}

					for(int i = first_loc+1; i < last_loc; i++){

						if(buf[i] == '*' || buf[i] == '+' || buf[i] == '-'){

							if(work_op.empty() == false && work_op.top() == '*'){

								work *= work_num.top();
								work %= MOD;
								work_num.pop();
								work_op.pop();
							}

							work_num.push(work);
							work_op.push(buf[i]);
							work = 0;

						}else{

							work = 10*work+(buf[i]-'0');
							work %= MOD;

							if(i+1 == last_loc){

								if(work_op.empty() == false && work_op.top() == '*'){

									work *= work_num.top();
									work %= MOD;
									work_num.pop();
									work_op.pop();
								}

								work_num.push(work);
							}
						}
					}

					//このままだと右結合になってしまうので左結合にする
					while(!work_num.empty()){

						calc_num.push(work_num.top());
						work_num.pop();
					}

					while(!work_op.empty()){

						calc_op.push(work_op.top());
						work_op.pop();
					}

					ll A;

					A = calc_num.top();
					calc_num.pop();

					while(!calc_op.empty()){
						if(calc_op.top() == '+'){

							A += calc_num.top();
							A %= MOD;

						}else{

							A -= calc_num.top();
							if(A < 0)A += MOD;
						}
						calc_op.pop();
						calc_num.pop();
					}

					NUM.push(A);
				}

				if(first_loc < last_loc){

					OP.push(buf[last_loc]);
				}

				if(last_loc == length-1){

					last_num = 0; //次の文字列と結合することはない
					is_last_num = false;

				}else{ //last_numを求める★★次に数字が連結する場合あり★★

					work = 0;

					//★★*が混ざっているか調べる★★
					int last_mult = -1;
					for(int i = length -1; i > last_loc; i--){

						if(buf[i] == '*'){

							last_mult = i;
							break;
						}
					}

					if(last_mult == -1 || last_mult < last_loc){ //最後の±から末尾までに*がない

						last_num = 0;

						for(int i = last_loc+1; i < length; i++){

							last_num = 10*last_num+(buf[i]-'0');
							last_num %= MOD;
						}

						if(last_loc == length-1){

							is_last_num = false;
						}else{

							is_last_num = true;
						}

					}else{ //last_loc+1～last_multまでをMULTに突っ込む

						work = 0;
						last_op = '*';

						for(int i = last_loc+1; i < last_mult; i++){

							if(buf[i] == '*'){

								work_num.push(work);
								work = 0;

							}else{

								work = 10*work+(buf[i]-'0');
								work %= MOD;

								if(i+1 == last_mult){

									work_num.push(work);
								}
							}
						}

						ll tmp = 1;

						while(!work_num.empty()){

							tmp *= work_num.top();
							tmp %= MOD;
							work_num.pop();
						}

						MULT.push(tmp);
						last_num = 0;

						for(int i = last_mult+1; i < length; i++){

							last_num = 10*last_num+(buf[i]-'0');
							last_num %= MOD;
						}

						if(last_mult == length-1){

							is_last_num = false;
						}else{

							is_last_num = true;
						}
					}
				}
			}
		}
	}

	//last_numが残っていたら処理
	if(last_op == '*'){

		while(!MULT.empty()){
			last_num *= MULT.front();
			last_num %= MOD;
			MULT.pop();
		}
		NUM.push(last_num);

	}else{

		NUM.push(last_num);
	}

	ll ans = NUM.front();
	NUM.pop();

	while(!OP.empty()){

		if(OP.front() == '+'){

			ans += NUM.front();
			ans %= MOD;
			NUM.pop();

		}else{

			ans -= NUM.front();
			if(ans < 0)ans += MOD;
			ans %= MOD;
			NUM.pop();
		}
		OP.pop();
	}

	printf("%lld\n",ans);

	return 0;
}



Measured memory_bytes: 3440