Find the minimum number with the given sum of digits $s$ such that all digits in it are distinct (i.e. all digits are unique).

For example, if $s=20$, then the answer is $389$. This is the minimum number in which all digits are different and the sum of the digits is $20$ ($3+8+9=20$).

For the given $s$ print the required number.


-----Input-----

The first line contains an integer $t$ ($1 \le t \le 45$) — the number of test cases.

Each test case is specified by a line that contains the only integer $s$ ($1 \le s \le 45$).


-----Output-----

Print $t$ integers — the answers to the given test cases.


-----Examples-----

Input
4
20
8
45
10
Output
389
8
123456789
19


-----Note-----

None

Difficulty: EASY
Tags: Greedy algorithms
Skill types: Greedy algorithms

Starter code:

Solutions:
t = int(input())
for i in range(t):
	num = int(input())
	reverse = ''
	sum1 = 0
	while sum1 != num:
		digits = '987654321'
		for x in digits:
			if sum1 + int(x) > num:
				digits = digits[digits.index(x) + 1:len(digits)]
			else:
				digits = digits[digits.index(x) + 1:len(digits)]
				reverse += str(x)
				sum1 += int(x)
	real = ''
	for y in range(-1, -1 * (len(reverse) + 1), -1):
		real += reverse[y]
	print(int(real))


for i in range(int(input())):
	x = int(input())
	s = ''
	for i in range(9, 0, -1):
		if x - i == abs(x - i):
			x = x - i
			s = str(i) + s
	print(s)


t = int(input())
for _ in range(t):
	n = int(input())
	a = 9
	s = ''
	cnt = 20
	while n > 0 and cnt > 0:
		cnt -= 1
		s += str(min(a, n))
		a -= 1
		n -= int(s[-1])
	print(s[::-1])


t = int(input())
for i in range(t):
	s = int(input())
	L = []
	i = 0
	while s > 0:
		if s >= 9 - i:
			s -= 9 - i
			L.append(9 - i)
			i += 1
		else:
			L.append(s)
			s = 0
	L.reverse()
	M = [str(x) for x in L]
	print(''.join(M))


t = int(input())
for c in range(t):
	n = int(input())
	ans = list()
	digitos = [1, 2, 3, 4, 5, 6, 7, 8, 9]
	while n > 0:
		dec = min(n, digitos[-1])
		digitos.remove(dec)
		ans.append(dec)
		n = n - dec
	output = ''
	for c in range(len(ans) - 1, -1, -1):
		output += str(ans[c])
	print(output)


for _ in range(int(input())):
	num = ''
	done = False
	toget = int(input())
	for stuff in range(9, 0, -1):
		num = str(stuff) + num
		if sum([int(x) for x in num]) > toget:
			curnum = num[1:]
			curnum = str(toget - sum([int(x) for x in curnum])) + curnum
			print(int(curnum))
			done = True
			break
	if not done:
		print(num)


l = [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, 0, 0, 0, 0, 0, 0, 0, 0]
l[40] = 1456789
l[41] = 2456789
l[42] = 3456789
l[43] = 13456789
l[44] = 23456789
l[45] = 123456789
for i in range(int(input())):
	print(l[int(input())])


import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
t = int(input())
for _ in range(t):
	s = int(input())
	if 1 <= s <= 9:
		print(s)
	elif 10 <= s <= 17:
		print((s - 9) * 10 + 9)
	elif 18 <= s <= 24:
		print((s - 17) * 100 + 89)
	elif 25 <= s <= 30:
		print((s - 24) * 1000 + 789)
	elif 31 <= s <= 35:
		print((s - 30) * 10000 + 6789)
	elif 36 <= s <= 39:
		print((s - 35) * 10 ** 5 + 56789)
	elif 40 <= s <= 42:
		print((s - 39) * 10 ** 6 + 456789)
	elif 43 <= s <= 44:
		print((s - 42) * 10 ** 7 + 3456789)
	else:
		print(123456789)


