You are given a positive number $x$. Find the smallest positive integer number that has the sum of digits equal to $x$ and all digits are distinct (unique).


-----Input-----

The first line contains a single positive integer $t$ ($1 \le t \le 50$) — the number of test cases in the test. Then $t$ test cases follow.

Each test case consists of a single integer number $x$ ($1 \le x \le 50$).


-----Output-----

Output $t$ answers to the test cases:

if a positive integer number with the sum of digits equal to $x$ and all digits are different exists, print the smallest such number;

otherwise print -1.


-----Examples-----

Input
4
1
5
15
50
Output
1
5
69
-1


-----Note-----

None

Source: codeforces | Difficulty: EASY
Tags: Complete search

Mathematics

Greedy algorithms


Solutions:
n = int(input())
arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 19, 29, 39, 49, 59, 69, 79, 89, 189, 289, 389, 489, 589, 689, 789, 1789, 2789, 3789, 4789, 5789, 6789, 16789, 26789, 36789, 46789, 56789, 156789, 256789, 356789, 456789, 1456789, 2456789, 3456789, 13456789, 23456789, 123456789]
for _ in range(n):
	x = int(input())
	if x < 1 or x > 45:
		print(-1)
	else:
		print(arr[x])


for _ in range(int(input())):
	n = int(input())
	if n > 45:
		print(-1)
	else:
		l = []
		for i in range(9, 0, -1):
			if n <= i:
				l.append(str(n))
				break
			else:
				n -= i
				l.append(str(i))
		l.sort()
		x = ''
		for i in range(len(l)):
			x += l[i]
		print(x)


import sys
for i in range(int(sys.stdin.readline())):
	n = int(sys.stdin.readline())
	ans = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 19, 29, 39, 49, 59, 69, 79, 89, 189, 289, 389, 489, 589, 689, 789, 1789, 2789, 3789, 4789, 5789, 6789, 16789, 26789, 36789, 46789, 56789, 156789, 256789, 356789, 456789, 1456789, 2456789, 3456789, 13456789, 23456789, 123456789, -1, -1, -1, -1, -1, -1, -1]
	print(ans[n])


def fun(h):
	s = ''
	i = 9
	if h <= 9:
		return h
	if h > 45:
		return -1
	while h > 0:
		h = h - i
		if h >= 0:
			s += str(i)
		elif h < 0:
			if 1 <= h + i <= 9:
				s += str(h + i)
		i -= 1
	return s[::-1]
for _ in range(int(input())):
	print(fun(int(input())))


t = int(input())
for i in range(t):
	result = 0
	x = int(input())
	if x > 45:
		result = -1
	else:
		for j in range(9):
			digit = 9 - j
			if x - digit > 0:
				result += digit * 10 ** j
			elif x >= 0:
				result += x * 10 ** j
			x -= digit
	print(result)


t = int(input())
for _ in range(t):
	x = int(input())
	mp = {}
	if x > 45:
		print(-1)
	else:
		(val, ans, cnt) = (9, 0, 0)
		while x > 0:
			if x < val:
				ans = ans + x * pow(10, cnt)
				x = 0
			else:
				ans = ans + val * pow(10, cnt)
				cnt += 1
				x -= val
				val -= 1
		print(ans)


def ans(n):
	if n < 10:
		return n
	elif n < 18:
		return str(n - 9) + str(9)
	elif n < 25:
		return str(n - 17) + str(89)
	elif n < 31:
		return str(n - 24) + str(789)
	elif n < 36:
		return str(n - 30) + str(6789)
	elif n < 40:
		return str(n - 35) + str(56789)
	elif n < 43:
		return str(n - 39) + str(456789)
	elif n < 45:
		return str(n - 42) + str(3456789)
	elif n == 45:
		return str(n - 44) + str(23456789)
	else:
		return -1
n = int(input())
l1 = []
for i in range(n):
	l1.append(int(input()))
for i in l1:
	print(ans(i))
print()


from sys import stdout, stdin
input = stdin.readline
print = stdout.write

def main():
	mp = lambda : map(int, input().strip().split())
	it = int
	t = it(input())
	for _ in [0] * t:
		x = it(input())
		a = list(range(9, 0, -1))
		if x <= 45:
			s = ''
			while x:
				i = 0
				while a[i] > x:
					i += 1
				x -= a[i]
				s += str(a.pop(i))
			print(s[::-1] + '\n')
		else:
			print(str(-1) + '\n')
main()


def solve(num: int):
	if num > 45:
		return -1
	n = 9
	n_c = num
	ans = ''
	while n > 0 and n_c - n > 0:
		n_c -= n
		ans = str(n) + ans
		n -= 1
	return int(str(n_c) + ans)
for _ in range(int(input())):
	word = int(input())
	ans = solve(word)
	print(ans)


for g in [*open(0)][1:]:
	g = int(g)
	if g > 45:
		print(-1)
	else:
		n = 9
		r = ''
		while g > 0:
			m = min(n, g)
			r = str(m) + r
			g -= m
			n -= 1
		print(r)


t = int(input())
armstrongNum = []

def findArmstrong(num, digit):
	digit_arr = str(num).split()
	if len(digit_arr) == 1 and int(digit_arr[0]) <= digit:
		armstrongNum.insert(0, str(digit_arr[0]))
		return
	armstrongNum.insert(0, str(digit))
	findArmstrong(num - digit, digit - 1)
for i in range(t):
	x = int(input())
	if x < 10:
		print(x)
		continue
	if x > 45:
		print(-1)
		continue
	armstrongNum = []
	findArmstrong(x, 9)
	print(''.join(armstrongNum))


t = int(input())
for _ in range(t):
	n = int(input())
	s = 0
	ans = []
	for i in range(513):
		k = str(bin(i))[2:]
		k = k[::-1]
		k = k + '0' * (10 - len(k))
		p = 0
		for j in range(1, 10):
			p += j * int(k[j - 1])
		if p == n:
			ans.append(k)
	for i in range(len(ans)):
		s = ''
		for j in range(10):
			if ans[i][j] == '1':
				s += str(j + 1)
		ans[i] = int(s)
	l = 999999999999
	for f in ans:
		l = min(l, f)
	if l == 999999999999:
		print(-1)
	else:
		print(l)


t = int(input())
i = 0
while i < t:
	x = int(input())
	if x % 100 < 10:
		print(x)
	else:
		j = 9
		out = []
		while j > 0 and x >= j:
			x -= j
			out.append(str(j))
			j -= 1
		if str(x) not in out and x % 100 < 10 and (x > 0):
			out.append(str(x))
			x = 0
		if x > 0:
			print(-1)
		else:
			s = ''.join(out)
			print(s[::-1])
	i += 1


n = int(input())
for j in range(0, n):
	x = int(input())
	if 0 < x < 10:
		print(x)
	elif 10 <= x <= 17:
		for i in range(1, 9):
			if i * 1 + 9 == x:
				print(i * 10 + 9)
				break
	elif 18 <= x <= 24:
		for i in range(1, 8):
			if i + 8 + 9 == x:
				print(i * 100 + 89)
				break
	elif 25 <= x <= 30:
		for i in range(1, 7):
			if i + 7 + 8 + 9 == x:
				print(i * 1000 + 789)
				break
	elif 31 <= x <= 35:
		for i in range(1, 6):
			if i + 30 == x:
				print(i * 10000 + 6789)
				break
	elif 36 <= x <= 39:
		for i in range(1, 5):
			if i + 35 == x:
				print(i * 100000 + 56789)
				break
	elif 40 <= x <= 42:
		for i in range(1, 4):
			if i + 39 == x:
				print(i * 1000000 + 456789)
				break
	elif 43 <= x <= 44:
		for i in range(1, 3):
			if i + 42 == x:
				print(i * 10000000 + 3456789)
				break
	elif x == 45:
		print(123456789)
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	if n > 45:
		print(-1)
	else:
		p = n
		i = 9
		s = []
		while p > i:
			p -= i
			s.insert(0, str(i))
			i -= 1
		else:
			if n < 10:
				print(p)
			else:
				print(str(p), ''.join(s), sep='')


from math import *

def solve():
	arr = [1, 2, 3, 4, 5, 6, 7, 8, 9]
	n = int(input())
	ans = 0
	while n > 0 and len(arr) > 0:
		if n >= arr[-1]:
			ans = ans * 10 + arr[-1]
			n -= arr[-1]
			arr.remove(arr[-1])
		else:
			arr.remove(arr[-1])
	ans = sorted(list(str(ans)))
	if n == 0:
		print(''.join(ans))
	else:
		print(-1)
n = int(input())
for _ in range(n):
	solve()


t = int(input())
for _ in range(t):
	x = int(input())
	if x > 45:
		print(-1)
	else:
		number = ''
		for i in range(9, 0, -1):
			if i >= x:
				number += str(x)
				break
			else:
				number += str(i)
				x -= i
		print(number[::-1])


def C_Unique_Number(x):
	ans = ''
	if x > 45:
		return -1
	elif x <= 9:
		return x
	else:
		for i in range(9, 0, -1):
			if x - i >= 0:
				a = str(i)
				ans += a
				x = x - i
		Ans = ans[::-1]
		Ans = int(Ans)
		return Ans
t = int(input())
for i in range(t):
	x = int(input())
	res = C_Unique_Number(x)
	print(res)


for _ in range(int(input())):
	x = int(input())
	if x > 0 and x < 10:
		print(x)
	elif x < 18:
		print(str(x % 10 + 1) + '9')
	elif x < 25:
		print(str(1 + x - 18) + '89')
	elif x < 31:
		print(str(x - 24) + '789')
	elif x < 36:
		print(str(x - 30) + '6789')
	elif x < 40:
		print(str(x - 35) + '56789')
	elif x < 43:
		print(str(x - 39) + '456789')
	elif x < 45:
		print(str(x - 42) + '3456789')
	elif x == 45:
		print(123456789)
	else:
		print(-1)


import sys

def get_list():
	return list(map(int, sys.stdin.readline().split()))

def get_string():
	return input()

def get_int():
	return int(input())

def get_ints():
	return map(int, sys.stdin.readline().split())

def solve(k):
	k = str(k)
	k1 = set(k)
	summ = 0
	if len(k) == len(k1):
		return True
	return False

def re():
	dp = [0] * 52
	for i in range(10 ** 5 + 1, 0, -1):
		if solve(i):
			summ = 0
			for j in str(i):
				summ += int(j)
			if summ <= 50:
				dp[summ] = i
	return dp
dp = re()
dp[36] = 156789
dp[37] = 256789
dp[38] = 356789
dp[39] = 456789
dp[40] = 1456789
dp[41] = 2456789
dp[42] = 3456789
dp[43] = 13456789
dp[44] = 23456789
dp[45] = 123456789
for _ in range(get_int()):
	n = int(input())
	if dp[n] != 0:
		print(dp[n])
	else:
		print(-1)


def main():
	x = int(input())
	if x > 45:
		print(-1)
		return
	if x < 10:
		print(x)
		return
	s = ''
	total = 0
	for i in range(9, 0, -1):
		if total + i <= x:
			total += i
			s += str(i)
		if total == x:
			break
	if total != x:
		print(-1)
		return
	print(''.join(sorted(list(s))))
t = int(input())
for i in range(t):
	main()


for _ in range(int(input())):
	t = int(input())
	if t > 45:
		print(-1)
	else:
		ls = []
		for i in range(1, 10):
			t -= 10 - i
			if t > 0:
				ls.append(str(10 - i))
			else:
				ls.append(str(t + 10 - i))
				break
		ls.reverse()
		print(''.join(ls))


