#K8906. Smallest Integer With Given Digit Sum

    ID: 37446 Type: Default 1000ms 256MiB

Smallest Integer With Given Digit Sum

Smallest Integer With Given Digit Sum

You are given a positive integer \( N \). Your task is to find the smallest positive integer \( M \) such that:

  • The sum of the digits of \( M \) is exactly \( N \); that is, \( \sum_{i} d_i = N \).
  • Every digit in \( M \) is non-zero and the digits are in non-decreasing order (i.e. each digit is less than or equal to its subsequent digit).

If no such \( M \) exists, output -1.

Examples:

  • For \( N = 5 \), the answer is 5.
  • For \( N = 10 \), the answer is 19 (since \( 1 + 9 = 10 \) and 1 < 9).
  • For \( N = 15 \), the answer is 69 (since \( 6 + 9 = 15 \) and 6 < 9).
  • For \( N = 50 \), no valid \( M \) exists; hence, output is -1.

inputFormat

The input is given from stdin and consists of:

  1. An integer \( T \) representing the number of test cases.
  2. \( T \) lines, each containing a single integer \( N \) for which you have to compute the answer.

outputFormat

For each test case, output the smallest positive integer \( M \) satisfying the conditions, or -1 if such an integer does not exist. The answers for each test case should be output on separate lines to stdout.

## sample
1
5
5

</p>