t = int(input())
for i in range(t):
	n = int(input())
	ar = []
	max = 9
	while n >= max:
		n -= max
		ar.append(max)
		max -= 1
		if n == 0:
			break
	if n > 0:
		ar.append(n)
	ans = 0
	for j in range(1, len(ar) + 1):
		ans *= 10
		ans += ar[len(ar) - j]
	print(ans)


ts = int(input())
for _ in range(ts):
	s = int(input())
	x = 9
	ans = 0
	i = 0
	while s > x:
		ans += x * 10 ** i
		s -= x
		x -= 1
		i += 1
	ans += s * 10 ** i
	print(ans)


def fun():
	t = int(input())
	while t:
		n = int(input())
		res = ''
		max_ele = 9
		while n:
			if n > max_ele:
				n -= max_ele
				res = res + str(max_ele)
				max_ele -= 1
			else:
				res = res + str(n)
				n = 0
		res1 = ''
		for ind in reversed(range(len(res))):
			res1 = res1 + res[ind]
		print(res1)
		t -= 1
fun()


t = int(input())
sol = []
for _ in range(t):
	s = int(input())
	a = []
	for i in range(9, 0, -1):
		if i <= s:
			a.append(i)
			s -= i
	a = [str(x) for x in a][::-1]
	sol.append(''.join(a))
for s in sol:
	print(s)


t = int(input())
while t:
	t -= 1
	sum = int(input())
	r = ''
	add = 9
	while sum != 0 and add > 0:
		if add > sum:
			add -= 1
			continue
		r += str(add)
		sum -= add
		add -= 1
	print(r[::-1])


from collections import Counter
n = int(input())
for _ in range(n):
	s = int(input())
	currSum = 0
	reversedList = []
	for digit in range(9, -1, -1):
		currSum += digit
		reversedList.append(digit)
		if currSum >= s:
			currSum -= digit
			reversedList.pop()
			break
	diff = s - currSum
	reversedList.append(diff)
	res = map(str, reversed(reversedList))
	print(''.join(res))


for x in range(int(input())):
	num = int(input())
	curr = 9
	digits = ''
	while num > 0:
		if num > curr:
			num -= curr
			digits += str(curr)
			curr -= 1
		else:
			digits += str(num)
			num = 0
	print(digits[::-1])


dicc = {'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'}
cant = int(input())
while cant > 0:
	num = input()
	print(dicc[num])
	cant -= 1


def main():
	t = int(input())
	for i in range(t):
		n = int(input())
		max_num = 9
		res = ''
		while n != 0:
			if n < max_num:
				res += str(n)
				break
			res += str(max_num)
			n -= max_num
			max_num -= 1
		ans = int(res[::-1])
		print(ans)
main()


t = int(input())

def solve():
	k = int(input())
	if k <= 9:
		print(k)
	elif k <= 17:
		print(9 + (k - 9) * 10)
	elif k <= 24:
		print(89 + (k - 17) * 100)
	elif k <= 30:
		print(789 + 1000 * (k - 24))
	elif k <= 35:
		print(6789 + 10000 * (k - 30))
	elif k <= 39:
		print(56789 + 100000 * (k - 35))
	elif k <= 42:
		print(456789 + 1000000 * (k - 39))
	elif k <= 44:
		print(3456789 + 10000000 * (k - 42))
	else:
		print(123456789)
while t:
	solve()
	t -= 1


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


for _ in range(int(input())):
	ans = int(input())
	l = []
	while ans > 0:
		if ans - 9 >= 0:
			ans -= 9
			l.append(9)
		if ans - 8 >= 0:
			ans -= 8
			l.append(8)
		if ans - 7 >= 0:
			ans -= 7
			l.append(7)
		if ans - 6 >= 0:
			ans -= 6
			l.append(6)
		if ans - 5 >= 0:
			ans -= 5
			l.append(5)
		if ans - 4 >= 0:
			ans -= 4
			l.append(4)
		if ans - 3 >= 0:
			ans -= 3
			l.append(3)
		if ans - 2 >= 0:
			ans -= 2
			l.append(2)
		if ans - 1 >= 0:
			ans -= 1
			l.append(1)
	l.sort()
	pp = ''
	for i in l:
		oo = str(i)
		pp += oo
	print(pp)