t = int(input())
while t:
	n = int(input())
	if n < 10:
		print(n)
	elif n <= 45:
		li = [1, 2, 3, 4, 5, 6, 7, 8, 9]
		li.sort(reverse=True)
		lk = []
		for i in li:
			if sum(lk) + i < n:
				lk.append(i)
			elif sum(lk) + i == n:
				lk.append(i)
				break
			else:
				continue
		lk.sort(reverse=False)
		print(''.join(map(str, lk)))
	else:
		print(-1)
	t -= 1


def s(arr):
	ans = 0
	for i in arr:
		ans += int(i)
	return ans

def unique_numbe():
	for i in range(int(input())):
		n = int(input())
		ans = '0'
		i = 9
		game = False
		while i >= 1:
			sums = s(ans)
			if sums + i <= n:
				ans += str(i)
			sums = s(ans)
			if sums == n:
				arr = list(ans)
				arr.sort()
				a = ''.join(arr)
				print(a[1:])
				game = True
				break
			i -= 1
		if game == False:
			print('-1')
unique_numbe()


for i in range(int(input())):
	k = int(input())
	if k > 45:
		print(-1)
	elif k > 9:
		(s, n) = ('', 9)
		while k > n:
			s += str(n)
			k -= n
			n -= 1
		s += str(k)
		print(s[::-1])
	else:
		print(k)


t = int(input())
for _ in range(t):
	x = int(input())
	res = []
	temp = x
	delta = 9
	while temp > delta and delta > 0:
		temp -= delta
		res.append(delta)
		delta -= 1
	if delta > 0:
		res.append(temp)
	if sum(res) == x:
		print(''.join(map(str, reversed(res))))
	else:
		print(-1)


def check_distinct(num):
	if len(set(str(num))) == len(list(str(num))):
		return True
	else:
		return False
T = int(input())
for _ in range(T):
	n = int(input())
	m = n
	ls = [i for i in range(1, 10)][::-1]
	lss = [i for i in range(1, 10)]
	ans = ''
	for i in ls:
		if n in lss:
			ans += str(n)
			break
		elif n != 0:
			n -= i
			ans += str(i)
			lss.remove(i)
		else:
			break
	ans = ans[::-1]
	if check_distinct(ans) and sum(map(int, list(ans))) == m:
		print(ans)
	else:
		print(-1)


t = int(input())
a = [1, 2, 3, 4, 5, 6, 7, 8, 9]
for _ in range(t):
	x = int(input())
	ans = 1234567890
	for i in range(2 ** 9):
		answer = []
		sm = 0
		for j in range(9):
			if i & 1 << j:
				answer.append(str(a[j]))
				sm += a[j]
		if sm == x:
			ans = min(int(''.join(answer)), ans)
	if ans == 1234567890:
		print(-1)
	else:
		print(ans)


ans = {1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 6: 6, 7: 7, 8: 8, 9: 9, 10: 19, 11: 29, 12: 39, 13: 49, 14: 59, 15: 69, 16: 79, 17: 89, 18: 189, 19: 289, 20: 389, 21: 489, 22: 589, 23: 689, 24: 789, 25: 1789, 26: 2789, 27: 3789, 28: 4789, 29: 5789, 30: 6789, 31: 16789, 32: 26789, 33: 36789, 34: 46789, 35: 56789, 36: 156789, 37: 256789, 38: 356789, 39: 456789, 40: 1456789, 41: 2456789, 42: 3456789, 43: 13456789, 44: 23456789, 45: 123456789, 46: -1, 47: -1, 48: -1, 49: -1, 50: -1}
for i in range(int(input())):
	print(ans[int(input())])


for _ in range(int(input())):
	n = int(input())
	a = ''
	for x in range(9, 0, -1):
		if n >= x:
			n -= x
			a += str(x)
	if n == 0:
		print(a[::-1])
	else:
		print(-1)


def sumOfDigits(i):
	ans = 0
	u = []
	while i != 0:
		ans += i % 10
		u.append(i % 10)
		i = i // 10
	return (ans, sorted(u) == sorted(list(set(u))))
arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 19, 29, 39, 49, 59, 69, 79, 89, 189, 289, 389, 489, 589, 689, 789, 1789, 2789, 3789, 4789, 5789, 6789, 16789, 26789, 36789, 46789, 56789, 156789, 256789, 356789, 456789, 1456789, 2456789, 3456789, 13456789, 23456789, 123456789]
t = int(input())
for i in range(t):
	n = int(input())
	if n > 45:
		print(-1)
	else:
		print(arr[n - 1])


import sys
input = sys.stdin.readline

def inp():
	return int(input())
nTest = inp()

def SumList(Lista2Analyse):
	aux = 0
	for elem in Lista2Analyse:
		aux = aux + elem
	return aux
Vec = list(range(10))
Aux = list()
aux = 45
for i in Vec:
	aux = aux - i
	Aux.append(aux)

def ComputeNCifras(XIn, SumVec, IndexVec):
	for j in SumVec:
		if X <= j:
			return IndexVec[SumVec.index(j)]
Aux.remove(0)
Aux.reverse()
Vec.remove(0)
for i in range(nTest):
	Subset = list(range(10))
	Subset.remove(0)
	X = inp()
	if (X > 0) & (X < 46):
		Ncif = ComputeNCifras(X, Aux, Vec)
		for k in range(1, len(Subset) - Ncif + 1):
			Subset.remove(k)
		SumaLastDigits = SumList(Subset[1:])
		Subset[0] = X - SumaLastDigits
		A = list(map(str, Subset))
		print(''.join(A))
	elif X == 0:
		print(0)
	else:
		print(-1)


def solve():
	x = int(input())
	if x > 45:
		print(-1)
	elif x < 10:
		print(x)
	else:
		i = 9
		n = 0
		while x > i:
			n = n * 10 + i
			x -= i
			i -= 1
		if x != 0:
			n = n * 10 + x
		n = list(str(n))
		i = len(n) - 1
		while i >= 0:
			print(n[i], end='')
			i -= 1
		print()
t = int(input())
while t > 0:
	solve()
	t -= 1


for _ in range(int(input())):
	n = input()
	if len(n) == 1:
		print(n)
	else:
		n = int(n)
		m = n
		ss = 9
		cnt = 0
		flag = 1
		ss = 9
		b = []
		while m and m <= 45:
			while m < ss:
				ss -= 1
			m -= ss
			b.append(ss)
			cnt += 1
			if m == 0:
				flag = 1
				break
			if m <= 0 or ss == 0:
				flag = 0
				break
			ss -= 1
		if m > 45:
			flag = 0
		if flag:
			b.sort()
			for i in b:
				print(i, end='')
			print()
		else:
			print(-1)


t = int(input())
for k in range(t):
	n = int(input())
	count = 0
	arr = []
	if n > 45:
		print('-1')
	else:
		for i in range(9, 0, -1):
			val = count + i
			if not val > n:
				arr.append(i)
				count += i
		arr.sort()
		print(''.join([str(i) for i in arr]))


import copy
import math
t = int(input())
for case in range(t):
	n = int(input())
	s = ''
	k = 9
	if n > 45:
		print(-1)
		continue
	while n > 0:
		if n >= k:
			n -= k
			s += str(k)
			k -= 1
		else:
			s += str(n)
			break
	print(s[::-1])


for t in range(int(input())):
	n = int(input())
	if n <= 45:
		a = [0]
		b = [0, 9, 8, 7, 6, 5, 4, 3, 2, 1]
		for i in range(9, 0, -1):
			a.append(a[-1] + i)
		for i in range(10):
			if a[i] > n:
				break
		k = n - a[i - 1]
		y = ''
		if k > 0:
			y += str(k)
		j = i - 1
		while j >= 1:
			y += str(b[j])
			j -= 1
		print(y)
	else:
		print(-1)


for _ in range(int(input())):
	x = int(input())
	s = 0
	y = 9
	ans = ''
	while y > 0:
		if s + y > x:
			break
		s += y
		ans = str(y) + ans
		y -= 1
	if s == x:
		print(ans)
	elif y <= 0:
		print(-1)
	else:
		print(str(x - s) + ans)


list = []
s = 0
for i in range(9, 0, -1):
	s += 1
	for _ in range(i):
		list.append(s)
for _ in range(int(input())):
	x = int(input())
	if x > 45:
		print(-1)
	else:
		digits = list[x - 1]
		result = ''
		count = 0
		start = 9
		for _ in range(digits - 1):
			result = f'{start}' + result
			count += start
			start -= 1
		result = f'{x - count}' + result
		print(result)


for s in [*open(0)][1:]:
	x = int(s)
	r = ''
	i = 9
	while 0 < i < x:
		r = f'{i}' + r
		x -= i
		i -= 1
	print((f'{x}' + r, -1)[i < 1])


for run in range(int(input())):
	n = int(input())
	lst = list()
	(s, l) = (0, 9)
	while s < n and l > 0:
		lst.append(min(n - s, l))
		s += l
		l -= 1
	if s < n:
		print(-1)
	else:
		lst.reverse()
		print(*lst, sep='')


t = int(input())
for i in range(t):
	x = int(input())
	an = ''
	k = 9
	flag = False
	if x > 45:
		print(-1)
		flag = True
	if x == 0:
		print(0)
		flag = True
	if not flag:
		while x > 0:
			if x - k >= 0:
				x -= k
				an = an + str(k)
			k -= 1
		print(an[::-1])


from sys import stdin, stdout
import math
from itertools import permutations, combinations
from collections import defaultdict
from collections import Counter
from bisect import bisect_left
import sys
from queue import PriorityQueue
import operator as op
from functools import reduce
import re
mod = 1000000007
input = sys.stdin.readline

def L():
	return list(map(int, stdin.readline().split()))

def In():
	return map(int, stdin.readline().split())

def I():
	return int(stdin.readline())

def printIn(ob):
	return stdout.write(str(ob) + '\n')

def powerLL(n, p):
	result = 1
	while p:
		if p & 1:
			result = result * n % mod
		p = int(p / 2)
		n = n * n % mod
	return result

def ncr(n, r):
	r = min(r, n - r)
	numer = reduce(op.mul, range(n, n - r, -1), 1)
	denom = reduce(op.mul, range(1, r + 1), 1)
	return numer // denom

def SieveOfEratosthenes(n):
	prime_list = []
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			prime_list.append(p)
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime_list

def get_divisors(n):
	for i in range(1, int(n / 2) + 1):
		if n % i == 0:
			yield i
	yield n

def myCode():
	n = I()
	if n <= 9:
		print(n)
	elif n >= 10 and n <= 17:
		for i in '12345678':
			if int(i) + 9 == n:
				print(i + str(9))
				break
	elif n >= 18 and n <= 24:
		for i in '1234567':
			if int(i) + 8 + 9 == n:
				print(i + str(89))
				break
	elif n >= 25 and n <= 30:
		for i in '123456':
			if int(i) + 7 + 8 + 9 == n:
				print(i + str(789))
				break
	elif n >= 31 and n <= 35:
		for i in '12345':
			if int(i) + 6 + 7 + 8 + 9 == n:
				print(i + str(6789))
				break
	elif n >= 36 and n <= 39:
		for i in '1234':
			if int(i) + 5 + 6 + 7 + 8 + 9 == n:
				print(i + str(56789))
				break
	elif n >= 40 and n <= 42:
		for i in '123':
			if int(i) + 4 + 5 + 6 + 7 + 8 + 9 == n:
				print(i + str(456789))
				break
	elif n >= 43 and n <= 44:
		for i in '12':
			if int(i) + 3 + 4 + 5 + 6 + 7 + 8 + 9 == n:
				print(i + str(3456789))
				break
	elif n == 45:
		print(123456789)
	else:
		print(-1)

