Compressed Formula

Evaluate an arithmetic formula with +, -, * over non-negative integers, given as N runs where each short string repeats r_i times, and print the result modulo 1,000,000,007.

Medium7MathStringImplementationDivide and conquerNo attempts yetTime limit2sMemory limit512 MB

Problem

You are given a long but simple formula in a compressed format. A compressed formula is a sequence of NN pairs of an integer rir_i and a string sis_i, where each sis_i consists only of the digits 0 to 9 and the characters +, -, *. To restore the original formula, repeat sis_i exactly rir_i times for every ii, then concatenate the resulting strings in the order of the sequence.

A restored formula always satisfies the following BNF.

<expression> := <term> | <expression> '+' <term> | <expression> '-' <term>
<term> := <number> | <term> '*' <number>
<number> := <digit> | <non-zero-digit> <number>
<digit> := '0' | <non-zero-digit>
<non-zero-digit> := '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9'

Here + means addition, - means subtraction, and * means multiplication of integers.

Write a program that computes the value of the given formula modulo 1,000,000,007. Here xx modulo mm is the non-negative integer rr such that some integer kk satisfies x=km+rx = km + r and 0r<m0 \le r < m. For integers xx and mm, that rr is uniquely determined.

Input

The input consists of a single test case.

N
r1 s1
...
rN sN

The first line contains the length NN (1N1041 \le N \le 10^4) of the compressed formula. Each of the following NN lines holds one piece of the compressed formula. The ii-th line contains an integer rir_i (1ri1091 \le r_i \le 10^9) and a string sis_i (1si101 \le |s_i| \le 10), where rir_i is the number of repetitions of sis_i and sis_i is a piece of the original formula. The formula restored by repeating and concatenating the pieces satisfies the BNF above.

Output

Print the value of the given compressed formula modulo 1,000,000,007.