3122: The magic of numbers

时间限制:1000 ms 内存限制:128 MB
上传者:
提交:10 通过:5

题目描述

ACMers of rainbow island are very obsessed with numbers. They often sit together and discuss numbers. One day, rainbow island owner announced to all islanders that he would hold the seventh rainbow island digital fun contest on June 13, and invite rainbow island math talents to participate.

On June 13, the rainbow island Master stood in the center of the rainbow island and announced the questions to all the contestants. The contestant with the shortest time to get the correct answer will be awarded the honorary mathematician of the rainbow island and selected into the rainbow island Hall of fame. The number of digit 0 is $a_0$, $\cdots$, the number of digit 9 is $a_9$. You use these numbers to constitute integers. For example, integer 2233 requires two digits 2 and two digits 3. Also, there are k opportunities to change the number -- you can change a number to any number. Now you start from 1, after you constitute 1, you try to constitute 2, $\cdots$, what's the maximum number can you constitute? 

输入格式

Each test contains multiple test cases. The first line contains the number of test cases $T$ ($1 \leq T \leq 100$). Description of the test cases follows.

The first line of each sample contains a number $k$($1\leq k\leq 10^{18}$).

The next line contains $10$ numbers $a_i~(1\leq a_0+a_1+\dots+a_9\leq 10^{18})$, describing the number of digits from 0 to 9.

输出格式

For each test, output the largest integer that can be constituted.

输入样例 复制

2
10
1 1 1 1 1 1 1 1 1 1
114514
114514 114514 114514 114514 114514 114514 114514 114514 114514 114514

输出样例 复制

9
209374