def main():
	for t in range(I()):
		myCode()
main()


t = int(input())
res = []
for i in range(t):
	n = int(input())
	atual = 9
	num = []
	soma = sum(num)
	a = True
	while n != 0:
		if n - atual >= 0:
			num.append(atual)
			n -= atual
			atual -= 1
		else:
			atual -= 1
		if atual < 0:
			res.append([-1])
			a = False
			break
	if a:
		num.sort()
		res.append(num)
for r in res:
	print()
	for item in r:
		print(item, end='')


for _ in range(int(input())):
	x = int(input())
	if x > 45:
		print(-1)
	elif x < 10:
		print(x)
	elif x > 9 and x < 18:
		z = x - 9
		print(z, end='')
		print(x - z)
	elif x > 17 and x < 25:
		z = x - 17
		print(z, end='')
		print(89)
	elif x > 24 and x < 31:
		z = x - 24
		print(z, end='')
		print(789)
	elif x > 30 and x < 36:
		z = x - 30
		print(z, end='')
		print(6789)
	elif x > 35 and x < 40:
		z = x - 35
		print(z, end='')
		print(56789)
	elif x > 39 and x < 43:
		z = x - 39
		print(z, end='')
		print(456789)
	elif x > 42 and x < 45:
		z = x - 42
		print(z, end='')
		print(3456789)
	elif x == 45:
		print(123456789)


for _ in range(int(input())):
	x = int(input())
	if x > 45:
		print(-1)
		continue
	if x <= 9:
		print(x)
		continue
	for i in range(1, 10):
		if i / 2 * (19 - i) >= x:
			term = i
			extra = i / 2 * (19 - i) - x
			break
	curr = 9
	output = ''
	for i in range(term - 1):
		output = str(curr - i) + output
	output = str(int(curr - term + 1 - extra)) + output
	print(output)


t = int(input())
for test in range(0, t):
	n = int(input())
	if n > 45:
		print(-1)
	elif n == 44:
		print(23456789)
	elif len(str(n)) == 1:
		print(n)
	else:
		s = ''
		big = 9
		while len(str(n)) > 1:
			n = n - big
			s = s + str(big)
			big = big - 1
		if n <= big:
			s = s + str(n)
			s = s[::-1]
			print(int(s))
		elif n % 2 == 0 and n // 2 == big:
			s = s + str(big) + str(big - 1) + str(1)
			s = s[::-1]
			print(int(s))
		else:
			k = n - big
			s = s + str(big) + str(k)
			s = s[::-1]
			print(int(s))


t = int(input())
for i in range(t):
	n = int(input())
	if n > 45:
		print(-1)
	elif n <= 9:
		print(n)
	else:
		digit = 9
		l = []
		while True:
			if n > digit:
				l.append(digit)
				n -= digit
				digit -= 1
			else:
				l.append(n)
				break
		l.reverse()
		x = ''.join(map(str, l))
		print(x)


T = int(input())
lst = [1, 2, 3, 4, 5, 6, 7, 8, 9]
lst1 = list(reversed(lst))
for _ in range(T):
	n = int(input())
	ans = []
	if n > 45:
		print(-1)
		continue
	elif n < 10:
		print(n)
		continue
	else:
		for i in lst1:
			n -= i
			ans.append(i)
			if n in lst1 and n not in ans:
				print(n, end='')
				ans.reverse()
				for j in ans:
					print(j, end='')
				break
		print()


def main():
	t = int(input())
	for _ in range(t):
		print(case())

def case():
	n = int(input())
	ans = ''
	d = 9
	if n > 45:
		return -1
	while n >= d and d > 0:
		ans = str(d) + ans
		n -= d
		d -= 1
	if n != 0:
		ans = str(n) + ans
	else:
		return ans
	return ans
main()


for _ in range(int(input())):
	n = int(input())
	if n < 46:
		s = ''
		a = 9
		while n - a > 0:
			n -= a
			s = str(a) + s
			a -= 1
		if n:
			s = str(n) + s
		print(s)
	else:
		print(-1)


num = [1, 2, 3, 4, 5, 6, 7, 8, 9, 19, 29, 39, 49, 59, 69, 79, 89, 189, 289, 389, 489, 589, 689, 789, 1789, 2789, 3789, 4789, 5789, 6789, 16789, 26789, 36789, 46789, 56789, 156789, 256789, 356789, 456789, 1456789, 2456789, 3456789, 13456789, 23456789, 123456789]
for _ in range(int(input())):
	try:
		print(num[int(input()) - 1])
	except:
		print(-1)


t = int(input())
while t:
	n = int(input())
	sum = 0
	last = 9
	ans = ''
	while sum < n and last > 0:
		ans += str(min(n - sum, last))
		sum += last
		last -= 1
	if sum < n:
		print(-1)
	else:
		print(ans[::-1])
	t -= 1


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush, nsmallest
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
from decimal import Decimal
mod = pow(10, 9) + 7

def data():
	return sys.stdin.readline().strip()

def out(var):
	sys.stdout.write(str(var) + '\n')