for _ in range(int(input())):
	a = int(input())
	l = []
	for i in range(9):
		if a <= 9 and a not in l:
			l.append(a)
			break
		else:
			a = a - (9 - i)
			l.append(9 - i)
	l.reverse()
	l = map(str, l)
	r = ''.join(l)
	print(r)


import math
t = int(input())
for _ in range(t):
	s = int(input())
	if 0 <= s <= 9:
		print(s)
		continue
	n_digits = 1
	i = 9
	val = 9
	while s > val:
		i -= 1
		val += i
		n_digits += 1
	arr = []
	val = 9
	tot = 0
	for i in range(n_digits - 1):
		arr.append(str(val))
		tot += val
		val -= 1
	arr.append(str(s - tot))
	arr.reverse()
	print(''.join(arr))


t = int(input())
while t:
	t -= 1
	n = int(input())
	if n > 0 and n < 10:
		print(n)
		continue
	elif n > 9 and n < 18:
		i = n - 9
		i = str(i)
		s = i + '9'
	elif n > 17 and n < 25:
		i = n - 17
		i = str(i)
		s = i + '89'
	elif n > 24 and n < 31:
		i = n - 24
		i = str(i)
		s = i + '789'
	elif n > 30 and n < 36:
		i = n - 30
		i = str(i)
		s = i + '6789'
	elif n > 35 and n < 40:
		i = n - 35
		i = str(i)
		s = i + '56789'
	elif n > 39 and n < 43:
		i = n - 39
		i = str(i)
		s = i + '456789'
	elif n > 42 and n < 45:
		i = n - 42
		i = str(i)
		s = i + '3456789'
	else:
		i = n - 44
		i = str(i)
		s = i + '23456789'
	print(int(s))


t = int(input())
for a in range(t):
	s = int(input())
	numcount = 0
	currvalue = 0
	for i in range(9, 0, -1):
		if i <= s:
			s -= i
			currvalue += i * 10 ** numcount
			numcount += 1
	print(currvalue)


import sys
t = int(input())
while t:
	p = int(input())
	check = 9
	res = ''
	while p:
		while p < check:
			check -= 1
		res += str(0 + check)
		p -= check
		check -= 1
	print(''.join(reversed(res)))
	t -= 1


for _ in range(int(input())):
	summ = int(input())
	digits = [1, 2, 3, 4, 5, 6, 7, 8, 9]
	num = 0
	place = 1
	while summ // 10 > 0:
		summ -= digits[-1]
		num += place * digits[-1]
		place *= 10
		digits.pop()
	while summ > 0:
		if summ in digits:
			num += place * summ
			break
		else:
			summ -= digits[-1]
			num += place * digits[-1]
			place *= 10
			digits.pop()
	print(num)


test = int(input())
while test > 0:
	test -= 1
	n = int(input())
	if n <= 9:
		print(n)
	else:
		t = ''
		temp = 9
		while n > 0 and temp > 0:
			if n - temp >= 0:
				t += str(temp)
				n -= temp
			temp -= 1
		print(t[::-1])


t = int(input())
for i in range(t):
	s = int(input())
	k = s
	p = []
	if s < 10:
		p.append(s)
		s = 0
	else:
		m = 9
		while s > m:
			s -= m
			p.append(m)
			m -= 1
	p.append(s)
	x = ''.join([str(i) for i in p[::-1]])
	print(int(x))


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


cases = int(input())

def get_num(num, arr, current_num=9):
	if num < 10 and num not in arr:
		return num
	arr.append(current_num)
	return current_num + 10 * get_num(num - current_num, arr, current_num=current_num - 1)
