QOJ.ac

QOJ

Limite de temps : 1.0 s Limite de mémoire : 1024 MB Points totaux : 100 Hackable ✓

#15228. Iris' Food

Statistiques

Iris is playing with oql's keyboard again.

Over a period of $T$ days, each day Iris types several characters on oql's keyboard, and these characters happen to be exactly the 10 Arabic digits from $0$ to $9$. Statistics show that there are $a_i$ occurrences of the digit $i$.

Every day, oql decides to feed Iris a certain amount of cat food. He decides to choose $m$ digits from the $\sum_{i=0}^9 a_i$ available digits and rearrange them to form an $m$-digit decimal non-negative integer $x$ that does not contain a leading zero. Then, oql will feed Iris $x$ grams of cat food that day.

However, Iris is still a kitten and should not eat too much cat food. Therefore, oql wants to make this number as small as possible. Please help Iris calculate how much cat food she gets each day.

Since the answer can be very large, you only need to output the result modulo $10^9 + 7$. Please note that you need to output the result of the minimum answer modulo $10^9 + 7$, not the minimum value of $x \pmod{10^9 + 7}$.

Input

The first line contains an integer $T$ ($1 \le T \le 10^4$), representing the number of days.

For the next $T$ lines, each line contains 11 space-separated non-negative integers $m, a_0, a_1, \dots, a_9$ ($1 \le m \le 10^9, 0 \le a_i \le 10^9$), representing the situation for each day.

The data guarantees that a solution exists, meaning it is always possible to form at least one $m$-digit non-negative integer without a leading zero.

Output

For each day, output a single integer representing the result of the amount of cat food Iris gets that day, modulo $10^9 + 7$.

Examples

Input 1

3
3 1 0 0 0 3 0 0 0 0 0
1 2 0 0 0 0 0 0 0 0 0
4 0 1 1 1 3 0 0 0 0 0

Output 1

404
0
1234

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.