def outa(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
for _ in range(int(data())):
	x = int(data())
	if x > 45:
		out(-1)
		continue
	answer = []
	temp = 9
	while x:
		if x >= temp:
			answer.append(str(temp))
			x -= temp
			temp -= 1
		else:
			answer.append(str(x))
			break
	out(''.join(answer[::-1]))


for _ in range(int(input())):
	x = int(input())
	if x > 45:
		print(-1)
	else:
		s = 0
		digits = []
		for i in range(9, 0, -1):
			s = s + i
			digits.append(i)
			if s >= x:
				digits[-1] = digits[-1] - (s - x)
				digits.reverse()
				res = ''
				for x in digits:
					res = res + str(x)
				print(res)
				break


for t in range(int(input())):
	num = int(input())
	digit = None
	s = 0
	val = []
	string = []
	l1 = 9
	if num < 10:
		print(num)
	else:
		while l1 > 0:
			for i in range(1, l1):
				if l1 + i + sum(val) == num:
					temp = f"{i}{l1}{''.join(string[::-1])}"
					if digit == None:
						digit = temp
					elif len(digit) > len(temp):
						digit = temp
					elif len(digit) == len(temp):
						if int(digit) > int(temp):
							digit = temp
					else:
						pass
			val.append(l1)
			string.append(f'{l1}')
			l1 -= 1
		if digit == None:
			print(-1)
		else:
			print(digit)


def nums(n):
	t = n
	a = [9, 8, 7, 6, 5, 4, 3, 2, 1]
	ans = []
	i = 0
	while n and i < len(a):
		if a[i] <= n:
			n -= a[i]
			ans.append(a[i])
			a.pop(i)
		else:
			i += 1
	if sum(ans) != t:
		return -1
	return ''.join(map(str, sorted(ans)))
for i in range(int(input())):
	print(nums(int(input())))


a = int(input())
for i in range(a):
	answer = []
	n = int(input())
	if n >= 46:
		print('-1')
	else:
		x = 9
		while x > 0:
			if n >= x and n - x >= 0:
				n = n - x
				answer.insert(0, x)
			x -= 1
	for q in answer:
		print(q, end='')
	print()


t = int(input())
res = ''
for i in range(t):
	x = int(input())
	if x > 45:
		res += '-1\n'
	elif len(str(x)) == 1:
		res += str(x) + '\n'
	else:
		n = 9
		s = '9'
		c = True
		while c:
			for i in range(1, int(s[0])):
				if n + i == x:
					s = str(i) + s
					c = False
					res += s + '\n'
					break
			s = str(i) + s
			n += i
print(res)


t = int(input())
A = []
while t != 0:
	n = int(input())
	if n < 46:
		B = []
		k = 9
		while n != 0:
			if n - k > -1:
				n = n - k
				B.append(str(k))
				k = k - 1
			else:
				k = k - 1
		B = B[::-1]
		B = ''.join(B)
		A.append(B)
	else:
		A.append('-1')
	t = t - 1
for i in A:
	print(i)


for _ in range(int(input())):
	a = int(input())
	if a <= 9:
		print(a)
	else:
		s = '9'
		x = 8
		f = 1
		a -= 9
		while a > 0 and x > 0:
			if a - x > 0:
				s += str(x)
				a -= x
			elif a - x == 0:
				s += str(x)
				print(''.join(sorted(s)))
				f = 0
				break
			x -= 1
		if f:
			print(-1)


T = int(input())
li = [1, 2, 3, 4, 5, 6, 7, 8, 9]
li_check = [0] * 9
result = []
for i in range(1, 2 ** 9 + 1):
	stack = []
	for j in range(9):
		if i & 1 << j:
			stack.append(j + 1)
	t = stack[:]
	result.append(t)
for TC in range(1, T + 1):
	n = int(input())
	sol = []
	for i in range(len(result)):
		if sum(result[i]) == n:
			total = 0
			for k in range(len(result[i])):
				total += result[i][k] * 10 ** (len(result[i]) - k - 1)
			sol.append(total)
	if sol:
		print(min(sol))
	else:
		print(-1)


import collections
from collections import defaultdict
for _ in range(int(input())):
	n = int(input())
	if n > 45:
		print(-1)
		continue
	if n < 10:
		print(n)
		continue
	z = list(range(9, 0, -1))
	s = 0
	ans = []
	for x in z:
		if s + x <= n:
			ans.append(x)
			s += x
	ans = [str(x) for x in ans]
	ans.sort()
	print(''.join(ans))


def suma(n):
	s = 0
	while n != 0:
		s = s + n % 10
		n = n // 10
	return s
te = int(input())
for i in range(te):
	num = int(input())
	res = '987654321'
	if num > 45:
		print('-1')
	else:
		for i in range(100):
			if res[-1] == '0':
				res = res[:-1]
			if suma(int(res)) == num:
				print(res[::-1])
				break
			res = str(int(res) - 1)


t = int(input())
for i in range(t):
	x = int(input())
	if x < 10:
		print(x)
	elif x > 45:
		print(-1)
	else:
		q = 9
		l = []
		while x != 0:
			if x <= q:
				l.append(x)
				x = 0
				continue
			else:
				x -= q
				l.append(q)
				q -= 1
		l = l[::-1]
		print(*l, sep='')


t = int(input())
while t:
	t -= 1
	n = int(input())
	if n > 45:
		print(-1)
		continue
	x = 0
	i = 9
	j = 0
	while n:
		z = min(n, i)
		i -= 1
		x = x + z * 10 ** j
		n -= z
		j += 1
	print(x)


t = int(input())
arr = [9, 8, 7, 6, 5, 4, 3, 2, 1]
for i in range(t):
	x = int(input())
	if x > 45:
		print(-1)
	elif x < 10:
		print(x)
	else:
		s = ''
		for j in arr:
			x = x - j
			if x >= 0:
				s = str(j) + s
				if x == 0:
					break
			else:
				x = x + j
		print(s)


n = int(input())
for i in range(n):
	t = int(input())
	if t < 10:
		print(t)
	if t < 18 and t > 9:
		print(t - 9, '9', sep='')
	if t < 25 and t > 17:
		print(t - 17, '89', sep='')
	if t < 31 and t > 24:
		print(t - 24, '789', sep='')
	if t < 36 and t > 30:
		print(t - 30, '6789', sep='')
	if t < 40 and t > 35:
		print(t - 35, '56789', sep='')
	if t < 43 and t > 39:
		print(t - 39, '456789', sep='')
	if t < 45 and t > 42:
		print(t - 42, '3456789', sep='')
	if t == 45:
		print(123456789)
	if t > 45:
		print(-1)


t = int(input())
while t:
	t -= 1
	x = int(input())
	if x > 45:
		print(-1)
		continue
	unique_elem = []
	for i in range(9, 0, -1):
		if x // i != 0:
			unique_elem.append(i)
			x -= i
		if x <= 0:
			break
	unique_elem.sort()
	ans = ''
	for i in unique_elem:
		ans += str(i)
	print(ans)


def solve(n):
	if len(n) == 1:
		return [int(n)]
	n = int(n)
	num = [9, 8, 7, 6, 5, 4, 3, 2, 1]
	result = []
	dec = {}
	i = 0
	while i < 9:
		if n > num[i] and num[i] not in dec:
			result.append(num[i])
			dec[num[i]] = 1
			n -= num[i]
			i += 1
		elif n <= num[i]:
			if n not in dec:
				result.append(n)
				return sorted(result)
			return -1
		else:
			for j in range(1, n):
				if j != n - j and j not in dec and (n - j not in dec):
					result.append(j)
					result.append(n - j)
					return sorted(result)
			return -1
	return -1
for _ in range(int(input())):
	n = input()
	p = solve(n)
	if p == -1:
		print(-1)
	else:
		t = ''
		for i in p:
			t += str(i)
		print(t)


import sys
import math
from heapq import heappop, heappush, heapify

def mati(n):
	return [intl() for i in range(n)]
iinp = lambda : int(sys.stdin.readline())
inp = lambda : sys.stdin.readline().strip()
strl = lambda : list(inp().strip().split(' '))
intl = lambda : list(map(int, inp().split(' ')))
mint = lambda : map(int, inp().split())
flol = lambda : list(map(float, inp().split(' ')))
flush = lambda : sys.stdout.flush()
for _ in range(iinp()):
	n = iinp()
	if n in range(1, 10):
		print(n)
	elif n > 45:
		print(-1)
	elif n == 45:
		print(123456789)
	else:
		s = '987654321'
		a = [9, 17, 24, 30, 35, 39, 42, 44, 45]
		for i in range(9):
			if -a[i] + n < 0:
				nn = -a[i - 1] + n
				if nn:
					print(str(nn) + s[:i][::-1])
				else:
					print(s[:i][::-1])
				break


def solve(n):
	if n > 45:
		return -1
	if n < 10:
		return n
	s = 0
	ls = []
	dig = 9
	while dig > 0 and s < n:
		if n - s < dig:
			ls.append(str(n - s))
			s = n
		else:
			ls.append(str(dig))
			s += dig
			dig -= 1
	ls.reverse()
	return ''.join(ls)
t = int(input())
while t:
	n = int(input())
	print(solve(n))
	t -= 1


for _ in range(int(input())):
	x = int(input())
	if x > 45:
		print(-1)
	elif x < 10:
		print(x)
	else:
		m = ''
		y = 9
		while y > 0 and x > 0:
			if y <= x:
				m += str(y)
				x -= y
			y -= 1
		print(m[::-1])


t = int(input())
from collections import Counter
while t > 0:
	n = int(input())
	if n < 10:
		print(n)
	else:
		s = ''
		i = 9
		while n > 0:
			if i > n:
				break
			n = n - i
			s += str(i)
			i -= 1
			if i <= 0:
				break
		if n != 0:
			s += str(n)
		s = s[::-1]
		l = [i for i in s]
		x = Counter(l)
		if len(x) < len(l):
			print(-1)
		else:
			print(s)
	t -= 1


count = int(input())
for _ in range(count):
	a = int(input())
	if a > 45:
		print('-1')
	else:
		list_1 = []
		k = 9
		m = 0
		counter = 0
		while m < a:
			m += k
			counter += 1
			k -= 1
		k = 9
		list_1 = [k - i for i in range(counter - 1)]
		su = sum(list_1)
		r = a - su
		list_1.append(r)
		list_1.sort()
		list_2 = [str(i) for i in list_1]
		f = ''.join(list_2)
		print(f)


t = int(input())

def q(n):
	if n < 10:
		return n % 10
	elif n < 18:
		return str(n % 9) + '9'
	elif n < 25:
		return str(n % 17) + '89'
	elif n < 31:
		return str(n % 24) + '789'
	elif n < 36:
		return str(n % 30) + '6789'
	elif n < 40:
		return str(n % 35) + '56789'
	elif n < 43:
		return str(n % 39) + '456789'
	elif n < 45:
		return str(n % 42) + '3456789'
	elif n == 45:
		return '123456789'
	elif n > 45:
		return -1
for i in range(t):
	n = int(input())
	print(q(n))


test = int(input())
for t in range(test):
	n = int(input())
	if n > 45:
		print(-1)
	else:
		sumi = 0
		s = ''
		temp = 9
		while sumi < n and temp > 0:
			s = str(temp) + s
			sumi += temp
			temp -= 1
		if sumi == n:
			print(int(s))
		else:
			s = s[1:]
			val = n - (sumi - (temp + 1))
			print(int(str(val) + s))


import functools
for _ in range(int(input())):
	x = int(input())
	if x <= 9:
		print(x)
	elif x >= 46:
		print(-1)
	else:
		check = []
		index = 9
		while x > 0:
			if x > index:
				x -= index
				check.insert(0, index)
				index -= 1
			else:
				check.insert(0, x)
				x = 0
		print(functools.reduce(lambda a, b: str(a) + str(b), check))


n = int(input())
for i in range(n):
	s = int(input())
	ans = []
	st = s
	if s > 45:
		print(-1)
	elif s < 10:
		print(s)
	else:
		t = 9
		while s > 0 and t > 0:
			if s >= t and str(t) not in ans:
				ans.append(str(t))
				s -= t
				t -= 1
			else:
				t -= 1
		print(''.join(ans[::-1]))


t = int(input())
for _ in range(t):
	x = int(input())
	if x > 45:
		print(-1)
	else:
		l = 0
		while l * (l + 1) // 2 + (9 - l) * l < x:
			l += 1
		s = []
		for i in range(10 - l, 10):
			s += [i]
		while sum(s) > x:
			s[0] -= 1
		for i in s:
			print(i, end='')
		print()


test = int(input())
for testcase in range(test):
	n = int(input())
	if n <= 45:
		if n < 10:
			print(n)
		else:
			i = 9
			s = 0
			ans = 0
			while i > 0:
				if s + i <= n:
					s += i
					ans = ans * 10 + i
				if s >= n:
					break
				i -= 1
			if n == s:
				ans = str(ans)
				print(ans[::-1])
			else:
				print(-1)
	else:
		print(-1)


l = []
ans = ['', '', '', '', '', '', '', '', '']
for j in range(8, -1, -1):
	for i in range(1, j + 2):
		ans[j] = str(i)
		l.append(''.join(ans))
for j in range(int(input())):
	n = int(input())
	if n > 45:
		print(-1)
	else:
		print(l[n - 1])


for _ in range(int(input())):
	n = int(input())
	m = n
	if n > 45:
		print(-1)
	elif n < 10:
		print(n)
	else:
		s = {1, 2, 3, 4, 5, 6, 7, 8, 9}
		ans = ''
		while True:
			if m > max(s):
				m -= max(s)
				ans = str(max(s)) + ans
				s.remove(max(s))
			else:
				for i in sorted(s, reverse=True):
					if m >= i:
						ans = str(i) + ans
						s.remove(i)
						m -= i
			if m <= 0:
				break
		print(ans)


def sup10(x):
	s = ''
	l = [9, 8, 7, 6, 5, 4, 3, 2, 1]
	li = []
	for i in range(len(l)):
		x -= l[i]
		s = str(l[i]) + s
		li.append(l[i])
		if x < 10 and x not in li:
			s = str(x) + s
			break
		elif x < 10 and x == l[i]:
			continue
	print(s)

def sum(x):
	if x < 10:
		print(x)
	elif 10 <= x <= 45:
		sup10(x)
	else:
		print(-1)
t = int(input())
l = []
for i in range(t):
	x = int(input())
	l.append(x)
for i in range(len(l)):
	sum(l[i])


for __ in range(int(input())):
	n = int(input())
	ar = []
	i = 9
	if n > 45:
		print(-1)
	else:
		while n > 0:
			if n - i >= 0:
				n -= i
				ar.append(i)
			i -= 1
		ar.sort()
		print(''.join(map(str, ar)))


import bisect
import collections
import functools
import itertools
import math
import heapq
import random
import string

def repeat(_func=None, *, times=1):

	def decorator(func):

		@functools.wraps(func)
		def wrapper(*args, **kwargs):
			for _ in range(times):
				func(*args, **kwargs)
		return wrapper
	if _func is None:
		return decorator
	else:
		return decorator(_func)

def unpack(func=int):
	return map(func, input().split())

def l_unpack(func=int):
	return list(map(func, input().split()))

def s_unpack(func=int, rev=False):
	return sorted(map(func, input().split()), reverse=rev)

def ml_unpack(n):
	return [int(input()) for _ in range(n)]

def range_n():
	return range(int(input()))

def getint():
	return int(input())

def getmatrix(rows):
	return [list(map(int, input().split())) for _ in range(rows)]

def display_matrix(mat):
	for i in range(len(mat)):
		print(mat[i])

def factor(n):
	d = collections.defaultdict(int)
	while not n % 2:
		d[2] += 1
		n //= 2
	i = 3
	while i * i <= n:
		while not n % i:
			d[i] += 1
			n //= i
		i += 2
	if n > 1:
		d[n] += 1
	return d

@repeat(times=getint())
def main():
	n = getint()
	arr = list(range(1, 10))

	def util(idx, currsum, num):
		if idx == 9:
			if currsum == n:
				return num
			return float('inf')
		if currsum == n:
			return num
		if currsum > n:
			return float('inf')
		return min(util(idx + 1, currsum + arr[idx], num * 10 + arr[idx]), util(idx + 1, currsum, num))
	ans = util(0, 0, 0)
	if ans == float('inf'):
		ans = -1
	print(ans)
main()


t = int(input())
for i in range(t):
	n = input()
	if len(str(n)) < 2:
		print(n)
	elif int(n) > 45:
		print(-1)
	else:
		k = 9
		s = ''
		while k > 0:
			if int(n) - k >= 0:
				s = str(k) + str(s)
				n = int(n) - k
			if int(n) == 0:
				print(s)
				break
			k -= 1
		if int(n) > 0:
			print(-1)


for _ in range(int(input())):
	x = int(input())
	last = 9
	summ = 0
	ans = []
	while summ < x and last > 0:
		ans.append(str(min(x - summ, last)))
		summ += last
		last -= 1
	if summ < x:
		print(-1)
	else:
		print(int(''.join(reversed(ans))))


t = int(input())
z = 1
while z <= t:
	x = int(input())
	if x <= 9:
		print(x)
	elif x > 45:
		print('-1')
	elif x > 9 and x < 18:
		a = x - 9
		print(str(a) + '9')
	elif x >= 18 and x < 25:
		a = x - 17
		print(str(a) + '89')
	elif x >= 25 and x < 31:
		a = x - 24
		print(str(a) + '789')
	elif x >= 31 and x < 36:
		a = x - 30
		print(str(a) + '6789')
	elif x >= 36 and x < 40:
		a = x - 35
		print(str(a) + '56789')
	elif x >= 40 and x < 43:
		a = x - 39
		print(str(a) + '456789')
	elif x >= 43 and x < 45:
		a = x - 42
		print(str(a) + '3456789')
	elif x == 45:
		print('123456789')
	z = z + 1


import itertools
t = int(input())
num = [10 ** 9 for i in range(51)]
num[45] = 123456789
for i in range(10):
	num[i] = i
alp = [i for i in range(10)]
for i in range(2, 9):
	for j in itertools.combinations(alp, i):
		tot = sum(j)
		x = ''
		for v in j:
			x += str(v)
		x = int(x)
		num[tot] = min(num[tot], x)
for i in range(46, 51):
	num[i] = -1
for i in range(t):
	s = int(input())
	ans = num[s]
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	m = 9
	a = ''
	while n > m and m > 0:
		n = n - m
		a = str(m) + a
		m = m - 1
	if n <= m:
		a = str(n) + a
		print(a)
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	if n > 45:
		print(-1)
		continue
	i = 9
	s = ''
	while n > 9 - len(s):
		n = n - i
		s += str(i)
		i = i - 1
	s += str(n)
	print(s[len(s) + 1::-1])


test = int(input())
while test > 0:
	test -= 1
	n = int(input())
	rs = 1000000000
	for c1 in range(1, 10):
		if c1 > n:
			break
		if c1 == n:
			rs = min(rs, c1)
			break
		s = c1
		for c2 in range(c1 + 1, 10):
			if c1 + c2 > n:
				break
			if c1 + c2 == n:
				rs = min(rs, s * 10 + c2)
				break
			s = s * 10 + c2
			for c3 in range(c2 + 1, 10):
				if c1 + c2 + c3 > n:
					break
				if c1 + c2 + c3 == n:
					rs = min(rs, s * 10 + c3)
					break
				s = s * 10 + c3
				for c4 in range(c3 + 1, 10):
					if c1 + c2 + c3 + c4 > n:
						break
					if c1 + c2 + c3 + c4 == n:
						rs = min(rs, s * 10 + c4)
						break
					s = s * 10 + c4
					for c5 in range(c4 + 1, 10):
						if c1 + c2 + c3 + c4 + c5 > n:
							break
						if c1 + c2 + c3 + c4 + c5 == n:
							rs = min(rs, s * 10 + c5)
						s = s * 10 + c5
						for c6 in range(c5 + 1, 10):
							if c1 + c2 + c3 + c4 + c5 + c6 > n:
								break
							if c1 + c2 + c3 + c4 + c5 + c6 == n:
								rs = min(rs, s * 10 + c6)
							s = s * 10 + c6
							for c7 in range(c6 + 1, 10):
								if c1 + c2 + c3 + c4 + c5 + c6 + c7 > n:
									break
								if c1 + c2 + c3 + c4 + c5 + c6 + c7 == n:
									rs = min(rs, s * 10 + c7)
								s = s * 10 + c7
								for c8 in range(c7 + 1, 10):
									if c1 + c2 + c3 + c4 + c5 + c6 + c7 + c8 > n:
										break
									if c1 + c2 + c3 + c4 + c5 + c6 + c7 + c8 == n:
										rs = min(rs, s * 10 + c8)
									s = s * 10 + c8
									for c9 in range(c8 + 1, 10):
										if c1 + c2 + c3 + c4 + c5 + c6 + c7 + c8 + c9 > n:
											break
										if c1 + c2 + c3 + c4 + c5 + c6 + c7 + c8 + c9 == n:
											rs = min(rs, s * 10 + c9)
										s = s * 10 + c9
										s = (s - c9) // 10
									s = (s - c8) // 10
								s = (s - c7) // 10
							s = (s - c6) // 10
						s = (s - c5) // 10
					s = (s - c4) // 10
				s = (s - c3) // 10
			s = (s - c2) // 10
		s = s - c1
	if rs == 1000000000:
		print(-1)
	else:
		print(rs)


t = int(input().strip())
for i in range(t):
	x = int(input().strip())
	j = 9
	s = ''
	if x > 45:
		print(-1)
		continue
	while x:
		if x <= j:
			s = str(x) + s
			x = 0
		else:
			x = x - j
			s = str(j) + s
			j -= 1
	print(s)


import sys
input = sys.stdin.readline

def ri():
	return tuple(map(int, input().split(' ')))
for _ in range(int(input())):
	x = int(input())
	if x > 45:
		print(-1)
	else:
		nums = []
		st = 9
		while x > st:
			x -= st
			nums.append(str(st))
			st -= 1
		nums.append(str(x))
		print(''.join(nums[::-1]))


for _ in range(int(input())):
	n = int(input())
	if n > 45:
		print(-1)
	else:
		x = 9
		lis = ''
		while n > x:
			n -= x
			lis += str(x)
			x -= 1
		lis += str(n)
		print(int(''.join(lis[::-1])))


t = int(input())
for z in range(t):
	n = int(input())
	if n > 45:
		print('-1')
	else:
		arr = [1, 2, 3, 4, 5, 6, 7, 8, 9]
		(s, i) = (n, 8)
		li = []
		while s != 0:
			if s >= arr[i]:
				s -= arr[i]
				li.append(arr[i])
			i -= 1
		for i in range(len(li) - 1, -1, -1):
			print(li[i], end='')
		print()


string = ''
x = []
n = int(input())
for i in range(0, n):
	x.append(int(input()))
for i in range(0, n):
	if x[i] > 45:
		print(-1)
	else:
		for j in range(9, -1, -1):
			if x[i] - j >= 0:
				string += str(j)
				x[i] -= j
			else:
				string += str(x[i])
				break
		string = ''.join(sorted(string))
		if string[0] == '0':
			print(string[1:])
		else:
			print(string)
		string = ''


for i in range(int(input())):
	n = int(input())
	if n < 10:
		print(n)
	elif n > 45:
		print(-1)
	elif n == 45:
		print(123456789)
	elif 10 <= n <= 17:
		print((n - 9) * 10 + 9)
	elif 18 <= n <= 24:
		print((n - 17) * 100 + 89)
	elif 25 <= n <= 30:
		print((n - 24) * 1000 + 789)
	elif 31 <= n <= 35:
		print((n - 30) * 10000 + 6789)
	elif 36 <= n <= 39:
		print((n - 35) * 100000 + 56789)
	elif 40 <= n <= 42:
		print((n - 39) * 1000000 + 456789)
	else:
		print((n - 42) * 10000000 + 3456789)


for _ in range(int(input())):
	x = int(input())
	n = 2
	if x <= 9:
		print(x)
	elif x > 45:
		print(-1)
	elif x == 45:
		for i in range(1, 10):
			print(i, end='')
		print()
	else:
		while n * (n + 1) / 2 + n * (9 - n) <= x:
			n += 1
		n -= 1
		y = x - int(n * (n + 1) / 2 + n * (9 - n))
		if y:
			print(y, end='')
		for i in range(10 - n, 10):
			print(i, end='')
		print()


for _ in range(int(input())):
	n = int(input())
	s = 0
	d = 9
	li = []
	while s < n and d > 0:
		li.append(min(n - s, d))
		s += d
		d -= 1
	if s < n:
		print(-1)
	else:
		li.reverse()
		print(*li, sep='')


for _ in range(int(input())):

	def sum_of_digits(n):
		c = 0
		for i in range(len(n)):
			c += int(n[i])
		return c
	x = int(input())
	s = ''
	Q = 9
	if x > 45:
		print(-1)
	else:
		while sum_of_digits(s) < x:
			s = str(Q) + s
			Q -= 1
		print(str(int(s[0]) - (sum_of_digits(s) - x)) + s[1:])


for _ in range(int(input())):
	n = int(input())
	if n > 45:
		print(-1)
	else:
		x = ''
		s = 9
		while s > 0:
			if n >= s:
				x += str(s)
				n -= s
			s -= 1
		for i in range(len(x) - 1, -1, -1):
			print(x[i], end='')
		print()


def ass(a, b):
	if a != b:
		print(f'Assertion error: {a} != {b}')
	else:
		print('OK')

def intline():
	return [int(item) for item in input().split()]

def line():
	return [item for item in input().split()]

def number():
	return int(input())

def dump(lst):
	for (i, item) in enumerate(lst):
		print(i, item)

def binsearch(arr, a, b):
	m = (a + b) // 2
	if a >= b:
		return a - 1 if arr[a] == 0 else a
	return binsearch(arr, a, m - 1) if arr[m] == 0 else binsearch(arr, m + 1, b)
arr = [-1]
s = ''
for i in range(10):
	for j in range(1, 10 - i):
		arr.append(str(j) + s)
	s = str(9 - i) + s
for i in range(46, 51):
	arr.append(-1)
for i in range(number()):
	print(arr[number()])


for _ in range(int(input())):
	n = int(input())
	ans = ''
	curr = 9
	if n > 45:
		print(-1)
	else:
		while n > 0:
			if n > curr:
				ans += str(curr)
				n -= curr
				curr -= 1
			else:
				ans += str(n)
				n = 0
		a = sorted(ans)
		ans = ''
		for i in a:
			ans += i
		print(ans)


q = int(input())
for i in range(q):
	t = int(input())
	n = 9
	o = []
	if t <= 45:
		while t > 0:
			t = t - n
			o.append(n)
			n = n - 1
		o[len(o) - 1] += t
		o = [str(i) for i in o]
		o = ''.join(o)
		print(o[::-1])
	else:
		print(-1)


t = int(input())
while t > 0:
	f = 0
	num = 987654321
	sum = 45
	n = int(input())
	if n > 45:
		print('-1')
		t -= 1
		continue
	else:
		while f < 45:
			if sum == n:
				break
			elif num % 10 == 1:
				num = int(num / 10)
				sum = sum - 1
			else:
				num = num - 1
				sum = sum - 1
			f += 1
	print(str(num)[::-1])
	t -= 1


def f(x):
	s = 0
	for i in range(10):
		if x >= sum(range(i, 10)):
			s = sum(range(i, 10))
			break
	if x == s:
		return ''.join(map(str, range(i, 10)))
	return ''.join(map(str, sorted([x - s] + list(range(i, 10)))))
t = int(input())
for _ in range(t):
	x = int(input())
	if x > 45:
		print(-1)
	elif x == 45:
		print(123456789)
	elif x < 10:
		print(x)
	else:
		print(f(x))


def sol(x, idx, st):
	global arr
	if x == 0:
		arr.append(st)
	elif x > 0 and idx <= 9:
		sol(x, idx + 1, st)
		sol(x - idx, idx + 1, st + str(idx))
for _ in range(int(input())):
	x = int(input())
	digits = '123456789'
	arr = []
	sol(x, 1, '')
	if not arr:
		print(-1)
	else:
		ans = arr[0]
		for a in arr:
			if len(a) < len(ans):
				ans = a
			elif len(a) == len(ans):
				ans = min(a, ans)
		print(ans)


def main():
	n = int(input())
	output = []
	for i in range(n):
		x = int(input())
		y = x
		for i in range(9, 0, -1):
			if x - i >= 0:
				output.append(i)
				x -= i
		if sum(output) != y:
			print(-1)
		else:
			print(''.join(sorted([str(x) for x in output])))
		output = []
main()


t = int(input())
for o in range(t):
	x = int(input())
	j = x
	k = 45 - x
	sum = 0
	i = 0
	if x > 45:
		print(-1)
	else:
		while i < 10:
			sum = sum + i
			if sum > k:
				break
			i = i + 1
		digits = 10 - i
		k = 0
		i = 1
		while i < digits:
			j = j - (10 - i)
			k = k + (10 - i) * 10 ** (i - 1)
			i = i + 1
		print(j * 10 ** (i - 1) + k)


t = int(input())
for i in range(t):
	x = int(input())
	n = 0
	if x < 10:
		print(x)
	elif x > 45:
		print(-1)
	else:
		n = x
		nums = []
		E = 9
		count = 0
		while n != count:
			if n - count > E:
				count += E
				nums.append(E)
				E -= 1
			else:
				nums.append(n - count)
				count = n
		nums = sorted(nums)
		for k in range(len(nums)):
			print(nums[k], end='')
		print('')


for j in range(int(input())):
	x = int(input())
	j = 9
	my_set = list()
	k = 0
	if x < 46:
		while x != 0:
			for i in range(0, j):
				k = j - i
				if k <= x:
					my_set.append(str(k))
					x -= k
				else:
					my_set.append(str(x))
					x -= x
				if x == 0:
					break
			j -= 1
		s = ''
		for i in range(0, len(my_set)):
			s += my_set[len(my_set) - i - 1]
		print(int(s))
	else:
		print(-1)


T = int(input())
while T:
	dig = 9
	ans = ''
	x = int(input())
	dig = list(range(9, 0, -1))
	if x > 45:
		print(-1)
		T -= 1
		continue
	for i in dig:
		if x >= i:
			ans += str(i)
			x -= i
	print(ans[::-1])
	T -= 1


for _ in range(int(input())):
	n = int(input())
	if n > 45:
		print(-1)
		continue
	i = 9
	k = 1
	ans = 0
	while n > i:
		ans += k * i
		n = n - i
		i -= 1
		k *= 10
	ans += n * k
	print(ans)


for i in range(int(input())):
	n = int(input())
	if n < 10:
		print(n)
	elif n > 45:
		print(-1)
	else:
		s = []
		for j in range(9, 0, -1):
			while n and n - j >= 0:
				s.append(j)
				n -= j
				j -= 1
		print(''.join((str(i) for i in sorted(s))))


for _ in range(int(input())):
	n = int(input())
	if n < 10:
		print(n)
	if 10 <= n <= 17:
		print((n - 9) * 10 + 9)
	if 18 <= n <= 24:
		print((n - 17) * 100 + 89)
	if 25 <= n <= 30:
		print((n - 24) * 1000 + 789)
	if 31 <= n <= 35:
		print((n - 30) * 10000 + 6789)
	if 36 <= n <= 39:
		print((n - 35) * 100000 + 56789)
	if 40 <= n <= 42:
		print((n - 39) * 1000000 + 456789)
	if n == 43:
		print(13456789)
	if n == 44:
		print(23456789)
	if n == 45:
		print(123456789)
	if n > 45:
		print(-1)


t = int(input())
for _ in range(t):
	x = int(input())
	if x > 45:
		print(-1)
		continue
	if x < 10:
		print(x)
		continue
	if x < 18:
		print(str(x - 9) + '9')
		continue
	if x < 25:
		print(str(x - 17) + '89')
		continue
	if x < 31:
		print(str(x - 24) + '789')
		continue
	if x < 36:
		print(str(x - 30) + '6789')
		continue
	if x < 40:
		print(str(x - 35) + '56789')
		continue
	if x < 43:
		print(str(x - 39) + '456789')
		continue
	if x == 43:
		print('13456789')
		continue
	if x == 44:
		print('23456789')
		continue
	if x == 45:
		print('123456789')


for _ in range(int(input())):
	n = int(input())
	if n > 45:
		print(-1)
		continue
	kq = ''
	for i in range(9, 0, -1):
		if n - i < 0:
			continue
		kq = str(i) + kq
		n -= i
	print(kq)


n = int(input())
for i in range(n):
	t = int(input())
	ans = ''
	x = 0
	while t > 0 and x < 10:
		ans = str(min(t, 9 - x)) + ans
		t -= min(t, 9 - x)
		x += 1
	if t > 0:
		print(-1)
	else:
		print(ans)


t = int(input())
answer = []
while t != 0:
	t = t - 1
	x = int(input())
	if x > 45:
		answer.append(-1)
		continue
	result = []
	y = 9
	while y != 0:
		k = x - y
		if k >= 0:
			result.append(y)
			x = x - y
			y = 9 - len(result)
		else:
			y = y - 1
	result = int(''.join(sorted(map(str, result))))
	answer.append(result)
for x in answer:
	print(x)


x = int(input())
dict = {}
for i in range(10):
	dict[i] = i
for i in range(10, 46):
	sum = 9
	digits = '9'
	for j in range(8, 0, -1):
		if sum + j < i:
			sum += j
			digits = str(j) + digits
		elif sum + j == i:
			dict[i] = int(str(j) + digits)
			break
result = []
for i in range(x):
	n = int(input())
	if n > 45:
		result.append(-1)
	else:
		result.append(dict[n])
for i in result:
	print(i)


for _ in range(int(input())):
	num = int(input())
	if num > 45:
		print('-1')
	else:
		ans = ''
		for i in range(9, 0, -1):
			if num - i >= 0:
				num -= i
				ans += str(i)
		ans = ans[::-1]
		print(ans)


import sys
import math
CASE = 1
rla = ''
mp = [9, 8, 7, 6, 5, 4, 3, 2, 1]

def solve():
	n = int(input())
	if n < 10 or n > 45:
		print(n if n < 10 else -1)
		return
	ans = ''
	x = 9
	while n > 0 and x > 0:
		while x > n:
			x -= 1
		n -= x
		ans += chr(x + ord('0'))
		x -= 1
	print(ans[::-1] if n == 0 else -1)
while True:
	rla = sys.stdin.readline()
	cases = 1
	if not rla:
		break
	if (rla == '\n') | (rla == ''):
		continue
	if CASE == 1:
		cases = int(rla)
	for cas in range(cases):
		solve()


t = int(input())
for _ in range(t):
	x = int(input())
	s = ''
	mx = 9
	while len(s) < 9 and x > 0:
		app = min(mx, x)
		if app == mx:
			mx -= 1
		s += str(app)
		x -= app
	if x != 0:
		print(-1)
	else:
		print(s[::-1])


n = int(input())
for i in range(n):
	a = int(input())
	x = [9, 8, 7, 6, 5, 4, 3, 2, 1]
	g = str('')
	if a > 45:
		print('-1')
	else:
		for i in range(len(x)):
			if x[i] > a:
				g += str(a)
				break
			a -= x[i]
			g += str(x[i])
			if a == 0:
				break
		print(g[::-1])


q = int(input())
for _ in range(q):
	x = int(input())
	anum = []
	asum = 0
	if x > 45:
		print(-1)
	else:
		for i in range(10)[::-1]:
			asum += i
			anum.append(i)
			if asum >= x:
				break
		anum[-1] = x - sum(anum[:-1])
		print(*reversed(anum), sep='')


from math import *
import threading
import sys
mod = 10 ** 9 + 7

def npr(n, r):
	return factorial(n) // factorial(n - r) if n >= r else 0

def lower_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] >= num:
			answer = middle
			end = middle - 1
		else:
			start = middle + 1
	return answer