while cases:
	res = get_num(int(input()), [])
	print(res)
	cases -= 1


t = int(input())
for i in range(t):
	s = int(input())
	c = 0
	n = 9
	if s > n:
		while s >= n and n > 0:
			s -= n
			c = c + n * 10 ** (9 - n)
			n -= 1
		c += s * 10 ** (9 - n)
		print(c)
	else:
		print(s)


testcases = int(input())
for i in range(testcases):
	split_num = int(input())
	split_list = []
	while split_num >= 10:
		for j in range(9, 0, -1):
			if j not in split_list:
				split_list.append(j)
				split_num -= j
				if split_num in split_list:
					continue
				break
	split_list.append(split_num)
	final_list = ''
	for a in split_list:
		a = str(a)
		final_list += a
	print(final_list[::-1])


def solution(n):
	nums = [1, 2, 3, 4, 5, 6, 7, 8, 9]
	outs = []
	while n > 0:
		num = nums.pop()
		if n >= num:
			n -= num
			outs.append(num)
	return ''.join(map(str, outs[::-1]))
t = int(input())
msgs = []
for _ in range(t):
	n = int(input())
	msgs.append(f'{solution(n)}')
print('\n'.join(msgs))


for s in [*map(int, open(0))][1:]:
	r = ''
	i = 9
	while s:
		while i > s:
			i -= 1
		if i:
			s -= i
			r = str(i) + r
		i -= 1
	print(r)


t = int(input())
for i in range(t):
	s = int(input())
	ans = 0
	if s < 10:
		ans = s
	else:
		i = 9
		while i > 0:
			if s >= i:
				ans = i * 10 ** (9 - i) + ans
				s = s - i
				i -= 1
			else:
				ans = s * 10 ** (9 - i) + ans
				break
	print(ans)


def solve():
	v = [''] * 46
	v[1] = '1'
	v[2] = '2'
	v[3] = '3'
	v[4] = '4'
	v[5] = '5'
	v[6] = '6'
	v[7] = '7'
	v[8] = '8'
	v[9] = '9'
	c = 10
	l = 9
	b = '9'
	while c <= 45:
		a = 1
		while a < l:
			v[c] = b + str(a)
			c += 1
			a += 1
		b += str(l - 1)
		l -= 1
	t = int(input())
	for _ in range(t):
		q = int(input())
		print(v[q][::-1])
solve()


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


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


t = int(input())
while t:
	n = int(input())
	m = n
	a = []
	k = 9
	if m <= 9:
		print(m)
	else:
		while m != 0:
			m = m - k
			a.append(k)
			k = k - 1
			while m < k:
				k = k - 1
		b = a[::-1]
		m = ''
		for i in range(len(b)):
			m = m + str(b[i])
		print(m)
	t = t - 1


_ = int(input())
for t in range(_):
	s = int(input())
	res = ''
	for x in range(9, 0, -1):
		if x <= s:
			s -= x
			res += str(x)
	print(res[::-1])


a = int(input())
for i in range(a):
	b = int(input())
	j = 9
	sum = 0
	ans = ''
	k = b
	while sum != b:
		if k > j:
			ans += f'{j}'
			sum += j
			k = k - j
			j -= 1
		else:
			ans += f'{k}'
			sum += k
	print(ans[::-1])


T = int(input())
for _ in range(T):
	s = int(input())
	(ans, cur) = (0, 9)
	while s:
		if s < cur:
			ans += s * 10 ** (9 - cur)
			break
		else:
			ans += cur * 10 ** (9 - cur)
			s -= cur
			cur -= 1
	print(ans)


def summa(s, n, k, q):
	for j in range(1, 10):
		n[k] = j
		if sum(n) == s or j == q:
			return j
		else:
			continue
