题目描述
Background
The formal problem statement is provided at the end of the description.
Problem Description
ZHY is practicing rap in an empty room.
ZHY initially produces a sound with intensity $x$. This sound collides with the walls, generating an echo with intensity $\lfloor \frac{x}{10} \rfloor$. The echo continues to collide with the walls, generating further echoes until the intensity of the echo becomes $0$.
There is also a radio in the room that records all sounds (including the initial sound and all echoes). Unfortunately, ZHY accidentally broke the radio. Now, the radio can only display the sum of the intensities of all recorded sounds, $y$. Can you calculate the initial intensity of the sound ZHY produced based on this sole piece of information? Due to the radio's age, it might malfunction and display incorrect numbers. For such cases, you need to output $-1$.
Formal Problem Statement
Define a function as follows:
$$f(x)=\begin{cases} 0 & x = 0 \\ x+f(\lfloor\frac{x}{10}\rfloor) & x > 0 \end{cases}$$
For example, $f(123)=123+12+1=136$.
Given a number $y$, determine if there exists a unique number $x$ such that $f(x)=y$. If so, output $x$; otherwise, output $-1$.
Input Format
This problem contains multiple test cases.
The first line contains an integer $T$, representing the number of test cases.
Each test case consists of a single line with an integer $y$.
Output Format
For each test case, if there exists a unique $x$ corresponding to $y$, output $x$. Otherwise, output -1.
Sample Input and Output
Sample Input #1
2
12
136
Sample Output #1
11
123
Sample Input #2
3
10
123
7510
Sample Output #2
-1
111
6761
Notes
| Subtask id | $y$ | Special Property | Score |
|---|---|---|---|
| 1 | $< 1000$ | None | 10 |
| 2 | $< 10^6$ | None | 15 |
| 3 | $< 10^{100000}$ | $S\le 9$ | 10 |
| 4 | $< 10^{100000}$ | $S\le 10$ | 20 |
| 5 | $< 10^{3000}$ | None | 15 |
| 6 | $< 10^{500000}$ | None | 30 |
In the Special Property column, $S\le k$ means "If there is a solution, the sum of all digits in $x$ does not exceed $k$."
For $100\%$ of the data, $1\le T\le 10$, $0 \le y < 10^{500000}$.
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分