def upper_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] <= num:
			answer = middle
			start = middle + 1
		else:
			end = middle - 1
	return answer

def abs(x):
	return x if x >= 0 else -x

def binary_search(li, val, lb, ub):
	ans = -1
	while lb <= ub:
		mid = (lb + ub) // 2
		if li[mid] > val:
			ub = mid - 1
		elif val > li[mid]:
			lb = mid + 1
		else:
			ans = mid
			break
	return ans

def kadane(x):
	sum_so_far = 0
	current_sum = 0
	for i in x:
		current_sum += i
		if current_sum < 0:
			current_sum = 0
		else:
			sum_so_far = max(sum_so_far, current_sum)
	return sum_so_far

def pref(li):
	pref_sum = [0]
	for i in li:
		pref_sum.append(pref_sum[-1] + i)
	return pref_sum

def graph(n, m):
	adj = dict()
	for i in range(1, n + 1):
		adj.setdefault(i, 0)
	for i in range(m):
		(a, b) = map(int, input().split())
		adj[a] += 1
		adj[b] += 1
	return adj

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	li = []
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	for p in range(2, len(prime)):
		if prime[p]:
			li.append(p)
	return li

def primefactors(n):
	factors = []
	while n % 2 == 0:
		factors.append(2)
		n //= 2
	for i in range(3, int(sqrt(n)) + 1, 2):
		while n % i == 0:
			factors.append(i)
			n //= i
	if n > 2:
		factors.append(n)
	return factors

