#P8982. 「DROI」Round 1 下坠

「DROI」Round 1 下坠

Background

Does falling have an end?

Problem Description

ff is a function defined on N+\mathbb{N^+}.

Let aia_i be the ii-th digit of xx from low to high. Then f(x)=i=1len(ai+1)f(x)= \prod_{i=1}^{len} (a_i+1), where lenlen is the number of digits of xx.

For a number xx, if there exists yy such that f(y)=xf(y)=x, then we call xx a falling number.

Now there are QQ queries. Each query gives a positive integer kk.

Let xx be the kk-th smallest falling number among all falling numbers. Please find the smallest yy such that f(y)=xf(y)=x. If there is no y[1,1018]y \in [1,10^{18}] that satisfies the condition, output 1-1.

Input Format

The first line contains an integer QQ, the number of queries.

The next line contains QQ numbers. The ii-th number is the kk for the ii-th query.

Output Format

Output one line with QQ numbers. The ii-th number is the answer you found for the ii-th query.

3
1 2 3
1 2 3
3
9 14 46666666
9 18 -1

Hint

Sample Explanation #1

Note that the domain of ff is N+\mathbb{N^+}, so 11 is not a falling number. Therefore, the first three falling numbers are 2,3,42,3,4, and the corresponding yy values are 1,2,31,2,3.


Sample Explanation #2

The 99-th and 1414-th falling numbers are 1010 and 1818, and their corresponding yy values are 99 and 1818. It can be proven that the 4666666646666666-th falling number corresponds to y>1018y > 10^{18}.


Constraints

For 100%100\% of the testdata: Q105Q \leq 10^5, k5×107k \leq 5 \times 10^7.

For 10%10\% of the testdata: k100k \leq 100.

For 30%30\% of the testdata: k5×103k \leq 5 \times 10^3.

For another 20%20\% of the testdata: for every queried falling number xx, we have xy100\vert x-y \vert \leq 100 or y>1018y > 10^{18}.

Please note the unusual time limit.

Translated by ChatGPT 5