Under construction

Still being built. Things may change

Qnp

Time limit1.5sMemory limit256 MB

Summary
For each query, find the K-th smallest arrangement of the given digit counts (leading zeros allowed), modulo 10^9 + 7, with K up to 10^12.
Level

Medium7 of 10

Topics
Combinatorics, Math, Implementation
Solved
No attempts yet

Problem

You are given some digits. Find the KK-th smallest integer that consists of exactly the given digits, modulo 109+710^9 + 7. Answer QQ queries. Each query gives the frequencies of digits 00, 11, …\ldots, 99, followed by an integer KK.

Integers with leading zeroes are also counted.

Input

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

Each of the next QQ lines contains 11 integers. The first ten are the frequencies of digits 00, 11, …\ldots, 99. The last one is the integer KK (1≤K≤10121 \le K \le 10^{12}). In each query, the total number of digits is at least 1 and at most 7000070000.

Output

Print QQ lines. The ii-th line contains the answer for the ii-th query modulo 109+710^9 + 7.

Examples1

  1. Example 1

    Input
    6
    1 1 0 0 0 0 0 0 0 0 1
    1 1 0 0 0 0 0 0 0 0 2
    1 1 1 0 0 0 0 0 0 0 1
    1 1 1 0 0 0 0 0 0 0 2
    1 1 1 0 0 0 0 0 0 0 5
    1 2 0 0 0 0 0 0 0 0 2
    
    Expected output
    1
    10
    12
    21
    201
    101