def prod(li):
	ans = 1
	for i in li:
		ans *= i
	return ans

def dist(a, b):
	d = abs(a[1] - b[1]) + abs(a[2] - b[2])
	return d
sys.setrecursionlimit(300000)
for _ in range(int(input()) if True else 1):
	n = int(input())
	if n > 45:
		print(-1)
	else:
		nums = [1, 2, 3, 4, 5, 6, 7, 8, 9]
		start = 8
		ans = ''
		for i in range(9):
			for j in range(start, -1, -1):
				if nums[j] <= n:
					ans = str(nums[j]) + ans
					start = j - 1
					n -= nums[j]
					break
			if n < 0:
				break
		print(ans)


t = int(input())
i = 1
while True:
	if i > t:
		break
	i = i + 1
	n = int(input())
	if n // 10 == 0:
		print(n)
		continue
	j = 9
	l = 0
	m = 0
	while True:
		if j == 1:
			print(-1)
			break
		n = n - j
		m = 10 ** l * j + m
		if n // j == 0:
			print(10 ** (l + 1) * n + m)
			break
		j = j - 1
		l = l + 1


t = int(input())
for i in range(t):
	x = int(input())
	c = 9
	s = ''
	if x <= 9:
		print(x)
	elif x > 45:
		print(-1)
	else:
		for j in range(9, 0, -1):
			if c < j:
				s = str(c) + s
				break
			x = x - j
			c = x
			s = str(j) + s
		print(int(s))


n = int(input())
for i in range(n):
	x = int(input())
	if x > 45:
		print(-1)
	else:
		ans = ''
		temp = 9
		while temp >= 1:
			if x <= temp:
				ans += str(x)
				break
			else:
				ans += str(temp)
				x -= temp
			temp -= 1
		print(ans[::-1])


def get_ints():
	return [int(x) for x in input().split()]
mv = sum([i for i in range(1, 10)])
t = int(input())
for _ in range(t):
	x = int(input())
	if x > mv:
		print(-1)
	else:
		B = []
		for i in range(9, 0, -1):
			if x:
				s = min([x, i])
				x -= s
				B += [s]
		print(''.join(map(str, B[::-1])))


for i in range(int(input())):
	a = int(input())
	ans = ''
	cnt = 9
	f = True
	while a > 0:
		if a > 9:
			ans += str(cnt)
			a -= cnt
			cnt -= 1
			if cnt == 0:
				f = False
				break
		else:
			ans += str(min(a, cnt))
			a -= cnt
			if a <= 0:
				break
			cnt -= 1
			if cnt == 0:
				f = False
				break
	if f:
		print(ans[::-1])
	else:
		print(-1)