t = int(input())
for i in range(t):
	s = int(input())
	if s <= 9:
		print(s)
	else:
		m = 9
		q = 8
		n = [0] * m
		n[0] = m
		for k in range(1, 9):
			if s != m:
				p = summa(s, n, k, q)
				q = q - 1
				m = m + p
			else:
				break
		for r in range(8, -1, -1):
			if n[r] == 0:
				del n[r]
		n = sorted(n)
		u = len(n)
		w = 0
		for v in range(u):
			w = w + n[v] * 10 ** (u - v - 1)
		print(w)


def get_min_number(s):
	res = 0
	i = 9
	k = 0
	while s > 0:
		if s - i >= 0:
			res = i * 10 ** k + res
			s -= i
		else:
			res = s * 10 ** k + res
			s = 0
		k += 1
		i -= 1
	return res

def solve():
	s = int(input())
	print(get_min_number(s))
for _ in range(int(input())):
	solve()


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


t = int(input())
for i in range(t):
	x = int(input())
	l = 9
	c = 1
	j = 0
	while x // l != 0 and l != 1:
		x -= l
		j = c * l + j
		l -= 1
		c *= 10
	l = x
	j = c * l + j
	print(j)


test_cases = int(input())
for i in range(test_cases):
	s = int(input())
	digits = list(range(9, 0, -1))
	desired_number = ''
	for number in digits:
		if s >= number:
			desired_number += str(number)
			s -= number
		else:
			if s != 0:
				desired_number += str(s)
			break
	print(desired_number[::-1])


l = []
n = [i for i in range(1, 10)]
n.reverse()
a = int(input())
for i in range(a):
	l.append(int(input()))
for i in l:
	ans = ''
	for j in n:
		if i >= j:
			i = i - j
			ans = str(j) + ans
		else:
			ans = str(i) + ans
			break
	print(int(ans))


def main():
	s = int(input())
	res = ''
	n = 9
	while s > n:
		res = str(n) + res
		s -= n
		n -= 1
	print(str(s) + res)
for _ in range(int(input())):
	main()


t = int(input())
slist = []
for i in range(t):
	slist.append(int(input()))
final = []
for i in range(t):
	final.append([])
	for nz in range(9, 0, -1):
		if slist[i] - nz >= 0:
			final[i].append(nz)
			slist[i] -= nz

def Reverse(lst):
	new_lst = lst[::-1]
	return new_lst
for i in range(t):
	print(*Reverse(final[i]), sep='')


for _ in range(int(input())):
	s = int(input())
	r = []
	summa = 0
	for i in range(9):
		if summa + 9 - i > s:
			r.append(str(s - summa))
			break
		else:
			r.append(str(9 - i))
			summa += 9 - i
	print(int(''.join(r[::-1])))


def ans(n):
	x = n
	if n < 10:
		return n
	i = 9
	while n >= 3:
		n = n - i
		if n < 0:
			n = n + i
			break
		i -= 1
	while i < 9:
		n = n * 10 + i + 1
		i += 1
	return n
r = []
T = int(input())
for _ in range(T):
	n = int(input())
	c = ans(n)
	r.append(c)
for i in range(T):
	print(r[i])


t = int(input())
for i in range(t):
	s = int(input())
	if s < 10:
		x = s
	else:
		for j in range(10):
			if s > 45 - j * (j + 1) / 2:
				break
		x = int(s - 45 + j * (j + 1) / 2)
		for k in range(j + 1, 10):
			x = x * 10 + k
	print(x)


n = int(input())
r = []

def m(n):
	if n == 0:
		return 9
	else:
		return n - 1
for i in range(n):
	s = int(input())
	k = 9
	nn = ''
	while s > 0:
		if s <= 9 and str(s) not in nn:
			nn = nn + str(s)
			break
		if str(k) not in nn:
			nn = nn + str(k)
			s -= k
			k = m(k)
		else:
			while k in nn:
				k = m(k)
				s -= k
				nn = nn + str(k)
	r.append(nn[::-1])
for j in r:
	print(j)


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


