Intervals#6454

Intervals

2 seconds
128 megabytes
Easy

An integer number is called good if it consists of good digits.

You are given intervals [l_i, r_i] and the set of digits which are considered good. Find how many ways there are to choose one integer from each of those intervals so that their sum will be a good number. You can choose the same number in multiple intervals. Two ways are considered different if there exists an integer (1 \le i \le n) such that different integers are chosen from interval . The answer may be large, so you have to give it modulo 10^9 + 7.

Input

The first line contains ten integers: -th of them is equal to if digit is good and otherwise. These integers are numbered from to . The next line contains a single integer (1 \le n \le 7): the number of intervals. Next lines contain two integers each without leading zeros: l_i and r_i (0 \le l_i \le r_i < 10^{10}).

Output

Print the number of ways modulo 10^9 + 7.

Examples

Example 1

Loading
Loading

Example 2

Loading
Loading

Example 3

Loading
Loading