AlgoUniversity
  • Go Back
Discussion
Alex Book :

Author

Ayush Gangwani

Difficulty Level : Easy

Submissions : 73

Asked In : Observe.ai

Marks :10

: 0 | : 0

Alex has a book of an Infinite number of pages. Imagine practically when a book is opened $$$2$$$ pages get opened $$$1$$$ on left and $$$1$$$ on the right side except starting page which doesn't have any page to its left. In an open book left and right page numbers which open together form a spread. $$$1^{st}$$$ page doesn't have any page to its left so page number 1itself forms a spread and further all spreads have $$$2$$$-page numbers in them. The first spread contains page $$$1$$$, the second spread contains pages $$$2$$$ and $$$3$$$, the third spread contains pages $$$4$$$ and $$$5$$$ and the fourth spread contains pages $$$6$$$ and $$$7$$$ and so on.

Your task is to determine the first page number of the very first spread where the sum of digits of the page numbers is $$$S$$$. If no such spread exists, print $$$-1$$$.

Note: Page number $$$1$$$ itself forms a spread and thus is the first page for the first spread.

Input

The first line of input contains an integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of testcases. The description of $$$t$$$ testcases follows.

The first and only line of each testcase contains an integer $$$S$$$ $$$(1 \le S \le 10^5)$$$. It is guaranteed that the sum of $$$S$$$ over all the testcases does not exceed $$$10^5$$$.

Output

For each test case, print the answer to the problem in a single line.

Example

Input
3
1
9
4
Output
1
4
-1

Note

In sample test case 2,

  • The first spread contains page $$$1$$$ only, the sum of digits of page number is $$$1$$$.
  • The second spread contains pages $$$2$$$ and $$$3$$$, the sum of digits of page numbers is $$$5(2+3)$$$.
  • The third spread contains pages $$$4$$$ and $$$5$$$, the sum of digits of page numbers is $$$9(4+5)$$$.
So the third spread is the $$$1^{st}$$$ spread whose sum of digits of page numbers is $$$9$$$. Thus, the answer is 4.

You need to login to view your submissions.

You need to login to view all submissions.

Loading...

Result : Executed

Loading...

Feel something is wrong with the test cases?

Result : Accepted

Test Cases :

You need to Log In
We're glad that you want to attempt this problem!

But to Run or Submit the Problem, you need to Log In.

Continue to Log In
Challenge Submitted!

Your challenge has been submitted successfully.

You will get a response soon via WhatsApp or Email.

Challenge
Facing issue while trying to solve the problem! Don't worry, we got you covered!

Do let us know your issue.

Looks good!
Please enter your issue / feedback.

How do we get in touch with you?
Looks good!
Please enter your phone no.
Looks good!
Please enter your email address.