T = int(input())
for i in range(T):
	N = int(input())
	if N > 45:
		print(-1)
		continue
	S = []
	I = 9
	while N > I:
		S.append(str(I))
		N -= I
		I -= 1
	if N > 0:
		S.append(str(N))
	print(*S[::-1], sep='')


for _ in range(int(input())):
	n = int(input())
	if n == 43:
		print('13456789')
		continue
	elif n == 44:
		print('23456789')
		continue
	elif n == 45:
		print('123456789')
		continue
	s = set()
	curr = 9
	num = 0
	copy = n
	ch = 1
	while n > 9:
		if curr < 1:
			ch = 0
			break
		num = num * 10 + curr
		s.add(curr)
		n -= curr
		curr -= 1
	if ch == 0:
		print(-1)
	elif n in s:
		num = num * 10 + curr
		s.add(curr)
		n -= curr
		curr -= 1
		if n in s:
			print(-1)
		else:
			num = num * 10 + n
			num = str(num)
			num = num[::-1]
			print(num)
	else:
		num = num * 10 + n
		num = str(num)
		num = num[::-1]
		print(num)


from collections import *
from math import *
from itertools import *

def I():
	return map(int, input().strip().split())
dp = defaultdict(list)
arr = []
piv = [i for i in range(1, 10)]
for i in range(1, 10):
	arr.append(list(combinations(piv, i)))
for i in arr:
	for j in i:
		if len(dp[sum(j)]) == 0:
			dp[sum(j)] = [k for k in j]
for T in range(int(input())):
	n = int(input())
	if len(dp[n]) == 0:
		print(-1)
	else:
		print(*dp[n], sep='')


for _ in range(int(input())):
	n = int(input())
	l = '9 8 7 6 5 4 3 2 1'.split()
	i = 0
	s = ''
	while n > 0:
		try:
			if n - int(l[i]) >= 0:
				n -= int(l[i])
				s += l[i]
			i += 1
		except:
			print(-1)
			i = 0
			break
	if i != 0:
		print(''.join(sorted(s)) if n == 0 else -1)


for _ in range(int(input())):
	j = int(input())
	a = j
	ans = ''
	ini = 9
	if j < 10:
		ans = str(j) + ans
		j = 0
	while j > 0 and ini > 0:
		ans = str(min(ini, j)) + ans
		j -= ini
		ini -= 1
	if a > 45:
		print(-1)
	else:
		print(ans)


build = [9, 8, 7, 6, 5, 4, 3, 2, 1]
numberOfTests = int(input())
tests = []
for i in range(0, numberOfTests):
	tests.append(int(input()))

def f(num):
	ret = []
	total = 0
	for i in build:
		if total + i <= num:
			total += i
			ret.append(i)
	if sum(ret) != num:
		return [-1]
	else:
		return ret
for t in tests:
	hold = f(t)
	hold.reverse()
	print(''.join(map(str, hold)))


def solve():
	n = int(input())
	if n >= 1 and n <= 9:
		print(n)
	else:
		i = 9
		s = ''
		while n != 0:
			if i <= n:
				n = n - i
				s += str(i)
			i -= 1
			if i == 0:
				break
		if n == 0:
			print(int(s[::-1]))
		else:
			print(-1)
t = int(input())
for i in range(t):
	solve()


t = int(input())
for i in range(t):
	x = int(input())
	if x > 45:
		print(-1)
	else:
		r = ''
		for j in range(9, 0, -1):
			if x >= j:
				x -= j
				r = str(j) + r
		print(int(r))


for _ in range(int(input())):
	n = int(input())
	b = 9
	sub = ''
	if n > 45:
		print(-1)
	else:
		while b > 0:
			n -= b
			if n >= 0:
				sub = str(b) + sub
				b -= 1
			else:
				n += b
				sub = str(n) + sub
				break
		print(int(sub))


t = int(input())
for i in range(t):
	L = []
	x = int(input())
	if x > 45:
		print(-1)
		continue
	else:
		for i in range(9, 0, -1):
			if x > i:
				x -= i
				L.append(i)
			else:
				L.append(x)
				break
	L.reverse()
	otvet = 0
	for i in range(len(L)):
		otvet += 10 ** (len(L) - i - 1) * L[i]
	print(otvet)


from sys import stdin, stdout

def hi(t, l):
	r = 0
	s = 9
	while r < t and s > 0:
		l.append(min(t - r, s))
		r += s
		s -= 1
	if r < t:
		return -1
	else:
		return l
for _ in range(int(input())):
	n = int(input())
	l = []
	h = hi(n, l)
	if h == -1:
		print(-1)
	else:
		l.reverse()
		for i in l:
			print(i, end='')
		print()


import sys
N = int(200000.0 + 5)
sys.setrecursionlimit(N)

def charming():
	x = int(input())
	if x > 45:
		print(-1)
		return
	res = list()
	for i in range(9, 0, -1):
		if x >= i:
			res.append(i)
			x -= i
	if x:
		print(-1)
		return
	res = list(reversed(res))
	for i in res:
		print(i, end='')
	print()
for t in range(int(input())):
	charming()


for _ in range(int(input())):
	n = int(input())
	if n <= 9:
		print(n)
	elif n <= 17:
		print(n - 9, '9', sep='')
	elif n <= 24:
		print(n - 17, '89', sep='')
	elif n <= 30:
		print(n - 24, '789', sep='')
	elif n <= 35:
		print(n - 30, '6789', sep='')
	elif n <= 39:
		print(n - 35, '56789', sep='')
	elif n <= 42:
		print(n - 39, '456789', sep='')
	elif n <= 44:
		print(n - 42, '3456789', sep='')
	elif n <= 45:
		print(n - 44, '23456789', sep='')
	else:
		print('-1')


def Find(n):
	L = []
	s = 9
	while n > 0:
		if n > s:
			L.append(s)
			n -= s
			s -= 1
		else:
			L.append(n)
			n = 0
	L.reverse()
	return L
t = int(input())
for _ in range(t):
	n = int(input())
	if n < 10:
		print(n)
	elif n > 45:
		print(-1)
	else:
		for i in Find(n):
			print(i, end='')
		print()


def getCases():
	cases = []
	t = int(input())
	for case in range(t):
		cases.append(int(input()))
	return cases

def solve(num):
	if num > 45:
		return -1
	foo = [1, 2, 3, 4, 5, 6, 7, 8, 9]
	res = ''
	for i in range(9, 0, -1):
		if num in foo:
			res = ''.join((str(foo.pop(foo.index(num))), res))
			break
		else:
			num -= i
			res = ''.join((str(foo.pop(i - 1)), res))
	ans = int(res)
	return ans
for case in getCases():
	print(solve(case))


n = input()
p = []
for i in range(0, int(n)):
	l = int(input())
	p.append(l)
for i in range(0, len(p)):
	if p[i] < 10:
		print(p[i])
	elif 46 > p[i]:
		sum = p[i]
		j = 9
		k = []
		while j >= 1:
			sum = sum - j
			k.append(j)
			if sum < 9 and sum not in k:
				k.append(sum)
				break
			else:
				j = j - 1
		ans = 0
		ans1 = 0
		for m in range(0, len(k)):
			ans = ans + k[m] * 10 ** m
			ans1 = ans1 + k[m]
		if ans1 == p[i]:
			print(ans)
		else:
			print(-1)
	else:
		print(-1)


import math
test = int(input())
for t in range(test):
	x = int(input())
	y = math.ceil(x / 9)
	n = 9
	res = ''
	SUM = 0
	z = x
	while x > 0 and n > 0:
		res = str(min(n, x)) + res
		x = x - n
		n -= 1
		SUM += int(res[0])
	if SUM == z:
		print(int(res))
	else:
		print(-1)


def solution(n):
	ans = []
	last = 9
	sm = 0
	while sm < n and last > 0:
		ans.append(str(min(last, n - sm)))
		sm += last
		last -= 1
	if sm < n:
		return -1
	return ''.join(ans[::-1])
for i in range(int(input())):
	n = int(input())
	print(solution(n))


def solve(n):
	if n > 45:
		return -1
	if n < 10:
		return n
	s = '9'
	n -= 9
	for i in range(8, 0, -1):
		if n >= i:
			s += str(i)
			n -= i
		if n == 0:
			break
	return s[::-1]
for _ in range(int(input())):
	print(solve(int(input())))


t = int(input())
for x in range(0, t):
	l = []
	ans = ''
	num = int(input())
	k = num
	for i in range(9, 0, -1):
		if num > 0:
			if num >= i:
				num -= i
				l.append(i)
	if sum(l) == k:
		l.sort()
		for c in l:
			ans += str(c)
		print(ans)
	else:
		print(-1)


for _ in range(int(input())):
	x = int(input())
	req = []
	for i in range(9, 0, -1):
		if x <= i:
			req.append(str(x))
			x = 0
			break
		else:
			req.append(str(i))
			x -= i
	req.sort()
	req = ''.join(req)
	if x != 0:
		print(-1)
	else:
		print(req)


t = int(input())
numList = []
cont = 10
numLim = 9
num = '9'
while numLim > 1:
	for i in range(1, numLim):
		numList.append(str(i) + num)
		if i == numLim - 1:
			num = str(i) + num
	numLim -= 1
nums = []
for i in range(t):
	nums.append(int(input()))
for num in nums:
	if num <= 9:
		print(num)
	elif num <= 45:
		print(numList[num - 10])
	else:
		print(-1)


from math import *
sInt = lambda : int(input())
mInt = lambda : map(int, input().split())
lInt = lambda : list(map(int, input().split()))
t = sInt()
for _ in range(t):
	n = sInt()
	if n > 45:
		print(-1)
	elif n // 10 == 0:
		print(n)
	else:
		a = [9]
		n -= 9
		i = 8
		while n != 0:
			if n // 10 == 0 and n <= i:
				a.insert(0, n)
				n = 0
			else:
				a.insert(0, i)
				n -= i
				i -= 1
		print(*a, sep='')


for _ in range(int(input())):
	n = int(input())
	s = ''
	a = 0
	if n > 45:
		print(-1)
	elif n == 0:
		print(0)
	elif n > 0 and n <= 9:
		print(n)
	elif n == 45:
		print(123456789)
	else:
		for i in range(9, 0, -1):
			if n >= a + i:
				a += i
				s += str(i)
			if n == a:
				print(s[::-1])
				break


from collections import deque
t = int(input())

def solve():
	n = int(input())
	if n > 45:
		print(-1)
	else:
		res = []
		v = n
		last_number = 9
		while v > last_number:
			res.append(str(last_number))
			v -= last_number
			last_number -= 1
		if v > 0:
			res.append(str(v))
		res.reverse()
		ans = ''.join(res)
		print(ans)
	return
for i in range(t):
	solve()


_t = int(input())
for _i in range(_t):
	x = int(input())
	if x > 45:
		print(-1)
		continue
	a = []
	sum = 0
	i = 9
	while i > 0:
		sum += i
		if sum == x:
			print(i, sep='', end='')
			for j in range(len(a) - 1, -1, -1):
				print(a[j], sep='', end='')
			print()
			break
		elif sum < x:
			a.append(i)
		else:
			sum -= i
		i -= 1


for i in range(int(input())):
	n = input()
	lst = []
	if len(n) == 1:
		print(n)
	elif int(n) > 45:
		print(-1)
	else:
		n = int(n)
		for i in range(9, 0, -1):
			lst.append(i)
			n -= i
			if n < i:
				lst.append(n)
				break
		for i in range(len(lst) - 1, -1, -1):
			print(lst[i], end='')
		print()


