Qnp

아직 제출이 없습니다시간 제한1.5초메모리 제한256 MB

문제

You are given some digits. Your task is to find the KK-th smallest integer that consists of exactly the digits given, modulo 109+710^9 + 7. You should answer QQ such queries (a query consists of digit frequencies and an integer KK).

Note that integers with leading zeroes are also taken into account.

입력

The first line contains a single integer QQ (1Q50001 \le Q \le 5000).

Each of the next QQ lines contains 1111 integers. The first ten denote the frequencies of digits 00, 11, \ldots, 99. The last one is the integer KK (1K10121 \le K \le 10^{12}). For each query, the total number of digits is strictly positive and does not exceed 70,00070\\,000.

출력

Print QQ lines. The ii-th line must contain one integer: the answer for the ii-th query modulo 109+710^9 + 7.