t = int(input())
for _ in range(t):
	s = int(input())
	sol = ''
	summ = 0
	for i in range(9, 0, -1):
		if summ + i <= s:
			sol = str(i) + sol
			summ = summ + i
	print(sol)


t = int(input())
for i in range(t):
	n = int(input())
	if n <= 9:
		print(n)
	elif n <= 17:
		print((n - 9) * 10 + 9)
	elif n <= 24:
		print((n - 17) * 100 + 89)
	elif n <= 30:
		print((n - 24) * 1000 + 789)
	elif n <= 35:
		print((n - 30) * 10000 + 6789)
	elif n <= 39:
		print((n - 35) * 100000 + 56789)
	elif n <= 42:
		print((n - 39) * 1000000 + 456789)
	elif n == 43:
		print(13456789)
	elif n == 44:
		print(23456789)
	elif n == 45:
		print(123456789)


import sys

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

def get_ints_arr():
	return list(get_ints())
t = int(sys.stdin.readline())
for test in range(t):
	n = int(sys.stdin.readline())
	if n < 10:
		print(n)
		continue
	digit = 9
	currentSum = 0
	ans = ''
	left = n
	while currentSum != n:
		if digit > left:
			digit -= 1
		else:
			ans = str(digit) + ans
			currentSum += digit
			left -= digit
			digit -= 1
	print(ans)


def digi(s):
	i = 9
	sum = 9
	p = True
	d = 1
	while i > 0 and p:
		if s > sum:
			sum += i - 1
			d += 1
		else:
			p = False
		i = i - 1
	return d

def tot(l):
	x = len(l)
	sum = 0
	for i in range(x):
		sum += l[i]
	return sum

def out(l):
	l.reverse()
	str1 = ''
	for ele in l:
		ele = str(ele)
		str1 += ele
	return str1

def get(s):
	x = digi(s)
	l = []
	for i in range(x):
		l.append(9 - i)
	sum = tot(l)
	still = True
	while s <= sum and still:
		if s == sum:
			still = False
		elif x == 1:
			l[0] = l[0] - 1
		else:
			i = x - 1
			while i > 0:
				if l[i] == 1:
					i -= 1
					break
				else:
					l[i] = l[i] - 1
				break
		sum = tot(l)
	print(out(l))
t = int(input())
for i in range(t):
	s = int(input())
	get(s)


for _ in range(int(input())):
	n = int(input())
	c = 9
	ans = ''
	while n > c:
		ans = str(c) + ans
		n -= c
		c -= 1
	ans = str(n) + ans
	print(int(ans))


def fun(n):
	num = 0
	for i in range(9, 0, -1):
		if n - i < 0:
			num += n * 10 ** (9 - i)
			break
		else:
			n = n - i
			num += i * 10 ** (9 - i)
	print(num)
t = int(input())
for _ in range(t):
	n = int(input())
	fun(n)


def recursive_subtraction(s, x, num):
	if s < 10 and str(s) not in x:
		x += f'{str(s)}'
		return x
	else:
		x += f'{str(num)}'
		s -= num
		num -= 1
		return recursive_subtraction(s, x, num)
t = int(input())
for i in range(t):
	n = int(input())
	print(recursive_subtraction(n, '', 9)[::-1])


t = int(input())
for i in range(t):
	n = int(input())
	L = []
	x = 9
	while n >= 10 or n > x:
		n = n - x
		L.append(x)
		x -= 1
	L.append(n)
	for i in range(len(L) - 1, -1, -1):
		print(L[i], end='')
	print()


inplst = []
for _ in range(int(input())):
	s = int(input())
	inplst.append(s)
for s in inplst:
	lst = []
	for rng in range(9, 0, -1):
		if s <= rng:
			lst.append(s)
			break
		else:
			n = s - rng
			s = n
			lst.append(rng)
	for _ in range(len(lst) - 1, -1, -1):
		num = lst[_]
		print(num, end='')
	print()