t = int(input())
for loop in range(t):
	x = int(input())
	if x < 10:
		print(x)
	elif x > 45:
		print(-1)
	else:
		cur = 9
		temp_x = x
		s = ''
		for a in range(10):
			if temp_x > cur:
				s += str(cur)
				temp_x -= cur
				cur -= 1
			else:
				s += str(temp_x)
				print(s[::-1])
				break


def unique_number():
	for _ in range(int(input())):
		n = int(input())
		found = False
		ans = []
		i = 0
		k = [9, 8, 7, 6, 5, 4, 3, 2, 1]
		while n != 0 and i < len(k):
			if k[i] <= n:
				if k[i] == n:
					found = True
				n = n - k[i]
				ans += [k[i]]
			i += 1
		ans.reverse()
		print(*(ans if found else [-1]), sep='')
unique_number()


def find_number(x):
	number = ''
	figure = 9
	while x != 0:
		if x - figure >= 0 and figure > 0:
			number += f'{figure}'
			x -= figure
			figure -= 1
		elif figure < 0:
			return -1
		elif x == 0 and figure == 0:
			return int(number[::-1])
		else:
			figure -= 1
	return int(number[::-1])
for i in range(int(input())):
	x = int(input())
	print(find_number(x))


t = int(input())
for _ in range(t):
	n = int(input())
	x = n
	opts = [1, 2, 3, 4, 5, 6, 7, 8, 9]
	notFound = True
	ans = []
	while notFound and len(opts) != 0:
		if x - max(opts) <= 0:
			ans.append(x)
			notFound = False
		else:
			ans.append(max(opts))
			x -= max(opts)
			opts.remove(max(opts))
	if len(opts) == 0:
		print(-1)
	else:
		ans.sort()
		ans = list(map(str, ans))
		print(''.join(ans))


for _ in range(int(input())):
	n = int(input())
	if n > 45:
		print(-1)
	else:
		x = 9
		ans = ''
		while n > 0:
			a = min(n, x)
			ans += str(a)
			n -= a
			x -= 1
		print(ans[::-1])


T = int(input())
for t in range(T):
	x = int(input())
	if x < 10:
		print(x)
		continue
	if x < 18:
		print((x - 9) * 10 + 9)
		continue
	if x < 25:
		print((x - 17) * 100 + 89)
		continue
	if x < 31:
		print((x - 24) * 1000 + 789)
		continue
	if x < 36:
		print((x - 30) * 10000 + 6789)
		continue
	if x < 40:
		print((x - 35) * 100000 + 56789)
		continue
	if x < 43:
		print((x - 39) * 1000000 + 456789)
		continue
	if x < 45:
		print((x - 42) * 10000000 + 3456789)
		continue
	if x < 46:
		print(123456789)
		continue
	print(-1)


for i in range(int(input())):
	x = int(input())
	p = ''
	if x < 10:
		print(x)
	elif x > 45:
		print(-1)
	else:
		for j in range(9, 0, -1):
			if x >= j:
				p = p + str(j)
				x = x - j
			if x == 0:
				break
		for k in range(len(p) - 1, -1, -1):
			print(p[k], end='')
		print()


cases = int(input())
while cases:
	cases -= 1
	n = int(input())
	if n < 10:
		print(n)
	elif n > 45:
		print(-1)
	else:
		last = 9
		ans = 90
		n -= 9
		while n:
			ans += 1
			n -= 1
			if ans % 10 == last:
				ans -= 1
				ans *= 10
				ans += 1
				last -= 1
		print(str(ans)[::-1])


t = int(input())
while t:
	t -= 1
	cc = 0
	ssum = ans = 0
	k = 1
	x = int(input())
	if x > 45:
		print('-1')
	else:
		for i in range(9, -1, -1):
			for j in range(i, -1, -1):
				if ssum + j == x:
					ans += j * k
					cc = 1
					break
			ssum += i
			if cc == 1:
				break
			ans += i * k
			k *= 10
		print('%d' % ans)


for _ in range(int(input())):
	x = int(input())
	s = 0
	i = 0
	ans = ''
	while s != x:
		if x > 9 - i:
			ans = str(9 - i) + ans
			x -= 9 - i
			i += 1
		else:
			ans = str(x) + ans
			x = 0
		if i == 9 and x != 0:
			ans = '-1'
			break
	print(ans)


def Solution(x):
	if x < 10:
		return x
	if x > 45:
		return -1
	maxNum = 9
	res = []
	while x > 0:
		if x > maxNum:
			res.insert(0, maxNum)
			x -= maxNum
			maxNum = maxNum - 1
		else:
			res.insert(0, x)
			x -= x
	num = ''
	for v in res:
		num += str(v)
	return int(num)
for t in range(int(input())):
	X = int(input())
	print(Solution(X))


t = int(input())
while t > 0:
	n = int(input())
	if n > 45:
		print('-1')
	else:
		ans = ''
		for i in range(9, 0, -1):
			if n - i >= 0:
				n = n - i
				ans = str(i) + ans
			if n <= 0:
				break
		print(ans)
	t = t - 1


t = int(input())
for i in range(t):
	n = int(input())
	if n > 45:
		print(-1)
	elif n < 10:
		print(n)
	else:
		j = 9
		l = []
		while n > 0:
			if n < j:
				l.append(n)
				break
			else:
				l.append(j)
				n -= j
				j -= 1
		l.sort()
		for j in range(len(l)):
			print(l[j], end='')
		print()


res = {}
dig = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
for i in range(1, 2 ** 10):
	s = 0
	_str = ''
	for j in range(10):
		if 1 << j & i:
			s += dig[j]
			_str += str(dig[j])
	aux = res.get(s)
	if aux != None:
		if aux > int(_str):
			res[s] = int(_str)
	else:
		res[s] = int(_str)
for i in range(int(input())):
	e = int(input())
	r = res.get(e)
	if r != None:
		print(r)
	else:
		print(-1)


import collections
N = int(input())
for _ in range(N):
	n = int(input())
	if n < 10:
		print(n)
	elif n < 18:
		print(str(n - 9) + '9')
	elif n < 25:
		print(str(n - 17) + '89')
	elif n < 31:
		print(str(n - 24) + '789')
	elif n < 36:
		print(str(n - 30) + '6789')
	elif n < 40:
		print(str(n - 35) + '56789')
	elif n < 43:
		print(str(n - 39) + '456789')
	elif n < 45:
		print(str(n - 42) + '3456789')
	elif n < 46:
		print('123456789')
	else:
		print(-1)


for _ in range(int(input())):
	x = int(input())
	if x > 45:
		print('-1')
		continue
	ans = ''
	for n in range(9, 0, -1):
		if x > n:
			ans += str(n)
			x -= n
		else:
			ans += str(x)
			print(ans[::-1])
			break


for _ in range(0, int(input())):
	x = int(input())
	i = 9
	v = ''
	if x > 45:
		print(-1)
	else:
		while x > i:
			v = str(i) + v
			x -= i
			i -= 1
		print(str(x) + v)


t = int(input())
for i in range(t):
	x = int(input())
	if x > 45:
		print(-1)
	elif x < 10:
		print(x)
	else:
		array = []
		n = 9
		while x > 0:
			if x >= n:
				array.insert(0, n)
				x -= n
				n -= 1
			else:
				array.insert(0, x)
				x = 0
		s = ''
		for j in array:
			s += str(j)
		print(s)


resList = []
testCount = int(input())
for test in range(testCount):
	num = int(input())
	sum = 0
	numStr = ''
	if num > 45:
		resList.append(str(-1))
	elif len(str(num)) == 1:
		resList.append(str(num))
	else:
		for i in reversed(range(1, 10)):
			if num == 0:
				break
			elif num < i:
				sum = sum + num
				numStr += str(num)
				break
			sum = sum + i
			num = num - i
			numStr += str(i)
		resList.append(numStr[::-1])
for res in resList:
	print(res)


from sys import stdin, stdout
from collections import defaultdict
input = stdin.readline
from random import randint
import math
import itertools
L = [int(i) for i in range(1, 10)]
mylists = []
for n in range(1, 10):
	LL = list(itertools.combinations(L, n))
	for item in LL:
		mylists.append(item)
for i in range(len(mylists)):
	mylists[i] = sorted(list(mylists[i]))
mylists.sort()
d = {}
for ttt in range(51):
	x = ttt
	target = []
	for item in mylists:
		s = 0
		for ij in item:
			s += int(ij)
		if s == x and len(item) > 0:
			target.append(item)
	if len(target) == 0:
		d[x] = -1
	else:
		L = len(target[0])
		for item in target:
			L = min(L, len(item))
		final = []
		for item in target:
			if len(item) == L:
				final.append(item)
		final.sort()
		k = final[0]
		for i in range(len(k)):
			k[i] = str(k[i])
		answer = ''.join(k)
		d[x] = answer
for _ in range(int(input())):
	q = int(input())
	print(d[q])


for t in range(int(input())):
	n = int(input())
	if n > 45:
		print(-1)
		continue
	if n < 10:
		print(n)
		continue
	ans = ''
	counter = 9
	while n >= 10 or counter < n:
		n -= counter
		ans = str(counter) + ans
		counter -= 1
	ans = str(n) + ans
	print(ans)


rn = lambda : int(input())
rns = lambda : map(int, input().split())
rl = lambda : list(map(int, input().split()))
rs = lambda : input()
yn = lambda x: print('Yes') if x else print('No')
YN = lambda x: print('YES') if x else print('NO')
pl = lambda l: print(' '.join(list(map(str, l))))
for _ in range(rn()):
	n = rn()
	if n > 45:
		print(-1)
	else:
		ans = ''
		sum = 0
		last = 0
		for i in range(9, 0, -1):
			sum += i
			last = i
			if sum > n:
				sum -= i
				last = i + 1
			else:
				ans = str(i) + ans
		if sum != n:
			for i in range(1, last):
				if sum + i == n:
					ans = str(i) + ans
					sum += i
		if sum == n:
			print(ans)


t = int(input())
for i in range(t):
	x = int(input())
	x1 = 0
	if x >= 46:
		x1 = -1
	elif x < 10:
		x1 = x
	elif x < 18:
		x1 = x - 9
		x1 = 10 * x1 + 9
	elif x < 25:
		x1 = x - 17
		x1 = 100 * x1 + 89
	elif x < 31:
		x1 = x - 24
		x1 = x1 * 1000 + 789
	elif x < 36:
		x1 = x - 30
		x1 = x1 * 10000 + 6789
	elif x < 40:
		x1 = x - 35
		x1 = x1 * 100000 + 56789
	elif x < 43:
		x1 = x - 39
		x1 = x1 * 1000000 + 456789
	elif x < 45:
		x1 = x - 42
		x1 = x1 * 10000000 + 3456789
	else:
		x1 = 123456789
	print(x1)


for _ in range(int(input())):
	x = int(input())
	(c, i, ans, n) = (0, 9, 0, x)
	for i in range(9, 0, -1):
		if n - i <= 0:
			break
		ans += i * 10 ** c
		c += 1
		n = n - i
	if n > 0 and x < 46:
		ans += n * 10 ** c
		print(ans)
	else:
		print(-1)


def solve(n):
	if n > 45:
		return -1
	return helper(n, 9, '')

def helper(n, curr, path):
	if n == 0:
		return path
	if curr <= 0:
		return '-1'
	while curr > n:
		curr -= 1
	return helper(n - curr, curr - 1, str(curr) + path)
T = int(input())
for t in range(T):
	n = int(input())
	result = solve(n)
	print(result)