cases = int(input())
for _ in range(cases):
	n = int(input())
	s = ''
	for i in range(9, -1, -1):
		if 0 <= n <= i:
			s = str(n) + s
			break
		s = str(i) + s
		n -= i
	print(s)


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


T = int(input())
for t in range(0, T):
	s = int(input())
	if len(str(s)) == 1:
		print(s)
	else:
		lst = []
		num = 9
		copy = s
		while copy != 0:
			if copy <= num:
				lst.append(copy)
				copy -= copy
			else:
				lst.append(num)
				copy -= num
				num -= 1
		lst = lst[::-1]
		for item in lst:
			print(item, end='')
		print()


t = int(input())
for i in range(t):
	s = int(input())
	x = 9
	if s < 10:
		print(s)
		continue
	else:
		while s > x:
			s -= x
			x -= 1
	print(s, end='')
	for i in range(x + 1, 10):
		print(i, end='')
	print('')


for s1 in [*map(int, open(0))][1:]:
	rep = ''
	i = 9
	while s1:
		if i <= s1:
			s1 -= i
			rep = str(i) + rep
		i -= 1
	print(rep)


testCases = int(input())
subtractingNumber = 9
numberList = []
stringList = []
finalPrintingList = []
for i in range(testCases):
	sumOfDigits = int(input())
	while sumOfDigits != 0:
		if sumOfDigits - subtractingNumber < 0:
			subtractingNumber = sumOfDigits
			sumOfDigits = 0
		else:
			sumOfDigits = sumOfDigits - subtractingNumber
		numberList.append(subtractingNumber)
		subtractingNumber = subtractingNumber - 1
	for i in range(1, len(numberList) + 1):
		stringList.append(str(numberList[-abs(i)]))
	finalPrintingList.append(int(''.join(stringList)))
	stringList = []
	numberList = []
	subtractingNumber = 9
for i in range(len(finalPrintingList)):
	print(finalPrintingList[i])


for _ in range(int(input())):
	(n, a, s) = (int(input()), 9, [])
	while n > 0:
		s.append(min(n, a))
		n -= min(n, a)
		a -= 1
	print(''.join(map(str, s[::-1])))


t = int(input())
for i in range(t):
	num = int(input())
	numStr = ''
	sum = 0
	for j in range(9, 0, -1):
		sum += j
		if sum == num:
			numStr += str(j)
			break
		elif sum > num:
			sum -= j
		else:
			numStr += str(j)
	numStr = ''.join(reversed(numStr))
	print(numStr)


n = int(input())
for i in range(0, n):
	a = int(input())
	s = ''
	if a <= 9:
		print(a)
	else:
		l = [9, 8, 7, 6, 5, 4, 3, 2, 1]
		I = 0
		while a > 0:
			W = l[I]
			if a < W:
				s = s + str(a)
				break
			else:
				s = s + str(W)
				a = a - W
				I += 1
		for j in range(len(s) - 1, -1, -1):
			print(s[j], end='')
		print()


t = int(input())

def getNrFromList(vals):
	nr = 0
	for val in vals:
		nr = nr * 10 + val
	return nr
for _ in range(t):
	n = int(input())
	if n < 10:
		mini = n
	else:
		mini = float('inf')
		for i in range(1, 10):
			usedDigits = set([i])
			sumDigits = n - i
			notFound = False
			while sumDigits and (not notFound):
				notFound = True
				for j in range(9, 0, -1):
					if j not in usedDigits and j <= sumDigits:
						sumDigits -= j
						usedDigits.add(j)
						notFound = False
						break
			if sumDigits == 0:
				mini = min(getNrFromList(sorted(list(usedDigits))), mini)
	print(mini)


def main():
	curr_sum = int(input())
	i = 0
	curr_val = 9
	ans = 0
	while curr_sum > 0:
		if curr_sum >= curr_val:
			ans += curr_val * 10 ** i
		else:
			ans += curr_sum * 10 ** i
		curr_sum -= curr_val
		i += 1
		curr_val -= 1
	return ans
for _ in range(int(input())):
	print(main())


for _ in range(int(input())):
	s = int(input())
	v = 9
	ans = ''
	while s > 0:
		ans = str(min(s, v)) + ans
		s -= min(s, v)
		v -= 1
	print(ans)


n = int(input())
a = []
for i in range(n):
	a.append(int(input()))

def Xuly(n):
	dem = 9
	s = ''
	while n > 0:
		if n - dem >= 0:
			n = n - dem
			s = str(dem) + s
		dem -= 1
	return s
for i in range(n):
	print(Xuly(a[i]), end='\n')


def answer(value, i, res):
	while value >= 10:
		value += i - 9
		res = [9 - i] + res
		i += 1
	while len(res) != 0 and value >= res[0]:
		value += i - 9
		res = [9 - i] + res
		i += 1
	return [value] + res
for _ in range(int(input())):
	length = int(input())
	res = []
	for i in answer(length, 0, res):
		print(i, end='')
	print('\n', end='')


t = int(input())
for _ in range(t):
	n = int(input())
	ans = 0
	l = [x for x in range(1, 10)][::-1]
	for i in l:
		if n < i:
			ans += n * 10 ** (9 - i)
			break
		else:
			ans += i * 10 ** (9 - i)
		n = n - i
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	if n <= 9:
		print(n)
	elif n <= 17:
		s = str(n - 9)
		s += str(9)
		print(int(s))
	elif n <= 24:
		s = str(n - 17)
		s += str(89)
		print(int(s))
	elif n <= 30:
		s = str(n - 24)
		s += str(789)
		print(int(s))
	elif n <= 35:
		s = str(n - 30)
		s += str(6789)
		print(int(s))
	elif n <= 39:
		s = str(n - 35)
		s += str(56789)
		print(int(s))
	elif n <= 42:
		s = str(n - 39)
		s += str(456789)
		print(int(s))
	elif n <= 44:
		s = str(n - 42)
		s += str(3456789)
		print(int(s))
	else:
		print(123456789)


def solver(s):
	ans = '0'
	counter = 9
	while True:
		if s > sum(map(int, list(ans))):
			if s - sum(map(int, list(ans))) > 9:
				ans = str(counter) + ans
				counter -= 1
			elif s - sum(map(int, list(ans))) > counter:
				ans = str(counter) + ans
				counter -= 1
			else:
				ans = str(s - sum(map(int, list(ans)))) + ans
				return ans[:len(ans) - 1]
		else:
			return ans[:len(ans) - 1]

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


a = [str(j + 1) + ''.join([str(x) for x in range(11 - i, 10)]) for i in range(1, 10) for j in range(10 - i)]
print(*[a[int(input()) - 1] for i in range(int(input()))], sep='\n')


T = int(input())
for _ in range(T):
	n = int(input())
	ss = 0
	result = ''
	cap = 9
	while True:
		if n - ss > cap:
			ss += cap
			result += str(cap)
			cap -= 1
		else:
			result += str(n - ss)
			break
	print(''.join(sorted(result)))


import math
t = int(input())
for t1 in range(t):
	s = int(input())
	s1 = ''
	for i in range(9, 0, -1):
		if s >= i:
			s1 = str(i) + s1
			s = s - i
	print(s1)


n_testcases = int(input())
results = []
while n_testcases > 0:
	max_usable = 9
	to_reach = int(input())
	num = []
	left = to_reach
	while left > 0 and max_usable > 0:
		while max_usable <= left and max_usable > 0:
			num.append(str(max_usable))
			left -= max_usable
			max_usable -= 1
		max_usable -= 1
	num_int = int(''.join(num[::-1]))
	results.append(num_int)
	n_testcases -= 1
for i in range(len(results)):
	print(results[i])


t = int(input())
for _ in range(t):
	s = int(input())
	res = ''
	for i in '987654321':
		if s >= int(i):
			res += i
			s -= int(i)
	print(res[::-1])