Let $f(x)$ be the sum of digits of a decimal number $x$.

Find the smallest non-negative integer $x$ such that $f(x) + f(x + 1) + \dots + f(x + k) = n$.


-----Input-----

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

Each test case consists of one line containing two integers $n$ and $k$ ($1 \le n \le 150$, $0 \le k \le 9$). 


-----Output-----

For each test case, print one integer without leading zeroes. If there is no such $x$ that $f(x) + f(x + 1) + \dots + f(x + k) = n$, print $-1$; otherwise, print the minimum $x$ meeting that constraint.


-----Example-----
Input
7
1 0
1 1
42 7
13 7
99 1
99 0
99 2

Output
1
0
4
-1
599998
99999999999
7997

Source: codeforces | Difficulty: HARD
Tags: Greedy algorithms

Dynamic programming

Complete search

Constructive algorithms


Solutions:
tests = int(input())
INF = 10 ** 20
for test in range(tests):
	(n, w) = map(int, input().split())
	res = INF
	for k in range(17):
		for d in range(10):
			tmp = 0
			for i in range(w + 1):
				if d + i <= 9:
					tmp += 9 * k + d + i
				else:
					tmp += 1 + (d + i) - 10
			if n >= tmp and (n - tmp) % (w + 1) == 0:
				s = (n - tmp) // (w + 1)
				if s <= 8:
					prefix = str(s)
				else:
					prefix = str((s - 8) % 9) + '9' * ((s - 8) // 9) + '8'
				prefix += '9' * k
				prefix += str(d)
				x = int(prefix)
				if sum((sum((int(c) for c in str(x + i))) for i in range(w + 1))) == n:
					res = min(res, x)
	if res == INF:
		res = -1
	print(res)


import sys
sys.setrecursionlimit(10 ** 7)
from collections import defaultdict
con = 10 ** 9 + 7
INF = float('inf')

def main():
	for _ in range(int(input())):
		(N, K) = map(int, input().split())
		ans = INF
		for i in range(100 - K):
			val = 0
			for j in range(i, i + K + 1):
				s = sum(list(map(int, list(str(j)))))
				val += s
			if (N - val) % (K + 1) == 0 and N >= val:
				x = int((N - val) // (K + 1))
				tail = str(x % 9) + str('9') * int(x // 9)
				anspre = int(tail + '0' + str(i)) if i < 10 else int(tail + str(i))
				ans = min(ans, anspre)
		print(-1) if ans == INF else print(ans)
main()


def func(x, d, n, k):
	ans = str(x)
	for i in range(d):
		ans = '9' + ans
	for i in range(k + 1):
		y = (x + i) % 10
		if y >= x:
			n -= d * 9 + y
		else:
			n -= 1 + y
		if n < 0:
			return -1
	if n % (k + 1) != 0:
		return -1
	p = int(n / (k + 1))
	if p >= 8:
		ans = '8' + ans
		n -= (k + 1) * 8
		n = int(n / (k + 1))
		v = int(n / 9)
		for i in range(v):
			ans = '9' + ans
		if n - 9 * v != 0:
			ans = str(n - 9 * v) + ans
	else:
		ans = str(p) + ans
	return int(ans)
t = int(input())
while t:
	t -= 1
	(n, k) = list(map(int, input().split()))
	ans = -1
	for i in range(10):
		for j in range(18):
			res = func(i, j, n, k)
			if res != -1 and ans == -1:
				ans = res
			elif res != -1:
				ans = min(ans, res)
	print(ans)


def digsum(x):
	ret = 0
	while x > 0:
		ret += x % 10
		x //= 10
	return ret
tt = int(input())
for loop in range(tt):
	(n, k) = map(int, input().split())
	ans = float('inf')
	if (n - k * (k + 1) // 2) % (k + 1) == 0:
		X = (n - k * (k + 1) // 2) // (k + 1)
		now = []
		while X > 0:
			if len(now) == 0:
				now.append(min(X, 9 - k))
			else:
				now.append(min(9, X))
			X -= now[-1]
		tmp = 0
		for i in range(len(now)):
			tmp += 10 ** i * now[i]
		ans = min(tmp, ans)
	for t in range(1, k + 1):
		for m in range(1, 50):
			if (n - k * (k + 1) // 2 + 9 * m * (k - t + 1)) % (k + 1) == 0:
				X = (n - k * (k + 1) // 2 + 9 * m * (k - t + 1)) // (k + 1)
				now = []
				Xdown = 10 ** m - t
				while Xdown > 0:
					now.append(Xdown % 10)
					Xdown //= 10
					X -= now[-1]
				if X < 0:
					continue
				fl = True
				while X > 0:
					if fl:
						now.append(min(8, X))
						fl = False
					else:
						now.append(min(9, X))
					X -= now[-1]
				tmp = 0
				for i in range(len(now)):
					tmp += 10 ** i * now[i]
				ans = min(tmp, ans)
	if ans == float('inf'):
		ans = -1
	if ans == 0:
		ntmp = 0
		for j in range(ans, ans + k + 1):
			ntmp += digsum(j)
		if ntmp != n:
			ans = -1
	print(ans)


import sys
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
(t,) = I()
for _ in range(t):
	(n, k) = I()
	if k == 0:
		a = '9' * (n // 9) + (str(n % 9) if n % 9 else '')
		print(a[::-1])
		continue
	mi = (k + 1) * k // 2
	if n < mi:
		print(-1)
	else:
		an = -1
		for i in range(10):
			mi = 0
			for j in range(k + 1):
				mi += sum((int(p) for p in str(i + j)))
			if n < mi or (n - mi) % (k + 1):
				continue
			a = str(i)
			r = (n - mi) // (k + 1)
			if i + k >= 10:
				a += str(min(8, r))
				r -= min(8, r)
			while r:
				a += str(min(9, r))
				r -= min(9, r)
			if an == -1:
				an = int(a[::-1])
			else:
				an = min(an, int(a[::-1]))
		print(an)


ans = [[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1], [-1, 0, -1, -1, -1, -1, -1, -1, -1, -1], [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1], [-1, 1, 0, -1, -1, -1, -1, -1, -1, -1], [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1], [-1, 2, -1, -1, -1, -1, -1, -1, -1, -1], [-1, -1, 1, 0, -1, -1, -1, -1, -1, -1], [-1, 3, -1, -1, -1, -1, -1, -1, -1, -1], [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1], [-1, 4, 2, -1, -1, -1, -1, -1, -1, -1], [-1, 9, -1, 1, 0, -1, -1, -1, -1, -1], [-1, 5, -1, -1, -1, -1, -1, -1, -1, -1], [-1, 19, 3, -1, -1, -1, -1, -1, -1, -1], [-1, 6, -1, -1, -1, -1, -1, -1, -1, -1], [-1, 29, -1, 2, -1, -1, -1, -1, -1, -1], [-1, 7, 4, 9, 1, 0, -1, -1, -1, -1], [-1, 39, -1, -1, -1, -1, -1, -1, -1, -1], [-1, 8, -1, -1, -1, -1, -1, -1, -1, -1], [-1, 49, 5, 3, -1, -1, -1, -1, -1, -1], [-1, 18, -1, 19, 9, -1, -1, -1, -1, -1], [-1, 59, -1, 8, 2, -1, -1, -1, -1, -1], [-1, 28, 6, -1, -1, 1, 0, -1, -1, -1], [-1, 69, -1, 4, -1, -1, -1, -1, -1, -1], [-1, 38, -1, 29, 8, -1, -1, -1, -1, -1], [-1, 79, 7, 18, 19, 9, -1, -1, -1, -1], [-1, 48, -1, 7, 3, -1, -1, -1, -1, -1], [-1, 89, -1, 5, -1, -1, -1, -1, -1, -1], [-1, 58, 17, 39, 7, 2, -1, -1, -1, -1], [-1, 189, -1, 28, 18, -1, 1, 0, -1, -1], [-1, 68, -1, 17, 29, -1, -1, -1, -1, -1], [-1, 289, 27, 6, 4, 7, 9, -1, -1, -1], [-1, 78, -1, 49, 6, -1, -1, -1, -1, -1], [-1, 389, -1, 38, 17, -1, 8, -1, -1, -1], [-1, 88, 37, 27, 28, 3, -1, -1, -1, -1], [-1, 489, -1, 16, 39, -1, 7, -1, -1, -1], [-1, 98, -1, 59, 5, -1, 2, -1, -1, -1], [-1, 589, 47, 48, 16, 5, 6, 1, 0, -1], [-1, 198, -1, 37, 27, -1, 19, 9, -1, -1], [-1, 689, -1, 26, 38, -1, 5, 8, -1, -1], [-1, 298, 57, 69, 49, 4, 18, 7, -1, -1], [-1, 789, -1, 58, 15, -1, 4, 6, -1, -1], [-1, 398, -1, 47, 26, -1, 17, 5, -1, -1], [-1, 889, 67, 36, 37, 15, 3, 4, -1, -1], [-1, 498, -1, 79, 48, -1, 16, 3, -1, -1], [-1, 989, -1, 68, 59, -1, 29, 2, -1, -1], [-1, 598, 77, 57, 25, 14, 15, 19, 1, 0], [-1, 1989, -1, 46, 36, -1, 28, 18, -1, 1], [-1, 698, -1, 89, 47, -1, 14, 17, -1, 2], [-1, 2989, 87, 78, 58, 25, 27, 16, -1, 3], [-1, 798, -1, 67, 69, -1, 13, 15, -1, 4], [-1, 3989, -1, 56, 35, -1, 26, 14, -1, 5], [-1, 898, 97, 189, 46, 24, 39, 13, -1, 6], [-1, 4989, -1, 88, 57, -1, 25, 12, -1, 7], [-1, 998, -1, 77, 68, -1, 38, 29, -1, 8], [-1, 5989, 197, 66, 79, 35, 24, 28, 11, 9], [-1, 1998, -1, 289, 45, -1, 37, 27, -1, 10], [-1, 6989, -1, 188, 56, -1, 23, 26, -1, 11], [-1, 2998, 297, 87, 67, 34, 36, 25, -1, 12], [-1, 7989, -1, 76, 78, -1, 49, 24, -1, 13], [-1, 3998, -1, 389, 89, -1, 35, 23, -1, 14], [-1, 8989, 397, 288, 55, 45, 48, 22, -1, 15], [-1, 4998, -1, 187, 66, -1, 34, 39, -1, 16], [-1, 9989, -1, 86, 77, -1, 47, 38, -1, 17], [-1, 5998, 497, 489, 88, 44, 33, 37, 21, 18], [-1, 19989, -1, 388, 189, -1, 46, 36, -1, 19], [-1, 6998, -1, 287, 65, -1, 59, 35, -1, 20], [-1, 29989, 597, 96, 76, 55, 45, 34, -1, 21], [-1, 7998, -1, 589, 87, -1, 58, 33, -1, 22], [-1, 39989, -1, 488, 188, -1, 44, 32, -1, 23], [-1, 8998, 697, 387, 289, 54, 57, 49, -1, 24], [-1, 49989, -1, 196, 75, -1, 43, 48, -1, 25], [-1, 9998, -1, 689, 86, -1, 56, 47, -1, 26], [-1, 59989, 797, 588, 187, 65, 69, 46, 31, 27], [-1, 19998, -1, 487, 288, -1, 55, 45, -1, 28], [-1, 69989, -1, 296, 389, -1, 68, 44, -1, 29], [-1, 29998, 897, 789, 85, 64, 54, 43, -1, 30], [-1, 79989, -1, 688, 186, -1, 67, 42, -1, 31], [-1, 39998, -1, 587, 287, -1, 53, 59, -1, 32], [-1, 89989, 997, 396, 388, 75, 66, 58, -1, 33], [-1, 49998, -1, 889, 489, -1, 79, 57, -1, 34], [-1, 99989, -1, 788, 95, -1, 65, 56, -1, 35], [-1, 59998, 1997, 687, 286, 74, 78, 55, 41, 36], [-1, 199989, -1, 496, 387, -1, 64, 54, -1, 37], [-1, 69998, -1, 989, 488, -1, 77, 53, -1, 38], [-1, 299989, 2997, 888, 589, 85, 63, 52, -1, 39], [-1, 79998, -1, 787, 195, -1, 76, 69, -1, 40], [-1, 399989, -1, 596, 386, -1, 89, 68, -1, 41], [-1, 89998, 3997, 1989, 487, 84, 75, 67, -1, 42], [-1, 499989, -1, 988, 588, -1, 88, 66, -1, 43], [-1, 99998, -1, 887, 689, -1, 74, 65, -1, 44], [-1, 599989, 4997, 696, 295, 185, 87, 64, 51, 45], [-1, 199998, -1, 2989, 486, -1, 73, 63, -1, 46], [-1, 699989, -1, 1988, 587, -1, 86, 62, -1, 47], [-1, 299998, 5997, 987, 688, 94, 189, 79, -1, 48], [-1, 799989, -1, 796, 789, -1, 85, 78, -1, 49], [-1, 399998, -1, 3989, 395, -1, 188, 77, -1, 50], [-1, 899989, 6997, 2988, 586, 285, 84, 76, -1, 51], [-1, 499998, -1, 1987, 687, -1, 187, 75, -1, 52], [-1, -1, -1, 896, 788, -1, 83, 74, -1, 53], [-1, 599998, 7997, 4989, 889, 194, 186, 73, 61, 54], [-1, -1, -1, 3988, 495, -1, 289, 72, -1, 55], [-1, 699998, -1, 2987, 686, -1, 185, 89, -1, 56], [-1, -1, 8997, 996, 787, 385, 288, 88, -1, 57], [-1, 799998, -1, 5989, 888, -1, 184, 87, -1, 58], [-1, -1, -1, 4988, 989, -1, 287, 86, -1, 59], [-1, 899998, 9997, 3987, 595, 294, 93, 85, -1, 60], [-1, -1, -1, 1996, 786, -1, 286, 84, -1, 61], [-1, -1, -1, 6989, 887, -1, 389, 83, -1, 62], [-1, -1, 19997, 5988, 988, 485, 285, 82, 71, 63], [-1, -1, -1, 4987, 1989, -1, 388, 189, -1, 64], [-1, -1, -1, 2996, 695, -1, 284, 188, -1, 65], [-1, -1, 29997, 7989, 886, 394, 387, 187, -1, 66], [-1, -1, -1, 6988, 987, -1, 193, 186, -1, 67], [-1, -1, -1, 5987, 1988, -1, 386, 185, -1, 68], [-1, -1, 39997, 3996, 2989, 585, 489, 184, -1, 69], [-1, -1, -1, 8989, 795, -1, 385, 183, -1, 70], [-1, -1, -1, 7988, 986, -1, 488, 92, -1, 71], [-1, -1, 49997, 6987, 1987, 494, 384, 289, 81, 72], [-1, -1, -1, 4996, 2988, -1, 487, 288, -1, 73], [-1, -1, -1, 9989, 3989, -1, 293, 287, -1, 74], [-1, -1, 59997, 8988, 895, 685, 486, 286, -1, 75], [-1, -1, -1, 7987, 1986, -1, 589, 285, -1, 76], [-1, -1, -1, 5996, 2987, -1, 485, 284, -1, 77], [-1, -1, 69997, 19989, 3988, 594, 588, 283, -1, 78], [-1, -1, -1, 9988, 4989, -1, 484, 192, -1, 79], [-1, -1, -1, 8987, 995, -1, 587, 389, -1, 80], [-1, -1, 79997, 6996, 2986, 785, 393, 388, 91, 81], [-1, -1, -1, 29989, 3987, -1, 586, 387, -1, 82], [-1, -1, -1, 19988, 4988, -1, 689, 386, -1, 83], [-1, -1, 89997, 9987, 5989, 694, 585, 385, -1, 84], [-1, -1, -1, 7996, 1995, -1, 688, 384, -1, 85], [-1, -1, -1, 39989, 3986, -1, 584, 383, -1, 86], [-1, -1, 99997, 29988, 4987, 885, 687, 292, -1, 87], [-1, -1, -1, 19987, 5988, -1, 493, 489, -1, 88], [-1, -1, -1, 8996, 6989, -1, 686, 488, -1, 89], [-1, -1, 199997, 49989, 2995, 794, 789, 487, 191, 90], [-1, -1, -1, 39988, 4986, -1, 685, 486, -1, 181], [-1, -1, -1, 29987, 5987, -1, 788, 485, -1, 182], [-1, -1, 299997, 9996, 6988, 985, 684, 484, -1, 183], [-1, -1, -1, 59989, 7989, -1, 787, 483, -1, 184], [-1, -1, -1, 49988, 3995, -1, 593, 392, -1, 185], [-1, -1, 399997, 39987, 5986, 894, 786, 589, -1, 186], [-1, -1, -1, 19996, 6987, -1, 889, 588, -1, 187], [-1, -1, -1, 69989, 7988, -1, 785, 587, -1, 188], [-1, -1, 499997, 59988, 8989, 1985, 888, 586, 291, 189], [-1, -1, -1, 49987, 4995, -1, 784, 585, -1, 190], [-1, -1, -1, 29996, 6986, -1, 887, 584, -1, 281], [-1, -1, 599997, 79989, 7987, 994, 693, 583, -1, 282], [-1, -1, -1, 69988, 8988, -1, 886, 492, -1, 283], [-1, -1, -1, 59987, 9989, -1, 989, 689, -1, 284], [-1, -1, 699997, 39996, 5995, 2985, 885, 688, -1, 285]]
ans[98][1] = 999989
ans[100][1] = 1999989
ans[102][1] = 2999989
ans[104][1] = 3999989
ans[106][1] = 4999989
ans[108][1] = 5999989
ans[110][1] = 6999989
ans[112][1] = 7999989
ans[114][1] = 8999989
ans[116][1] = 9999989
ans[118][1] = 19999989
ans[120][1] = 29999989
ans[122][1] = 39999989
ans[124][1] = 49999989
ans[126][1] = 59999989
ans[128][1] = 69999989
ans[130][1] = 79999989
ans[132][1] = 89999989
ans[134][1] = 99999989
ans[136][1] = 199999989
ans[138][1] = 299999989
ans[140][1] = 399999989
ans[142][1] = 499999989
ans[144][1] = 599999989
ans[146][1] = 699999989
ans[148][1] = 799999989
ans[150][1] = 899999989
ans[107][1] = 999998
ans[109][1] = 1999998
ans[111][1] = 2999998
ans[113][1] = 3999998
ans[115][1] = 4999998
ans[117][1] = 5999998
ans[119][1] = 6999998
ans[121][1] = 7999998
ans[123][1] = 8999998
ans[125][1] = 9999998
ans[127][1] = 19999998
ans[129][1] = 29999998
ans[131][1] = 39999998
ans[133][1] = 49999998
ans[135][1] = 59999998
ans[137][1] = 69999998
ans[139][1] = 79999998
ans[141][1] = 89999998
ans[143][1] = 99999998
ans[145][1] = 199999998
ans[147][1] = 299999998
ans[149][1] = 399999998

def get(n):
	a = []
	while n >= 9:
		a += [9]
		n -= 9
	if n != 0:
		a += [n]
	a = sorted(a)
	return a
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if k == 0:
		g = get(n)
		print(''.join((str(k) for k in g)))
		continue
	else:
		print(ans[n][k])


from sys import stdout
from io import BytesIO, IOBase
from bisect import bisect_right, bisect_left
mod = 998244353
import os
import sys
from io import BytesIO, IOBase
import threading
from math import floor
from bisect import bisect_right
from collections import Counter
from math import gcd
from random import randint
mod = 10 ** 9 + 7

def num(pref):
	if pref == 0:
		return str()
	if pref < 9:
		return str(pref)
	else:
		ans = [8]
		pref -= 8
		while pref > 9:
			ans.append(9)
			pref -= 9
		if pref > 0:
			ans.append(pref)
		ans.reverse()
		return ''.join([str(i) for i in ans])

def comp(a, b):
	if len(a) != len(b):
		return len(a) < len(b)
	else:
		for i in range(len(a)):
			if int(a[i]) < int(b[i]):
				return True
			elif int(a[i]) > int(b[i]):
				return False

def main():
	for _ in range(int(input())):
		(n, k) = map(int, input().split())
		b = True
		ar = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7]
		ans = '1' * n
		for dig in range(10):
			for n_9 in range(17):
				t1 = min(10 - dig, k + 1)
				t = n - sum(ar[dig:dig + k + 1]) - 9 * n_9 * t1 - k - 1 + t1
				if t >= 0 and t % (k + 1) == 0:
					pref = t // (k + 1)
					t_ans = num(pref) + '9' * n_9 + str(dig)
					if comp(t_ans, ans):
						ans = t_ans
					b = False
		if b:
			print(-1)
		else:
			print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import queue
import math
t = int(input())

def s(a, b):
	ans = 0
	for i in range(a, b + 1):
		ans += i
	return ans

def smallest(x):
	ans = 0
	p = 1
	while x >= 9:
		ans = ans + 9 * p
		p *= 10
		x -= 9
	ans = ans + x * p
	return ans
while t:
	line = input().split()
	(n, k) = (int(line[0]), int(line[1]))
	ans = 1e+20
	for i in range(10):
		if i + k < 10:
			N = n - s(i, i + k)
			if N >= 0 and N % (k + 1) == 0:
				N //= k + 1
				ans = min(ans, smallest(N) * 10 + i)
		else:
			a = s(i, 9)
			b = s(0, i + k - 10)
			p = 10
			for d in range(0, 17):
				N = n - a - b - 9 * d * (10 - i) - (i + k - 9)
				if N >= 0 and N % (k + 1) == 0:
					N //= k + 1
					dig = min(N, 8)
					N -= dig
					tmp = i + (p // 10 - 1) * 10 + dig * p + smallest(N) * p * 10
					ans = min(ans, tmp)
				p *= 10
	if ans == 1e+20:
		print(-1)
	else:
		print(ans)
	t -= 1


def f(x):
	ret = 0
	while x:
		ret += x % 10
		x //= 10
	return ret

def d(x, k):
	ret = 0
	for i in range(k + 1):
		ret += f(x + i)
	return ret
t = int(input())
while t:
	t -= 1
	(n, k) = map(int, input().split())
	fl = False
	s = 0
	ans = '-1'
	for j in range(30):
		s = 0
		for f3 in range(j):
			if d(s, k) > n:
				continue
			s *= 10
			s += 9
		if d(s, k) > n:
			continue
		for i in range(10):
			h = s
			s *= 10
			s += i
			if d(s, k) > n:
				s = h
				continue
			jj = d(s, k)
			if jj == n or (jj <= n and (not (n - jj) % (k + 1))):
				ans1 = str(s)
				if jj != n:
					yy = (n - jj) // (k + 1)
					ggg = ''
					x = 0
					while yy:
						if yy > 9:
							if not x:
								ggg = '8' + ggg
								yy -= 8
							else:
								ggg = '9' + ggg
								yy -= 9
						else:
							uu = yy
							if not x:
								uu = min(uu, 8)
							ggg = chr(uu + ord('0')) + ggg
							yy -= uu
						x += 1
					if d(int(ggg + ans1), k) == n:
						ans1 = ggg + ans1
					else:
						ans1 = ggg + '0' + ans1
				if ans == '-1' or int(ans) > int(ans1):
					ans = ans1
			s = h
	print(ans)


import collections
import time
import os
import sys
import bisect
import heapq
from typing import List

def check(n, s, t, k):
	sm = 0
	for i in range(s, min(s + k + 1, 10)):
		sm += 9 * n + i
	if s + k > 9:
		for i in range((s + k) % 10 + 1):
			sm += 1 + i
	d = t - sm
	if d < 0:
		return (False, -1)
	k += 1
	if d % k == 0:
		d //= k
		prefix = ''
		pv = 8
		while d > 0:
			c = min(d, pv)
			prefix += str(c)
			d -= c
			pv = 9
		return (True, int(prefix[::-1] + '9' * n + str(s)))
	return (False, -1)

def solve(N, K):
	ans = float('inf')
	for i in range(N // 9 + 1):
		for s in range(10):
			(c, v) = check(i, s, N, K)
			if c:
				ans = min(ans, v)
	return ans if ans < float('inf') else -1
T = int(input())
for ti in range(T):
	(N, K) = map(int, input().split())
	print(solve(N, K))


def generate_prefix(su):
	pre = ''
	if su >= 8:
		pre += '8'
		su -= 8
	if len(pre) > 0:
		nu = 9
	else:
		nu = 8
	while su > 0:
		while su >= nu:
			su -= nu
			pre += str(nu)
		nu -= 1
	pre = pre[::-1]
	return pre

def get_number(su, nines, d, k):
	last_digit_sum = 0
	with_zeros = 0
	with_nines = 0
	for i in range(k + 1):
		if d + i < 10:
			last_digit_sum += d + i
			with_nines += 1
		else:
			last_digit_sum += (d + i) % 10
			with_zeros += 1
	su -= with_zeros + last_digit_sum + nines * 9 * with_nines
	if su < 0 or su % (k + 1) != 0:
		return ''
	su //= k + 1
	prefix = generate_prefix(su)
	if prefix == '0':
		prefix = ''
	ret = prefix + '9' * nines + str(d)
	return ret
for _ in range(int(input())):
	(su, k) = map(int, input().split())
	fans = 1e+20
	for d in range(10):
		for nines in range(0, 64):
			this_ans = get_number(su, nines, d, k)
			if this_ans == '':
				continue
			elif int(this_ans) < int(fans):
				fans = this_ans
	if fans == 1e+20:
		print(-1)
	else:
		print(fans)


from math import *
from collections import *
from bisect import *
import sys
input = sys.stdin.readline
t = int(input())

def call(n):
	pre = ''
	if n <= 8:
		return str(n)
	pre = '8'
	n -= 8
	pre += n // 9 * '9' + str(n % 9)
	return min(int(pre), int(pre[::-1]))
while t:
	t -= 1
	(n, k) = map(int, input().split())
	res = float('inf')
	for i in range(17):
		for j in range(10):
			need = min(k + 1, 10 - j)
			num = n - 9 * i * need
			num += need - (k + 1)
			for k1 in range(k + 1):
				num -= (j + k1) % 10
			if num >= 0 and num % (k + 1) == 0:
				z = int(str(call(num // (k + 1))) + '9' * i + str(j))
				res = min(res, z)
	if res == float('inf'):
		print(-1)
	else:
		print(res)


mat = [[0] * 10 for i in range(10)]

def val(n):
	r = 0
	while n:
		(r, n) = (r + n % 10, n // 10)
	return r
for k in range(10):
	for s in range(10):
		mat[s % 10][k] = sum([val(n) for n in range(s, s + k + 1)])

def get_k(k):
	return [m[k] for m in mat]

def get_value(n, k, acc=0):
	n_n = n + 1
	r = 0
	while n:
		(r, n) = (r + n % 10, n // 10)
	if k <= 0:
		return acc + r
	return get_value(n_n, k - 1, acc + r)
t = int(input())
for _ in range(t):
	data = input().split(' ')
	n = int(data[0])
	k = int(data[1])
	results = []
	for (index, i) in enumerate(get_k(k)):
		if i > n:
			continue
		rest = n - i
		rest = rest / (k + 1)
		nn = []
		if rest - 8 >= 0 and k > 9 - index:
			nn.append(8)
			rest -= 8
		while rest - 9 >= 0:
			nn.append(9)
			rest -= 9
		x = int(str(int(rest)) + ''.join([str(n_) for n_ in nn[::-1]]) + str(index))
		val = get_value(int(x), k)
		if val == n:
			results.append(x)
	if len(results) == 0:
		print(-1)
	else:
		print(min(results))


def construct(fx, d, i):
	s = '9' * (i - 1) + str(d)
	fx -= d + 9 * (i - 1)
	if fx < 0:
		return 2 ** 63 - 1
	if fx >= 8:
		s = '8' + s
		fx -= 8
	else:
		s = str(fx) + s
		fx = 0
	while fx:
		if fx >= 9:
			s = '9' + s
			fx -= 9
		else:
			s = str(fx) + s
			fx = 0
	return int(s)
for T in range(int(input())):
	(n, k) = (int(x) for x in input().split())
	ans = 2 ** 63 - 1
	for d in range(10):
		for i in range(1, 21):
			temp = n + 9 * i * max(0, k - 9 + d) - k * (k + 1) // 2
			if temp < 0 or temp % (k + 1):
				continue
			temp //= k + 1
			s = construct(temp, d, i)
			ans = min(ans, s)
	print(ans if ans != 2 ** 63 - 1 else -1)


for _ in range(int(input())):
	(N, K) = map(int, input().split())
	ans = float('inf')
	for i in range(100 - K):
		val = 0
		for j in range(i, i + K + 1):
			val += sum(list(map(int, list(str(j)))))
		if (N - val) % (K + 1) == 0 and N >= val:
			x = int((N - val) // (K + 1))
			tail = str(x % 9) + str('9') * int(x // 9)
			if i < 10:
				ans = min(ans, int(tail + '0' + str(i)))
			else:
				ans = min(ans, int(tail + str(i)))
	print(-1) if ans == float('inf') else print(ans)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	ans = float('INF')
	for w in range(17):
		for d in range(10):
			count = 0
			for i in range(k + 1):
				if d + i <= 9:
					count += 9 * w + d + i
				else:
					count += 1 + (d + i) - 10
			if n >= count and (n - count) % (k + 1) == 0:
				s = (n - count) // (k + 1)
				if s <= 8:
					c = str(s)
				else:
					c = str((s - 8) % 9) + '9' * ((s - 8) // 9) + '8'
				c += '9' * w
				c += str(d)
				x = int(c)
				ans = min(ans, x)
	print(-1 if ans == float('INF') else ans)


a = [[1, 0, -1, -1, -1, -1, -1, -1, -1, -1], [2, -1, -1, -1, -1, -1, -1, -1, -1, -1], [3, 1, 0, -1, -1, -1, -1, -1, -1, -1], [4, -1, -1, -1, -1, -1, -1, -1, -1, -1], [5, 2, -1, -1, -1, -1, -1, -1, -1, -1], [6, -1, 1, 0, -1, -1, -1, -1, -1, -1], [7, 3, -1, -1, -1, -1, -1, -1, -1, -1], [8, -1, -1, -1, -1, -1, -1, -1, -1, -1], [9, 4, 2, -1, -1, -1, -1, -1, -1, -1], [19, 9, -1, 1, 0, -1, -1, -1, -1, -1], [29, 5, -1, -1, -1, -1, -1, -1, -1, -1], [39, 19, 3, -1, -1, -1, -1, -1, -1, -1], [49, 6, -1, -1, -1, -1, -1, -1, -1, -1], [59, 29, -1, 2, -1, -1, -1, -1, -1, -1], [69, 7, 4, 9, 1, 0, -1, -1, -1, -1], [79, 39, -1, -1, -1, -1, -1, -1, -1, -1], [89, 8, -1, -1, -1, -1, -1, -1, -1, -1], [99, 49, 5, 3, -1, -1, -1, -1, -1, -1], [199, 18, -1, 19, 9, -1, -1, -1, -1, -1], [299, 59, -1, 8, 2, -1, -1, -1, -1, -1], [399, 28, 6, -1, -1, 1, 0, -1, -1, -1], [499, 69, -1, 4, -1, -1, -1, -1, -1, -1], [599, 38, -1, 29, 8, -1, -1, -1, -1, -1], [699, 79, 7, 18, 19, 9, -1, -1, -1, -1], [799, 48, -1, 7, 3, -1, -1, -1, -1, -1], [899, 89, -1, 5, -1, -1, -1, -1, -1, -1], [999, 58, 17, 39, 7, 2, -1, -1, -1, -1], [1999, 189, -1, 28, 18, -1, 1, 0, -1, -1], [2999, 68, -1, 17, 29, -1, -1, -1, -1, -1], [3999, 289, 27, 6, 4, 7, 9, -1, -1, -1], [4999, 78, -1, 49, 6, -1, -1, -1, -1, -1], [5999, 389, -1, 38, 17, -1, 8, -1, -1, -1], [6999, 88, 37, 27, 28, 3, -1, -1, -1, -1], [7999, 489, -1, 16, 39, -1, 7, -1, -1, -1], [8999, 98, -1, 59, 5, -1, 2, -1, -1, -1], [9999, 589, 47, 48, 16, 5, 6, 1, 0, -1], [19999, 198, -1, 37, 27, -1, 19, 9, -1, -1], [29999, 689, -1, 26, 38, -1, 5, 8, -1, -1], [39999, 298, 57, 69, 49, 4, 18, 7, -1, -1], [49999, 789, -1, 58, 15, -1, 4, 6, -1, -1], [59999, 398, -1, 47, 26, -1, 17, 5, -1, -1], [69999, 889, 67, 36, 37, 15, 3, 4, -1, -1], [79999, 498, -1, 79, 48, -1, 16, 3, -1, -1], [89999, 989, -1, 68, 59, -1, 29, 2, -1, -1], [99999, 598, 77, 57, 25, 14, 15, 19, 1, 0], [199999, 1989, -1, 46, 36, -1, 28, 18, -1, 1], [299999, 698, -1, 89, 47, -1, 14, 17, -1, 2], [399999, 2989, 87, 78, 58, 25, 27, 16, -1, 3], [499999, 798, -1, 67, 69, -1, 13, 15, -1, 4], [599999, 3989, -1, 56, 35, -1, 26, 14, -1, 5], [699999, 898, 97, 189, 46, 24, 39, 13, -1, 6], [799999, 4989, -1, 88, 57, -1, 25, 12, -1, 7], [899999, 998, -1, 77, 68, -1, 38, 29, -1, 8], [999999, 5989, 197, 66, 79, 35, 24, 28, 11, 9], [1999999, 1998, -1, 289, 45, -1, 37, 27, -1, 10], [2999999, 6989, -1, 188, 56, -1, 23, 26, -1, 11], [3999999, 2998, 297, 87, 67, 34, 36, 25, -1, 12], [4999999, 7989, -1, 76, 78, -1, 49, 24, -1, 13], [5999999, 3998, -1, 389, 89, -1, 35, 23, -1, 14], [6999999, 8989, 397, 288, 55, 45, 48, 22, -1, 15], [7999999, 4998, -1, 187, 66, -1, 34, 39, -1, 16], [8999999, 9989, -1, 86, 77, -1, 47, 38, -1, 17], [9999999, 5998, 497, 489, 88, 44, 33, 37, 21, 18], [19999999, 19989, -1, 388, 189, -1, 46, 36, -1, 19], [29999999, 6998, -1, 287, 65, -1, 59, 35, -1, 20], [39999999, 29989, 597, 96, 76, 55, 45, 34, -1, 21], [49999999, 7998, -1, 589, 87, -1, 58, 33, -1, 22], [59999999, 39989, -1, 488, 188, -1, 44, 32, -1, 23], [69999999, 8998, 697, 387, 289, 54, 57, 49, -1, 24], [79999999, 49989, -1, 196, 75, -1, 43, 48, -1, 25], [89999999, 9998, -1, 689, 86, -1, 56, 47, -1, 26], [99999999, 59989, 797, 588, 187, 65, 69, 46, 31, 27], [199999999, 19998, -1, 487, 288, -1, 55, 45, -1, 28], [299999999, 69989, -1, 296, 389, -1, 68, 44, -1, 29], [399999999, 29998, 897, 789, 85, 64, 54, 43, -1, 30], [499999999, 79989, -1, 688, 186, -1, 67, 42, -1, 31], [599999999, 39998, -1, 587, 287, -1, 53, 59, -1, 32], [699999999, 89989, 997, 396, 388, 75, 66, 58, -1, 33], [799999999, 49998, -1, 889, 489, -1, 79, 57, -1, 34], [899999999, 99989, -1, 788, 95, -1, 65, 56, -1, 35], [999999999, 59998, 1997, 687, 286, 74, 78, 55, 41, 36], [1999999999, 199989, -1, 496, 387, -1, 64, 54, -1, 37], [2999999999, 69998, -1, 989, 488, -1, 77, 53, -1, 38], [3999999999, 299989, 2997, 888, 589, 85, 63, 52, -1, 39], [4999999999, 79998, -1, 787, 195, -1, 76, 69, -1, 40], [5999999999, 399989, -1, 596, 386, -1, 89, 68, -1, 41], [6999999999, 89998, 3997, 1989, 487, 84, 75, 67, -1, 42], [7999999999, 499989, -1, 988, 588, -1, 88, 66, -1, 43], [8999999999, 99998, -1, 887, 689, -1, 74, 65, -1, 44], [9999999999, 599989, 4997, 696, 295, 185, 87, 64, 51, 45], [19999999999, 199998, -1, 2989, 486, -1, 73, 63, -1, 46], [29999999999, 699989, -1, 1988, 587, -1, 86, 62, -1, 47], [39999999999, 299998, 5997, 987, 688, 94, 189, 79, -1, 48], [49999999999, 799989, -1, 796, 789, -1, 85, 78, -1, 49], [59999999999, 399998, -1, 3989, 395, -1, 188, 77, -1, 50], [69999999999, 899989, 6997, 2988, 586, 285, 84, 76, -1, 51], [79999999999, 499998, -1, 1987, 687, -1, 187, 75, -1, 52], [89999999999, 999989, -1, 896, 788, -1, 83, 74, -1, 53], [99999999999, 599998, 7997, 4989, 889, 194, 186, 73, 61, 54], [199999999999, 1999989, -1, 3988, 495, -1, 289, 72, -1, 55], [299999999999, 699998, -1, 2987, 686, -1, 185, 89, -1, 56], [399999999999, 2999989, 8997, 996, 787, 385, 288, 88, -1, 57], [499999999999, 799998, -1, 5989, 888, -1, 184, 87, -1, 58], [599999999999, 3999989, -1, 4988, 989, -1, 287, 86, -1, 59], [699999999999, 899998, 9997, 3987, 595, 294, 93, 85, -1, 60], [799999999999, 4999989, -1, 1996, 786, -1, 286, 84, -1, 61], [899999999999, 999998, -1, 6989, 887, -1, 389, 83, -1, 62], [999999999999, 5999989, 19997, 5988, 988, 485, 285, 82, 71, 63], [1999999999999, 1999998, -1, 4987, 1989, -1, 388, 189, -1, 64], [2999999999999, 6999989, -1, 2996, 695, -1, 284, 188, -1, 65], [3999999999999, 2999998, 29997, 7989, 886, 394, 387, 187, -1, 66], [4999999999999, 7999989, -1, 6988, 987, -1, 193, 186, -1, 67], [5999999999999, 3999998, -1, 5987, 1988, -1, 386, 185, -1, 68], [6999999999999, 8999989, 39997, 3996, 2989, 585, 489, 184, -1, 69], [7999999999999, 4999998, -1, 8989, 795, -1, 385, 183, -1, 70], [8999999999999, 9999989, -1, 7988, 986, -1, 488, 92, -1, 71], [9999999999999, 5999998, 49997, 6987, 1987, 494, 384, 289, 81, 72], [19999999999999, 19999989, -1, 4996, 2988, -1, 487, 288, -1, 73], [29999999999999, 6999998, -1, 9989, 3989, -1, 293, 287, -1, 74], [39999999999999, 29999989, 59997, 8988, 895, 685, 486, 286, -1, 75], [49999999999999, 7999998, -1, 7987, 1986, -1, 589, 285, -1, 76], [59999999999999, 39999989, -1, 5996, 2987, -1, 485, 284, -1, 77], [69999999999999, 8999998, 69997, 19989, 3988, 594, 588, 283, -1, 78], [79999999999999, 49999989, -1, 9988, 4989, -1, 484, 192, -1, 79], [89999999999999, 9999998, -1, 8987, 995, -1, 587, 389, -1, 80], [99999999999999, 59999989, 79997, 6996, 2986, 785, 393, 388, 91, 81], [199999999999999, 19999998, -1, 29989, 3987, -1, 586, 387, -1, 82], [299999999999999, 69999989, -1, 19988, 4988, -1, 689, 386, -1, 83], [399999999999999, 29999998, 89997, 9987, 5989, 694, 585, 385, -1, 84], [499999999999999, 79999989, -1, 7996, 1995, -1, 688, 384, -1, 85], [599999999999999, 39999998, -1, 39989, 3986, -1, 584, 383, -1, 86], [699999999999999, 89999989, 99997, 29988, 4987, 885, 687, 292, -1, 87], [799999999999999, 49999998, -1, 19987, 5988, -1, 493, 489, -1, 88], [899999999999999, 99999989, -1, 8996, 6989, -1, 686, 488, -1, 89], [999999999999999, 59999998, 199997, 49989, 2995, 794, 789, 487, 191, 90], [1999999999999999, 199999989, -1, 39988, 4986, -1, 685, 486, -1, 181], [2999999999999999, 69999998, -1, 29987, 5987, -1, 788, 485, -1, 182], [3999999999999999, 299999989, 299997, 9996, 6988, 985, 684, 484, -1, 183], [4999999999999999, 79999998, -1, 59989, 7989, -1, 787, 483, -1, 184], [5999999999999999, 399999989, -1, 49988, 3995, -1, 593, 392, -1, 185], [6999999999999999, 89999998, 399997, 39987, 5986, 894, 786, 589, -1, 186], [7999999999999999, 499999989, -1, 19996, 6987, -1, 889, 588, -1, 187], [8999999999999999, 99999998, -1, 69989, 7988, -1, 785, 587, -1, 188], [9999999999999999, 599999989, 499997, 59988, 8989, 1985, 888, 586, 291, 189], [19999999999999999, 199999998, -1, 49987, 4995, -1, 784, 585, -1, 190], [29999999999999999, 699999989, -1, 29996, 6986, -1, 887, 584, -1, 281], [39999999999999999, 299999998, 599997, 79989, 7987, 994, 693, 583, -1, 282], [49999999999999999, 799999989, -1, 69988, 8988, -1, 886, 492, -1, 283], [59999999999999999, 399999998, -1, 59987, 9989, -1, 989, 689, -1, 284], [69999999999999999, 899999989, 699997, 39996, 5995, 2985, 885, 688, -1, 285]]
t = int(input())
for tt in range(t):
	(n, k) = [int(x) for x in input().split(' ')]
	print(a[n - 1][k])


m = []
for k in range(10):
	t = []
	for i in range(10):
		a = 0
		for j in range(k + 1):
			a += (i + j) % 10 + (i + j) // 10
		t.append(a)
	m.append(t)
for _ in range(int(input())):
	(n, k) = [int(x) for x in input().split()]
	l = m[k]
	ans = []
	for i in range(10):
		if n - l[i] < 0 or (n - l[i]) % (k + 1):
			continue
		p = (n - l[i]) // (k + 1)
		if p // 9 > 0 and i + k > 9:
			a = int(str(p % 9 + 1) + '9' * (p // 9 - 1) + '8')
		elif p // 9 > 0:
			a = int(str(p % 9) + '9' * (p // 9))
		else:
			a = p % 9
		ans.append(10 * a + i)
	if len(ans) == 0:
		print(-1)
		continue
	print(min(ans))


import os
import sys
debug = True
if debug and os.path.exists('input.in'):
	input = open('input.in', 'r').readline
else:
	debug = False
	input = sys.stdin.readline

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

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return s[:len(s) - 1]

def invr():
	return map(int, input().split())
test_count = int(input())
for t in range(test_count):
	if debug:
		print('Test Case #', t + 1)
	(n, k) = invr()
	totals = {}
	min_ans = -1
	for i in range(10):
		sum_x = 0
		digit_sum = -1
		last_digit = -1
		for j in range(0, k + 1):
			if i + j < 10:
				sum_x += i + j
			else:
				sum_x += (i + j) // 10 + (i + j) % 10
		if sum_x <= n and (n - sum_x) % (k + 1) == 0:
			digit_sum = (n - sum_x) // (k + 1)
			last_digit = i
			ans = ''
			if last_digit + k > 9 and digit_sum >= 9:
				ans += '8'
				digit_sum -= 8
			while digit_sum > 9:
				ans = '9' + ans
				digit_sum -= 9
			if digit_sum > 0:
				ans = str(digit_sum) + ans
			ans += str(last_digit)
			if min_ans == -1 or int(ans) < min_ans:
				min_ans = int(ans)
	print(min_ans)


import sys
from collections import deque
input = sys.stdin.buffer.readline
T = int(input())
for _ in range(T):
	(n, k) = map(int, input().split())

	def get_num(u, dw):
		(dg, cc) = ([], 0)
		while u:
			d = min(u, 8 if cc == dw else 9)
			u -= d
			dg.append(str(d))
			cc += 1
		return ''.join(reversed(dg))

	def check(sm, lv, ln, rn):
		rm = sm - lv * ln
		if rm < 0 or rm % rn:
			return (0, 0)
		rv = rm // rn
		if rv > lv:
			if rv != lv + 1:
				return (0, 0)
			return (1, get_num(lv, 0 if lv >= 9 else -1))
		else:
			d = lv - rv
			if d < 8 or (d - 8) % 9:
				return (0, 0)
			return (1, get_num(lv, d // 9 + 1))
	can = []
	for r in range(10):
		sm = n
		if r + k < 10:
			sm -= (k + 1) * (r + r + k) // 2
			if sm >= 0 and sm % (k + 1) == 0:
				can.append(get_num(sm // (k + 1), -1) + str(r))
		else:
			(ln, rn) = (10 - r, r + k - 9)
			sm -= ln * (r + 9) // 2 + rn * (rn - 1) // 2
			if sm >= 0:
				for lv in range(n + 1):
					(ok, u) = check(sm, lv, ln, rn)
					if ok:
						can.append(u + str(r))
	if not can:
		print(-1)
		continue
	mn = min([len(u) for u in can])
	mn = [u for u in can if len(u) == mn]
	mn.sort()
	print(mn[0])


def solve(s):
	(ans, ten) = (0, 1)
	while s > 0:
		val = min(9, s)
		ans += ten * val
		ten *= 10
		s -= val
	return ans

def digit_sum(val):
	s = 0
	while val > 0:
		s += val % 10
		val = int(val / 10)
	return s

def f(k):
	return int(k * (k - 1) / 2)

def xsolve(s, p):
	(ans, ten) = (0, 1)
	while s > p:
		ans += ten * 9
		ten *= 10
		s -= 9
	if s < 0 or s + 1 != p:
		return None
	d = min(s, 8)
	s -= d
	p -= d + 1
	ans += ten * d
	ten *= 10
	while s > 0:
		d = min(s, 9)
		ans += ten * d
		ten *= 10
		s -= d
	return ans

def main(n, k):
	ans = None
	if n - f(k + 1) >= 0 and (n - f(k + 1)) % (k + 1) == 0:
		ex = 10 - (k + 1)
		val = (n - f(k + 1)) / (k + 1)
		used = False
		if ex < val:
			val -= ex
			used = True
		pos = solve(int(val))
		if used:
			pos = 10 * pos + ex
		ans = pos
	for l in range(1, k + 1):
		for s in range(1, 151):
			left = n - s * l - f(l) - f(k + 1 - l)
			if left < 0:
				break
			elif left % (k + 1 - l) != 0 or s - (10 - l) < 0:
				continue
			p = int(left / (k + 1 - l))
			pos = xsolve(s - (10 - l), p)
			if pos != None:
				pos = pos * 10 + (10 - l)
				if ans == None:
					ans = pos
				else:
					ans = min(ans, pos)
	if ans == None:
		ans = -1
	print(int(ans))
t = int(input())
for _ in range(t):
	(n, k) = input().split()
	main(int(n), int(k))


import random

def alg(n, k):
	best = None
	last_digit = 9 - k
	ks = k * (k + 1) // 2
	if ks <= n:
		ts = n - ks
		if ts % (k + 1) == 0:
			s = ts // (k + 1)
			if last_digit >= s:
				best = min(s, last_digit)
			else:
				num = str(last_digit)
				s -= last_digit
				while s > 0:
					r = min(s, 9)
					s -= r
					num = str(r) + num
				best = int(num)
	for d in range(1, 100):
		for j in range(1, k + 1):
			tn = n + 9 * d * (k - j + 1)
			ts = tn - ks
			s = ts // (k + 1)
			req = 9 * (d - 1) + 10 - j
			if s < req:
				continue
			if ts % (k + 1) == 0:
				num = '9' * (d - 1) + str(10 - j)
				rem = s - req
				if rem > 8:
					num = '8' + num
					rem -= 8
				while rem > 0:
					r = min(rem, 9)
					rem -= r
					num = str(r) + num
				if best is None:
					best = int(num)
				else:
					best = min(best, int(num))
	if best is None:
		return -1
	return best
t = int(input())
tc = []
for _ in range(t):
	(n, k) = map(int, input().split(' '))
	tc.append((n, k))
for (n, k) in tc:
	print(alg(n, k))


def get(s):
	return str(s % 9) + '9' * (s // 9)
for tc in range(int(input())):
	(n, k) = map(int, input().split())
	k += 1
	bst = 10 ** 100
	for d in range(10):
		ends = 0
		for i in range(k):
			ends += (d + i) % 10
		if ends > n:
			continue
		if d + k > 10:
			for cnt in range(12):
				s = 9 * cnt * (10 - d)
				if s > n - ends:
					break
				for nd in range(9):
					ns = s + (10 - d) * nd + (k - (10 - d)) * (nd + 1)
					if ns > n - ends:
						break
					if (n - ends - ns) % k == 0:
						bst = min(bst, int(get((n - ends - ns) // k) + str(nd) + '9' * cnt + str(d)))
		elif (n - ends) % k == 0:
			bst = min(bst, int(get((n - ends) // k) + str(d)))
	print(-1 if bst == 10 ** 100 else bst)


import sys
import math
import collections
import operator as op
from collections import deque
from math import gcd, inf, sqrt
from bisect import bisect_right, bisect_left
from functools import reduce
from sys import stdin, stdout, setrecursionlimit
setrecursionlimit(2 ** 20)

def factorial(n):
	if n == 0:
		return 1
	return n * factorial(n - 1)

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 prime_factors(n):
	i = 2
	factors = []
	while i * i <= n:
		if n % i:
			i += 1
		else:
			n //= i
			factors.append(i)
	if n > 1:
		factors.append(n)
	return len(set(factors))

def isPowerOfTwo(x):
	return x and (not x & x - 1)

def factors(n):
	return list(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))

def construct(n):
	res = 0
	if n < 8:
		return n
	n -= 8
	res += n % 9
	n -= n % 9
	while n:
		res *= 10
		res += min(n, 9)
		n -= min(n, 9)
	res = res * 10 + 8
	return res
MOD = 10 ** 9 + 7
T = 1
T = int(stdin.readline())
for _ in range(T):
	(n, k) = list(map(int, stdin.readline().split()))
	ans = inf
	p = 1
	for n9 in range(17):
		p *= 10
		for d in range(10):
			no_carry = min(10 - d, k + 1)
			find = n - n9 * 9 * no_carry - (k + 1 - no_carry)
			for i in range(k + 1):
				find -= (i + d) % 10
			if find >= 0 and find % (k + 1) == 0:
				ans = min(ans, p * construct(find // (k + 1)) + p - 10 + d)
	if ans == inf:
		print(-1)
	else:
		print(ans)


def digitsum(n):
	ans = 0
	while n > 0:
		ans += n % 10
		n //= 10
	return ans

def construct_min_prefix(x):
	s = ''
	if x % 9 != 0:
		s += str(x % 9)
	s += '9' * (x // 9)
	return s

def find_sum(x, k):
	done = 0
	for i in range(k + 1):
		done += digitsum(int(x) + i)
	return done

def find(pref, s, e, n, k):
	ans = 10 ** 40
	st = str(pref) + '9' * s + str(e)
	possible = find_sum(st, k)
	if possible > n:
		return ans
	if possible == n:
		ans = min(ans, int(st))
	if possible < n:
		remaining = n - possible
		if remaining % (k + 1) == 0:
			num = construct_min_prefix(remaining // (k + 1)) + st
			ans = min(ans, int(num))
	return ans
for vishal in range(int(input())):
	ans = 10 ** 40
	(n, k) = list(map(int, input().split(' ')))
	for nines in range(100):
		for lastone in range(10):
			for aurek in range(10):
				if aurek + 9 * nines + lastone > n:
					continue
				ans = min(ans, find(aurek, nines, lastone, n, k))
	if ans >= 10 ** 40:
		print(-1)
	else:
		print(ans)


from sys import stdin, stdout

def get(s):
	return str(s % 9) + '9' * (s // 9)

def sum_of_digits(n, k):
	k += 1
	res = 10 ** 100
	for d in range(10):
		end = 0
		for i in range(k):
			end += (d + i) % 10
		if end > n:
			continue
		if d + k > 10:
			for cnt in range(12):
				s = 9 * cnt * (10 - d)
				if s > n - end:
					break
				for nd in range(9):
					ns = s + (10 - d) * nd + (k - (10 - d)) * (nd + 1)
					if ns > n - end:
						break
					if (n - end - ns) % k == 0:
						res = min(res, int(get((n - end - ns) // k) + str(nd) + '9' * cnt + str(d)))
		elif (n - end) % k == 0:
			res = min(res, int(get((n - end) // k) + str(d)))
	if res == 10 ** 100:
		return -1
	else:
		return res
t = int(stdin.readline())
for i in range(t):
	(n, k) = map(int, stdin.readline().split())
	stdout.write(str(sum_of_digits(n, k)) + '\n')


def get(summ):
	return str(summ % 9) + '9' * int(summ // 9)
for t in range(0, int(input())):
	(n, k) = map(int, input().split())
	result = -1
	for last_digit in range(10):
		last_digit_sum = 0
		for i in range(k + 1):
			last_digit_sum += (last_digit + i) % 10
		if last_digit_sum > n:
			continue
		if last_digit + k >= 10:
			for cnt9 in range(15):
				sum9 = 9 * cnt9 * (10 - last_digit)
				if sum9 > n - last_digit_sum:
					break
				for first_digt in range(9):
					first_digit_sum = (10 - last_digit) * first_digt + (k - 9 + last_digit) * (first_digt + 1)
					f = first_digit_sum + sum9 + last_digit_sum
					if n >= f:
						remain = n - f
						if remain % (k + 1) == 0:
							pres = int(get(remain // (k + 1)) + str(first_digt) + '9' * int(cnt9) + str(last_digit))
							if result == -1:
								result = pres
							else:
								result = min(result, pres)
		elif (n - last_digit_sum) % (k + 1) == 0:
			pres = int(get((n - last_digit_sum) // (k + 1)) + str(last_digit))
			if result == -1:
				result = pres
			else:
				result = min(result, pres)
	print(result)


from bisect import *
from collections import *
from math import gcd, ceil, sqrt, floor, inf
from heapq import *
from itertools import *
from operator import add, mul, sub, xor, truediv, floordiv
from functools import *
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

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

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

def N():
	return int(input())
from types import GeneratorType

def bootstrap(f, stack=[]):

	def wrappedfunc(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		else:
			to = f(*args, **kwargs)
			while True:
				if type(to) is GeneratorType:
					stack.append(to)
					to = next(to)
				else:
					stack.pop()
					if not stack:
						break
					to = stack[-1].send(to)
			return to
	return wrappedfunc
farr = [1]
ifa = []

def fact(x, mod=0):
	if mod:
		while x >= len(farr):
			farr.append(farr[-1] * len(farr) % mod)
	else:
		while x >= len(farr):
			farr.append(farr[-1] * len(farr))
	return farr[x]

def ifact(x, mod):
	global ifa
	ifa.append(pow(farr[-1], mod - 2, mod))
	for i in range(x, 0, -1):
		ifa.append(ifa[-1] * i % mod)
	ifa = ifa[::-1]

def per(i, j, mod=0):
	if i < j:
		return 0
	if not mod:
		return fact(i) // fact(i - j)
	return farr[i] * ifa[i - j] % mod

def com(i, j, mod=0):
	if i < j:
		return 0
	if not mod:
		return per(i, j) // fact(j)
	return per(i, j, mod) * ifa[j] % mod

def catalan(n):
	return com(2 * n, n) // (n + 1)

def linc(f, t, l, r):
	while l < r:
		mid = (l + r) // 2
		if t > f(mid):
			l = mid + 1
		else:
			r = mid
	return l

def rinc(f, t, l, r):
	while l < r:
		mid = (l + r + 1) // 2
		if t < f(mid):
			r = mid - 1
		else:
			l = mid
	return l

def ldec(f, t, l, r):
	while l < r:
		mid = (l + r) // 2
		if t < f(mid):
			l = mid + 1
		else:
			r = mid
	return l

def rdec(f, t, l, r):
	while l < r:
		mid = (l + r + 1) // 2
		if t > f(mid):
			r = mid - 1
		else:
			l = mid
	return l

def isprime(n):
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			return False
	return True

def binfun(x):
	c = 0
	for w in arr:
		c += ceil(w / x)
	return c

def lowbit(n):
	return n & -n

def inverse(a, m):
	a %= m
	if a <= 1:
		return a
	return (1 - inverse(m, a) * m) // a % m

class BIT:

	def __init__(self, arr):
		self.arr = arr
		self.n = len(arr) - 1

	def update(self, x, v):
		while x <= self.n:
			self.arr[x] += v
			x += x & -x

	def query(self, x):
		ans = 0
		while x:
			ans += self.arr[x]
			x &= x - 1
		return ans

class DSU:

	def __init__(self, n):
		self.c = [-1] * n

	def same(self, x, y):
		return self.find(x) == self.find(y)

	def find(self, x):
		if self.c[x] < 0:
			return x
		self.c[x] = self.find(self.c[x])
		return self.c[x]

	def union(self, u, v):
		(u, v) = (self.find(u), self.find(v))
		if u == v:
			return False
		if self.c[u] < self.c[v]:
			(u, v) = (v, u)
		self.c[u] += self.c[v]
		self.c[v] = u
		return True

	def size(self, x):
		return -self.c[self.find(x)]

class UFS:

	def __init__(self, n):
		self.parent = [i for i in range(n)]
		self.ranks = [0] * n

	def find(self, x):
		if x != self.parent[x]:
			self.parent[x] = self.find(self.parent[x])
		return self.parent[x]

	def union(self, u, v):
		(pu, pv) = (self.find(u), self.find(v))
		if pu == pv:
			return False
		if self.ranks[pu] >= self.ranks[pv]:
			self.parent[pv] = pu
			if self.ranks[pv] == self.ranks[pu]:
				self.ranks[pu] += 1
		else:
			self.parent[pu] = pv

def Prime(n):
	c = 0
	prime = []
	flag = [0] * (n + 1)
	for i in range(2, n + 1):
		if not flag[i]:
			prime.append(i)
			c += 1
		for j in range(c):
			if i * prime[j] > n:
				break
			flag[i * prime[j]] = prime[j]
			if i % prime[j] == 0:
				break
	return prime

def dij(s, graph):
	d = {}
	d[s] = 0
	heap = [(0, s)]
	seen = set()
	while heap:
		(dis, u) = heappop(heap)
		if u in seen:
			continue
		for v in graph[u]:
			if v not in d or d[v] > d[u] + graph[u][v]:
				d[v] = d[u] + graph[u][v]
				heappush(heap, (d[v], v))
	return d

def GP(it):
	return [(ch, len(list(g))) for (ch, g) in groupby(it)]

class DLN:

	def __init__(self, val):
		self.val = val
		self.pre = None
		self.next = None

def query(i, j, t):
	if t == 0:
		print('AND', i, j)
		sys.stdout.flush()
	elif t == 2:
		print('XOR', i, j)
		sys.stdout.flush()
	ans = N()
	return ans
t = N()
for i in range(t):
	(n, k) = RL()
	a = n
	ans = inf
	if n >= (k + 1) * k // 2:
		n -= (k + 1) * k // 2
		if n % (k + 1) == 0:
			n //= k + 1
			ma = 9 - k
			if n <= ma:
				ans = n
			else:
				(d, m) = divmod(n - ma, 9)
				if m:
					ans = str(m) + '9' * d + str(ma)
				else:
					ans = '9' * d + str(ma)
				ans = int(ans)
	if k >= 1:
		for y in range(1, k + 1):
			last = 10 - (k - y + 1)
			res = a - y * (y + 1) // 2 - (last + 9) * (10 - last) // 2
			if res < 0:
				continue
			else:
				for x in range(9):
					if res - x * (k + 1) < 0:
						break
					if (res - x * (k + 1)) % (9 * (10 - last)) == 0:
						i = (res - x * (k + 1)) // (9 * (10 - last))
						tmp = str(x) + '9' * i + str(last)
						ans = min(ans, int(tmp))
		for y in range(1, k + 1):
			last = 10 - (k - y + 1)
			res = a + 9 * y - last * (k + 1) - k * (k + 1) // 2
			if res >= 0 and res % (k + 1) == 0:
				f = res // (k + 1)
				if f == 0:
					ans = min(last, ans)
				elif f < 9:
					ans = min(ans, 10 * f + last)
				else:
					(d, m) = divmod(f - 8, 9)
					if m == 0:
						tmp = d * '9' + '8' + str(last)
					else:
						tmp = str(m) + '9' * d + '8' + str(last)
					ans = min(ans, int(tmp))
	if ans != inf:
		print(ans)
	else:
		print(-1)


import sys

def gen1(n):
	base = 10 ** n - 1
	yield base
	for i in range(0, n):
		yield (base - 10 ** i)

def gen2(n):
	for i in range(n):
		for x in gen1(i):
			for j in range(0, 10):
				yield (j * 10 ** i + x)

def dsum(n):
	s = 0
	while n > 0:
		s += n % 10
		n //= 10
	return s

def dsuminv(n):
	h = n // 9
	r = n % 9 + 1
	return r * 10 ** h - 1
h = {}
for x in gen2(15):
	for j in range(19):
		h[10 * x + j] = dsum(10 * x + j)
kk = sorted(h.keys())

def solve(n, k):
	if n < k * (k + 1) // 2:
		return -1
	if k == 0:
		return dsuminv(n)
	rs = sum((h[kk[i]] for i in range(k + 1)))
	for j in range(len(kk) - k - 1):
		if n < 20 and j > 200:
			break
		if rs == n and kk[j + k] == kk[j] + k:
			return kk[j]
		rs -= h[kk[j]]
		rs += h[kk[j + k + 1]]
	return -1
t = int(input().strip())
for _ in range(t):
	(n, k) = list(map(int, input().strip().split()))
	print(solve(n, k))


def sumDigits(x):
	if x == 0:
		return 0
	return x % 10 + sumDigits(x // 10)

def create(x):
	ans = ''
	while x >= 9:
		ans = '9' + ans
		x -= 9
	ans = str(x) + ans
	return int(ans)

def create_ex(x, y):
	track = -1
	for i in range(9, x + 1, 9):
		r = x - i
		if r + 1 == y:
			track = i
	if track == -1:
		return -1
	r = x - track
	ans = 0
	if r < 9:
		ans = r
	else:
		ans = create(r - 8) * 10 + 8
	ans *= 10 ** (track // 9)
	ans += create(track)
	return ans
preResult = {}
for i in range(100):
	s = 0
	for k in range(10):
		s += sumDigits(i + k)
		if s <= 150 and (s, k) not in preResult:
			preResult[s, k] = i
pre = [[-1 for i in range(152)] for j in range(152)]
for x in range(1, 151):
	pre[x][x] = create(x)
	if x != 150:
		if x < 9:
			pre[x][x + 1] = x
		else:
			pre[x][x + 1] = create(x - 8) * 10 + 8
	for y in range(1, x):
		pre[x][y] = create_ex(x, y)

def update(x, maybe):
	if x == -1:
		return maybe
	if x > maybe:
		return maybe
	return x

def solve():
	(n, k) = input().strip().split(' ')
	n = int(n)
	k = int(k)
	if (n, k) in preResult:
		return preResult[n, k]
	ans = -1
	for st in range(10):
		rem = n
		flag = False
		p1 = 0
		p2 = 0
		for i in range(k + 1):
			flag = flag | (st + i > 9)
			rem -= (st + i) % 10
			p1 += st + i <= 9
			p2 += st + i > 9
		if rem <= 0:
			continue
		if flag:
			for x in range(1, 151):
				if rem - x * p1 <= 0:
					break
				r = rem - x * p1
				if r % p2 != 0:
					continue
				r //= p2
				if pre[x][r] == -1:
					continue
				if x == r:
					continue
				ans = update(ans, pre[x][r] * 10 + st)
		else:
			if rem % (k + 1) != 0:
				continue
			r = rem // (k + 1)
			if pre[r][r] == -1:
				continue
			ans = update(ans, pre[r][r] * 10 + st)
	return ans
t = int(input())
for iter in range(t):
	ans = solve()
	print(ans)


def f(sm, nine):
	if sm < 0:
		return -1
	if nine * 9 > sm:
		return -1
	sm -= nine * 9
	ret = nine * '9'
	if sm >= 8:
		sm -= 8
		ret = '8' + ret
	ret = str(sm % 9) + sm // 9 * '9' + ret
	return int(ret)

def g(sm, lstmax):
	mn = min(sm, lstmax)
	sm -= lstmax
	ret = str(sm % 9) + sm // 9 * '9' + str(mn)
	return int(ret)

def digit_sum(n):
	s = str(n)
	return sum((int(i) for i in s))

def nc(i):
	return i * (i + 1) // 2

def valid(n, k):
	n %= 10
	if n + k >= 10:
		return False
	return True

def naive(n, k):
	c = 0
	sm = 0
	for i in range(k + 1):
		sm += digit_sum(c + i)
	for _ in range(10 ** 6):
		if sm == n:
			return c
		sm -= digit_sum(c)
		c += 1
		sm += digit_sum(c + k)
	else:
		return -1
for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	mp = k * (k + 1) // 2
	res = 10 ** 100
	if n - mp > 0 and (n - mp) % (k + 1) == 0:
		fx = (n - mp) // (k + 1)
		res = min(res, g(fx, 9 - k))
	for i in range(k + 1):
		for j in range(1, 30):
			mp = nc(k - i) - nc(i)
			if n + 9 * j * (k - i) - mp > 0 and (n + 9 * j * (k - i) - mp) % (k + 1) == 0:
				fx = (n + 9 * j * (k - i) - mp) // (k + 1)
				if f(fx, j) - i < 0:
					continue
				res = min(res, f(fx, j) - i)
	for i in range(400):
		tmp = 0
		for j in range(k + 1):
			tmp += digit_sum(i + j)
		if tmp == n:
			res = min(res, i)
			break
	if res == 10 ** 100:
		res = -1
	print(res)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	ans = float('inf')
	for m in range(20):
		for l in range(10):
			if k + l <= 9:
				dsum = n - k * (k + 1) // 2
				if dsum % (k + 1) == 0:
					f = dsum // (k + 1)
					f -= l
					if f >= 0:
						if 9 > f:
							test = str(f) * (f != 0) + str(l)
							ans = min(ans, int(test))
						else:
							q = f // 9
							r = f % 9
							test = str(r) * (r != 0) + '9' * q + str(l)
							test = int(test)
							ans = min(test, ans)
			else:
				dsum = n - (k + l - 9) * (1 - 9 * m - l) - (9 - l) * (10 - l) // 2 - (k + l - 9) * (k + l - 10) // 2
				if dsum % (k + 1) == 0:
					f = dsum // (k + 1)
					f -= 9 * m + l
					if f >= 0:
						if 9 > f:
							test = str(f) * (f != 0) + '9' * m + str(l)
							ans = min(ans, int(test))
						else:
							f -= 8
							q = f // 9
							r = f % 9
							test = str(r) * (r != 0) + '9' * q + '8' + '9' * m + str(l)
							test = int(test)
							ans = min(test, ans)
	if ans != float('inf'):
		print(ans)
	else:
		print(-1)


def digitsum(n):
	ans = 0
	while n > 0:
		ans += n % 10
		n //= 10
	return ans
for vishal in range(int(input())):
	ans = 10 ** 40
	(n, k) = list(map(int, input().split(' ')))
	for lastdigit in range(10):
		for numberofnine in range(100):
			if lastdigit + 9 * numberofnine > n:
				continue
			candi = '9' * numberofnine + str(lastdigit)
			mandi = candi
			done = 0
			for ii in range(k + 1):
				done += digitsum(int(candi) + ii)
			if k + 1 >= 10 - lastdigit:
				done -= k + 1 - 10 + lastdigit
			if done > n:
				continue
			for aurek in range(9):
				ddone = 0
				if k + 1 >= 10 - lastdigit:
					ddone = done + aurek * (10 - lastdigit) + (aurek + 1) * (k + 1 - 10 + lastdigit)
				else:
					ddone = done + aurek * (k + 1)
				if ddone > n:
					continue
				if ddone == n:
					if aurek > 0:
						candi = str(aurek) + candi
						ans = min(ans, int(candi))
					else:
						ans = min(ans, int(candi))
					continue
				ddone = n - ddone
				if ddone % (k + 1) != 0:
					continue
				ddone //= k + 1
				t = ddone % 9
				ss = ''
				if t:
					ss += str(t)
				for iii in range(ddone // 9):
					ss += '9'
				if len(ss) > 0:
					ss += str(aurek)
				if len(ss) == 0:
					ans = min(ans, int(mandi))
				else:
					ss += candi
					ans = min(ans, int(ss))
	if ans >= 10 ** 40:
		ans = -1
	print(ans)


MAX = 150
INF = float('inf')

def compute_suffix(digit_sum):
	digit_sum += 1
	digit_count = digit_sum // 9
	return 10 ** digit_count * (digit_sum % 9) + (10 ** digit_count - 1) - 1

def compute_prefix_sum(first_digit, prefix_len, num_count):
	pre_count = min(num_count, 10 - first_digit)
	result = 9 * prefix_len * pre_count + (2 * first_digit + pre_count - 1) * pre_count // 2
	result += (num_count - pre_count) * (num_count - pre_count + 1) // 2
	return result

def solve(suffix_table, digit_sum, num_count):
	result = INF
	for first_digit in range(min(10, digit_sum + 1)):
		for prefix_len in range((digit_sum - first_digit) // 9 + 1):
			prefix_sum = compute_prefix_sum(first_digit, prefix_len, num_count)
			if prefix_sum > digit_sum or (digit_sum - prefix_sum) % num_count != 0:
				continue
			suffix = suffix_table[(digit_sum - prefix_sum) // num_count]
			candidate = suffix * 10 ** (prefix_len + 1) + (10 ** prefix_len - 1) * 10 + first_digit
			result = min(result, candidate)
	return result if result != INF else -1
suffix_table = [compute_suffix(n) for n in range(MAX + 1)]
test_count = int(input())
for _ in range(test_count):
	(digit_sum, num_count) = map(int, input().split())
	print(solve(suffix_table, digit_sum, num_count + 1))


res = [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 19, 29, 39, 49, 59, 69, 79, 89, 99, 199, 299, 399, 499, 599, 699, 799, 899, 999, 1999, 2999, 3999, 4999, 5999, 6999, 7999, 8999, 9999, 19999, 29999, 39999, 49999, 59999, 69999, 79999, 89999, 99999, 199999, 299999, 399999, 499999, 599999, 699999, 799999, 899999, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], [-1, 0, -1, 1, -1, 2, -1, 3, -1, 4, 9, 5, 19, 6, 29, 7, 39, 8, 49, 18, 59, 28, 69, 38, 79, 48, 89, 58, 189, 68, 289, 78, 389, 88, 489, 98, 589, 198, 689, 298, 789, 398, 889, 498, 989, 598, 1989, 698, 2989, 798, 3989, 898, 4989, 998, 5989, 1998, 6989, 2998, 7989, 3998, 8989, 4998, 9989, 5998, 19989, 6998, 29989, 7998, 39989, 8998, 49989, 9998, 59989, 19998, 69989, 29998, 79989, 39998, 89989, 49998, 99989, 59998, 199989, 69998, 299989, 79998, 399989, 89998, 499989, 99998, 599989, 199998, 699989, 299998, 799989, 399998, 899989, 499998, 999989, 599998, -1, 699998, -1, 799998, -1, 899998, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], [-1, -1, -1, 0, -1, -1, 1, -1, -1, 2, -1, -1, 3, -1, -1, 4, -1, -1, 5, -1, -1, 6, -1, -1, 7, -1, -1, 17, -1, -1, 27, -1, -1, 37, -1, -1, 47, -1, -1, 57, -1, -1, 67, -1, -1, 77, -1, -1, 87, -1, -1, 97, -1, -1, 197, -1, -1, 297, -1, -1, 397, -1, -1, 497, -1, -1, 597, -1, -1, 697, -1, -1, 797, -1, -1, 897, -1, -1, 997, -1, -1, 1997, -1, -1, 2997, -1, -1, 3997, -1, -1, 4997, -1, -1, 5997, -1, -1, 6997, -1, -1, 7997, -1, -1, 8997, -1, -1, 9997, -1, -1, 19997, -1, -1, 29997, -1, -1, 39997, -1, -1, 49997, -1, -1, 59997, -1, -1, 69997, -1, -1, 79997, -1, -1, 89997, -1, -1, 99997, -1, -1, 199997, -1, -1, 299997, -1, -1, 399997, -1, -1, 499997, -1, -1, 599997, -1, -1, 699997], [-1, -1, -1, -1, -1, -1, 0, -1, -1, -1, 1, -1, -1, -1, 2, 9, -1, -1, 3, 19, 8, -1, 4, 29, 18, 7, 5, 39, 28, 17, 6, 49, 38, 27, 16, 59, 48, 37, 26, 69, 58, 47, 36, 79, 68, 57, 46, 89, 78, 67, 56, 189, 88, 77, 66, 289, 188, 87, 76, 389, 288, 187, 86, 489, 388, 287, 96, 589, 488, 387, 196, 689, 588, 487, 296, 789, 688, 587, 396, 889, 788, 687, 496, 989, 888, 787, 596, 1989, 988, 887, 696, 2989, 1988, 987, 796, 3989, 2988, 1987, 896, 4989, 3988, 2987, 996, 5989, 4988, 3987, 1996, 6989, 5988, 4987, 2996, 7989, 6988, 5987, 3996, 8989, 7988, 6987, 4996, 9989, 8988, 7987, 5996, 19989, 9988, 8987, 6996, 29989, 19988, 9987, 7996, 39989, 29988, 19987, 8996, 49989, 39988, 29987, 9996, 59989, 49988, 39987, 19996, 69989, 59988, 49987, 29996, 79989, 69988, 59987, 39996], [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, -1, -1, -1, -1, 1, -1, -1, -1, 9, 2, -1, -1, 8, 19, 3, -1, 7, 18, 29, 4, 6, 17, 28, 39, 5, 16, 27, 38, 49, 15, 26, 37, 48, 59, 25, 36, 47, 58, 69, 35, 46, 57, 68, 79, 45, 56, 67, 78, 89, 55, 66, 77, 88, 189, 65, 76, 87, 188, 289, 75, 86, 187, 288, 389, 85, 186, 287, 388, 489, 95, 286, 387, 488, 589, 195, 386, 487, 588, 689, 295, 486, 587, 688, 789, 395, 586, 687, 788, 889, 495, 686, 787, 888, 989, 595, 786, 887, 988, 1989, 695, 886, 987, 1988, 2989, 795, 986, 1987, 2988, 3989, 895, 1986, 2987, 3988, 4989, 995, 2986, 3987, 4988, 5989, 1995, 3986, 4987, 5988, 6989, 2995, 4986, 5987, 6988, 7989, 3995, 5986, 6987, 7988, 8989, 4995, 6986, 7987, 8988, 9989, 5995], [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, -1, -1, -1, -1, -1, 1, -1, -1, 9, -1, -1, 2, -1, -1, 7, -1, -1, 3, -1, -1, 5, -1, -1, 4, -1, -1, 15, -1, -1, 14, -1, -1, 25, -1, -1, 24, -1, -1, 35, -1, -1, 34, -1, -1, 45, -1, -1, 44, -1, -1, 55, -1, -1, 54, -1, -1, 65, -1, -1, 64, -1, -1, 75, -1, -1, 74, -1, -1, 85, -1, -1, 84, -1, -1, 185, -1, -1, 94, -1, -1, 285, -1, -1, 194, -1, -1, 385, -1, -1, 294, -1, -1, 485, -1, -1, 394, -1, -1, 585, -1, -1, 494, -1, -1, 685, -1, -1, 594, -1, -1, 785, -1, -1, 694, -1, -1, 885, -1, -1, 794, -1, -1, 985, -1, -1, 894, -1, -1, 1985, -1, -1, 994, -1, -1, 2985], [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, -1, -1, -1, -1, -1, -1, 1, -1, 9, -1, 8, -1, 7, 2, 6, 19, 5, 18, 4, 17, 3, 16, 29, 15, 28, 14, 27, 13, 26, 39, 25, 38, 24, 37, 23, 36, 49, 35, 48, 34, 47, 33, 46, 59, 45, 58, 44, 57, 43, 56, 69, 55, 68, 54, 67, 53, 66, 79, 65, 78, 64, 77, 63, 76, 89, 75, 88, 74, 87, 73, 86, 189, 85, 188, 84, 187, 83, 186, 289, 185, 288, 184, 287, 93, 286, 389, 285, 388, 284, 387, 193, 386, 489, 385, 488, 384, 487, 293, 486, 589, 485, 588, 484, 587, 393, 586, 689, 585, 688, 584, 687, 493, 686, 789, 685, 788, 684, 787, 593, 786, 889, 785, 888, 784, 887, 693, 886, 989, 885], [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, -1, -1, -1, -1, -1, -1, -1, 1, 9, 8, 7, 6, 5, 4, 3, 2, 19, 18, 17, 16, 15, 14, 13, 12, 29, 28, 27, 26, 25, 24, 23, 22, 39, 38, 37, 36, 35, 34, 33, 32, 49, 48, 47, 46, 45, 44, 43, 42, 59, 58, 57, 56, 55, 54, 53, 52, 69, 68, 67, 66, 65, 64, 63, 62, 79, 78, 77, 76, 75, 74, 73, 72, 89, 88, 87, 86, 85, 84, 83, 82, 189, 188, 187, 186, 185, 184, 183, 92, 289, 288, 287, 286, 285, 284, 283, 192, 389, 388, 387, 386, 385, 384, 383, 292, 489, 488, 487, 486, 485, 484, 483, 392, 589, 588, 587, 586, 585, 584, 583, 492, 689, 688], [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, -1, -1, -1, -1, -1, -1, -1, -1, 1, -1, -1, -1, -1, -1, -1, -1, -1, 11, -1, -1, -1, -1, -1, -1, -1, -1, 21, -1, -1, -1, -1, -1, -1, -1, -1, 31, -1, -1, -1, -1, -1, -1, -1, -1, 41, -1, -1, -1, -1, -1, -1, -1, -1, 51, -1, -1, -1, -1, -1, -1, -1, -1, 61, -1, -1, -1, -1, -1, -1, -1, -1, 71, -1, -1, -1, -1, -1, -1, -1, -1, 81, -1, -1, -1, -1, -1, -1, -1, -1, 91, -1, -1, -1, -1, -1, -1, -1, -1, 191, -1, -1, -1, -1, -1, -1, -1, -1, 291, -1, -1, -1, -1, -1, -1], [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 281, 282, 283, 284, 285]]
q = int(input())
for _ in range(q):
	(n, k) = map(int, input().split())
	if k > 1:
		print(res[k][n])
	elif k == 0:
		dziew = n // 9
		piersza = n - dziew * 9
		if piersza > 0:
			slowo = str(piersza)
		else:
			slowo = ''
		slowo += '9' * dziew
		print(slowo)
	elif n % 2 == 1:
		if n < 18:
			print(n // 2)
		else:
			k = 0
			while 18 * (k + 1) < n:
				k += 1
			liczba = '9' * k
			c = (n - 18 * k + 1) // 2
			if c > 0:
				liczba = str(c) + liczba
			cyk = int(liczba)
			print(cyk - 1)
	elif n < 10:
		print(-1)
	elif n <= 26:
		if n == 10:
			print(9)
		if n == 12:
			print(19)
		if n == 14:
			print(29)
		if n == 16:
			print(39)
		if n == 18:
			print(49)
		if n == 20:
			print(59)
		if n == 22:
			print(69)
		if n == 24:
			print(79)
		if n == 26:
			print(89)
	else:
		sumka = 26
		liczba = str(89)
		while True:
			if sumka == n:
				break
			if n - sumka >= 18:
				liczba = '9' + liczba
				sumka += 18
			else:
				liczba = str((n - sumka) // 2) + liczba
				sumka = n
		print(liczba)


def digit_sum(n):
	tot = 0
	while n:
		tot += n % 10
		n //= 10
	return tot

def sum_f(n, k):
	tot = 0
	for i in range(k + 1):
		tot += digit_sum(n + i)
	return tot
t = int(input().split()[0])
for case in range(t):
	(n, k) = map(int, input().split())
	ans = -1
	for i in range(1000 - k):
		diff = n - sum_f(i, k)
		if diff == 0:
			ans = i
			break
		if diff > 0 and diff % (k + 1) == 0:
			rem = diff // (k + 1)
			prefix = 0
			while rem >= 10:
				prefix = prefix * 10 + 9
				rem -= 9
			if rem > 0 and prefix == 0:
				prefix = rem
			elif rem > 0:
				prefix = int(str(rem) + str(prefix))
			curr = prefix * 1000 + i
			if ans == -1:
				ans = curr
			elif curr < ans:
				ans = curr
	print(ans)


import sys

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

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 19
MOD = 10 ** 9 + 7

def digit_sum(S):
	res = 0
	for s in S:
		res += int(s)
	return res
MAX = 150
ans = list2d(MAX + 1, 10, -1)
last = list2d(10, 10, 0)
for i in range(10):
	for j in range(i, i + 10):
		cnt = 0
		for k in range(i, j + 1):
			k %= 10
			cnt += k
		last[i][j % 10] = cnt
for i in range(MAX + 1):
	s = ''
	tmp = i
	while tmp - 9 >= 0:
		s += '9'
		tmp -= 9
	if tmp:
		s += str(tmp)
	s = s[::-1]
	for j in range(10):
		cnt = i * (j + 1)
		if cnt > MAX:
			break
		for k in range(10):
			if k + j >= 10:
				break
			res = cnt + last[k][k + j]
			if res <= MAX:
				if ans[res][j] == -1 or ans[res][j] > int(s + str(k)):
					ans[res][j] = int(s + str(k))
for i in range(MAX + 1):
	x = 0
	while x * 9 <= i:
		tmp = i
		s1 = '9' * x
		tmp -= x * 9
		if tmp - 8 >= 0:
			s1 += '8'
			tmp -= 8
		while tmp - 9 >= 0:
			s1 += '9'
			tmp -= 9
		if tmp:
			s1 += str(tmp)
		if not s1:
			s1 = '0'
		s1 = s1[::-1]
		s2 = str(int(s1) + 1)
		dsm1 = digit_sum(s1)
		dsm2 = digit_sum(s2)
		for j in range(1, 10):
			for a in range(1, j + 1):
				b = j + 1 - a
				cnt = dsm1 * a + dsm2 * b
				if cnt > MAX:
					break
				k = 10 - a
				if k + j < 10:
					continue
				res = cnt + last[k][(k + j) % 10]
				if res <= MAX:
					if ans[res][j] == -1 or ans[res][j] > int(s1 + str(k)):
						ans[res][j] = int(s1 + str(k))
		x += 1
for _ in range(INT()):
	(N, K) = MAP()
	print(ans[N][K])


import sys
import math
read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def solve_sum_digit(n):
	res = 0
	while n:
		res += n % 10
		n //= 10
	return res

def solve_0(n):
	digit = math.ceil(n / 9)
	res = ''
	if n % 9:
		res += str(n % 9) + '9' * (digit - 1)
	else:
		res += '9' * digit
	return res

def solve_1(n):
	if n % 2:
		if n <= 17:
			return n // 2
		else:
			digit = n // 18 + 1
			num_top = n % 18 // 2 + 1
			return str(num_top) + '9' * (digit - 2) + '8'
	elif n < 10:
		return -1
	elif n == 10:
		return 9
	else:
		digit = (n + 8) // 18 + 1
		num_top = (n + 8) % 18 // 2 + 1
		if digit == 2:
			return str(num_top - 1) + str(9)
		else:
			return str(num_top) + '9' * (digit - 3) + '89'

def solve_2(n):
	if n % 3:
		return -1
	elif n <= 24:
		return n // 3 - 1
	else:
		digit = n // 27 + 1
		num_top = n % 27 // 3 + 1
		return str(num_top) + '9' * (digit - 2) + '7'
t = int(input())
for case in range(t):
	(n, k) = map(int, input().split())
	if k == 0:
		ans = solve_0(n)
	elif k == 1:
		ans = solve_1(n)
	elif k == 2:
		ans = solve_2(n)
	else:
		pass_flag = 0
		if k == 3:
			lim = 10 ** 5
		elif k <= 5:
			lim = 10 ** 4
		else:
			lim = 10 ** 3
		for x in range(0, lim):
			sum_digit = 0
			for i in range(k + 1):
				sum_digit += solve_sum_digit(x + i)
			if sum_digit == n:
				ans = x
				pass_flag = 1
				break
		if pass_flag == 0:
			ans = -1
	print(ans)


import sys

def input():
	return sys.stdin.readline().rstrip()

def input_split():
	return [int(i) for i in input().split()]

def k_one(n):
	if n == 0:
		return 0
	ans = ''
	lis = list(range(1, 10))
	lis.reverse()
	for i in lis:
		if n == 0:
			return int(ans)
		div = n // i
		n = n % i
		ans = str(i) * div + ans
	return int(ans)
testCases = int(input())
answers = []

def sum_digs(a):
	ans = 0
	while a > 0:
		ans += a % 10
		a = a // 10
	return ans
store = [[[-1 for case_k in range(11)] for last_dig in range(10)] for num_nines in range(17)]
for num_nines in range(17):
	for last_dig in range(10):
		for case_k in range(1, 11):
			s = 0
			current = int('9' * num_nines + str(last_dig))
			for i in range(case_k):
				s += sum_digs(current + i)
			store[num_nines][last_dig][case_k] = s - case_k * sum_digs(current)
for _ in range(testCases):
	(n, k) = input_split()
	k = k + 1
	if k == 1:
		ans = k_one(n)
	else:
		possibilities = []
		for case_num_nines in range(17):
			for case_end_digit in range(10):
				temp = n - store[case_num_nines][case_end_digit][k]
				ending = int('9' * case_num_nines + str(case_end_digit))
				if temp < 0:
					continue
				if temp % k != 0:
					continue
				else:
					fx = temp // k
					if fx < sum_digs(ending):
						continue
					else:
						pending = fx - sum_digs(ending)
						if pending < 9:
							ans = int(str(pending) + '9' * case_num_nines + str(case_end_digit))
						else:
							ans = int(str(k_one(pending - 8)) + str(8) + '9' * case_num_nines + str(case_end_digit))
						possibilities.append(ans)
		if len(possibilities) == 0:
			ans = -1
		else:
			ans = min(possibilities)
	answers.append(ans)
print(*answers, sep='\n')


for ss in range(int(input())):
	(n, k) = input().strip().split()
	n = int(n)
	k = int(k)
	list = []
	ilist = []
	klaar = True
	for i in range(10):
		m = 0
		for t in range(k + 1):
			s = i + t
			if s >= 10:
				s = s - 9
			m = m + s
		if i == 0 and m > n:
			print(-1)
			klaar = False
			break
		if (n - m) % (k + 1) == 0 and n > m:
			list.append(m)
			ilist.append(i)
		if n == m:
			print(i)
			klaar = False
			break
		if not klaar:
			break
	if klaar:
		if not list:
			print(-1)
			continue
		else:
			i = ilist[list.index(max(list))]
			if i + k < 10 or (i + k >= 10 and int((n - max(list)) / (k + 1)) < 9):
				lom = int((n - max(list)) / (k + 1))
				print(int(str(lom % 9) + lom // 9 * '9' + str(i)))
			else:
				lom = int((n - max(list)) / (k + 1) - 8)
				print(int(str(lom % 9) + lom // 9 * '9' + '8' + str(i)))


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

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

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

def N():
	return int(input())

def comb(n, m):
	return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0

def perm(n, m):
	return factorial(n) // factorial(n - m) if n >= m else 0

def mdis(x1, y1, x2, y2):
	return abs(x1 - x2) + abs(y1 - y2)
mod = 998244353
INF = float('inf')
from math import factorial
from collections import Counter, defaultdict, deque
from heapq import heapify, heappop, heappush

def main():
	for _ in range(N()):
		(n, k) = RL()
		res = INF
		for i in range(10):
			for pre in range(100, 0, -1):
				nine = 0
				sm = max(i + k - 9, 0)
				rec = str(i)
				tag = False
				for j in range(10000):
					now = min(9, (n - sm) // (k + 1))
					if now == 9 and nine >= pre and (tag == False):
						now = 8
						tag = True
					if now == 9:
						nine += 1
					if j != 0:
						rec += str(now)
					for l in range(k + 1):
						if j == 0:
							if i + l <= 9:
								sm += i + l
							else:
								sm += (i + l) % 10
						elif i + l <= 9 or tag:
							sm += now
						elif now != 9:
							sm += now
					if sm == n:
						res = min(res, int(rec[::-1]))
					if sm > n or now == 0:
						break
		print(res if res != INF else -1)
main()


t = int(input())

def solve(n, k):
	ans = -1
	for i in range(10):
		m = n // 9
		if i + k < 10:
			m = 0
		for j in range(m + 1):
			if i + k >= 10 and j == 0:
				continue
			cur_sum = (i + (i + k)) * (k + 1) // 2
			if j != 0:
				before_turn = 10 - i
				after_turn = k + 1 - before_turn
				cur_sum = (i + 9) * before_turn // 2 + (1 + after_turn) * after_turn // 2 + before_turn * 9 * (j - 1)
			rem = n - cur_sum
			if rem < 0 or rem % (k + 1) != 0:
				continue
			num = [i]
			for x in range(j - 1):
				num.append(9)
			mx = 9
			if i + k >= 10:
				mx = 8
			rem = rem // (k + 1)
			while rem != 0:
				d = min(rem, mx)
				mx = 9
				rem -= d
				num.append(d)
			cur_best = 0
			for d in range(len(num)):
				cur_best += 10 ** d * num[d]
			if ans == -1:
				ans = cur_best
			else:
				ans = min(ans, cur_best)
	print(ans)
for i in range(t):
	(n, k) = input().split(' ')
	n = int(n)
	k = int(k)
	solve(n, k)


for i in range(int(input())):
	(n, k) = map(int, input().split())
	ans = 'a' * 100
	for x in range(10):
		for d in range(n // 9 + 2):
			left = n
			for i in range(k + 1):
				left -= d * 9 + i + x
				if x + i > 9:
					left += (d + 1) * 9
			if left < 0:
				break
			if left % (k + 1) != 0:
				continue
			left //= k + 1
			temp = '9' * d + str(x)
			if left:
				add = min(left, 8)
				temp = str(add) + temp
				left -= add
			while left > 0:
				add = min(left, 9)
				temp = str(add) + temp
				left -= add
			if len(temp) < len(ans):
				ans = str(temp)
			elif len(temp) == len(ans) and temp < ans:
				ans = str(temp)
	if ans[0] == 'a':
		ans = -1
	print(ans)


T = int(input())
while T > 0:
	(n, k) = map(int, input().split())
	res = float('inf')
	for last in range(0, 10):
		if last + k <= 9:
			al = (last + last + k) * (k + 1) // 2
			left = n - al
			if left >= 0 and left % (k + 1) == 0:
				x = left // (k + 1)
				temp = last
				index = 1
				while x >= 10:
					temp += 9 * 10 ** index
					index += 1
					x -= 9
				temp += x * 10 ** index
				res = min(res, temp)
		else:
			number = 0
			al = (last + 9) * (9 - last + 1) // 2 + (last + k - 8) * (k + last - 9) // 2
			while True:
				already = 9 * number * (9 - last + 1) + al
				left = n - already
				if left < 0:
					break
				if left % (k + 1) == 0:
					index = 1
					y = last
					for i in range(number):
						y += 9 * 10 ** index
						index += 1
					x = left // (k + 1)
					if x > 8:
						x -= 8
						y += 8 * 10 ** index
						index += 1
					while x >= 10:
						y += 9 * 10 ** index
						index += 1
						x -= 9
					y += x * 10 ** index
					res = min(res, y)
				number += 1
	if res == float('inf'):
		res = -1
	print(res)
	T -= 1


import sys
import io
import math
import collections
import decimal
import itertools
import bisect
import heapq

def input():
	return sys.stdin.readline()[:-1]
INF = 10 ** 20

def calc(t):
	res = 0
	for a in t:
		while a:
			res += a % 10
			a //= 10
	return res

def solve(N, K):
	t0 = [i for i in range(K)]
	T = []
	for j in range(10):
		t = list(t0)
		for i in range(K):
			t[i] += j
		T.append(t)
	ans = INF
	for t in T:
		n = calc(t)
		N1 = N - n
		if N1 < 0 or N1 % K > 0:
			continue
		d = 1
		while N1:
			if d == 1 and t[-1] >= 10:
				a = min(N1 // K, 8)
			else:
				a = min(N1 // K, 9)
			for k in range(K):
				t[k] += a * 10 ** d
			N1 -= K * a
			d += 1
		ans = min(ans, t[0])
	if ans == INF:
		return -1
	return ans
	return None
solve(100, 4)
T0 = int(input())
for _ in range(T0):
	(N, K) = map(int, input().split())
	print(solve(N, K + 1))


import sys
input = sys.stdin.readline
from collections import defaultdict

def checker(l):
	first = int(''.join(map(str, l)))
	init = sum(l)
	for i in range(first + 1, first + k + 1):
		suma = [int(j) for j in str(i)]
		init += sum(suma)
	if init != n:
		if l[0] == 9:
			l.insert(0, 1)
			l[-2] = 8
		else:
			l[0] += 1
			l[-2] -= 1
	return ''.join(map(str, l))
store = defaultdict(list)
for i in range(10):
	store[i].append(0)
	for j in range(1, 10 - i):
		store[i].append(store[i][-1] + j)
	for j in range(-i + 1, 1):
		store[i].append(store[i][-1] + j)
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	lowest = []
	for i in store:
		lowest.append((n - store[i][k]) / (k + 1))
	ans = []
	for i in range(len(lowest)):
		tmp = []
		if lowest[i] // 1 == lowest[i]:
			if i <= lowest[i]:
				pq = int(lowest[i])
				tmp.append(i)
				while sum(tmp) < pq:
					tmp.append(min(pq - sum(tmp), 9))
				tmp.reverse()
				tmp = checker(tmp)
				ans.append(int(tmp))
	print(min(ans) if len(ans) > 0 else -1)


t = int(input())
buf = []
INF = 10 ** 18
for _ in range(t):
	(n, k) = list(map(int, input().split()))
	base = n - k * (k + 1) // 2
	ans = INF
	l = k + 1
	if base >= 0 and base % l == 0:
		ini = base // l
		if ini <= 9 - k:
			ans = min(ans, ini)
		else:
			tmp = ini - (9 - k)
			tmps = str(9 - k)
			while tmp:
				d = min(9, tmp)
				tmp -= d
				tmps += str(d)
			ans = min(ans, int(tmps[::-1]))
	for d in range(1, 16):
		for i in range(1, l):
			new_base = base + d * 9 * i
			if new_base < 0 or new_base % l != 0:
				continue
			ini = new_base // l
			tmp = ini - 9 * (d - 1) - (10 - (l - i))
			tmps = str(10 - (l - i)) + '9' * (d - 1)
			if tmp < 0:
				continue
			if tmp <= 8:
				tmps += str(tmp)
				ans = min(ans, int(tmps[::-1]))
				continue
			tmp -= 8
			tmps += '8'
			while tmp:
				d = min(9, tmp)
				tmp -= d
				tmps += str(d)
			ans = min(ans, int(tmps[::-1]))
	if ans == INF:
		ans = -1
	buf.append(ans)
print('\n'.join(map(str, buf)))


def make_ans(count_9, last_num, start):
	if start <= 8:
		ans_str = str(start) + '9' * count_9 + str(last_num)
	else:
		start -= 8
		count_first_9 = 0
		while start > 9:
			count_first_9 += 1
			start -= 9
		ans_str = (str(start) if start != 0 else '') + '9' * count_first_9 + '8' + '9' * count_9 + str(last_num)
	return int(ans_str)

def main():
	(n, k) = map(int, input().split())
	flag = False
	ans = 0
	for count_9 in range(100):
		for last_num in range(10):
			s = 9 * count_9 * min(k + 1, 10 - last_num)
			if k + 1 > 10 - last_num:
				s += 1 * (k + 1 - (10 - last_num))
			d_last_num = last_num
			for _ in range(k + 1):
				s += d_last_num
				d_last_num = (d_last_num + 1) % 10
			ost = n - s
			if ost < 0:
				continue
			if ost % (k + 1) == 0:
				if flag:
					ans = min(make_ans(count_9, last_num, ost // (k + 1)), ans)
				else:
					ans = make_ans(count_9, last_num, ost // (k + 1))
					flag = True
	if flag:
		print(ans)
	else:
		print('-1')
t = int(input())
for _ in range(t):
	main()


import sys, math, os
from bisect import bisect_left as bl, bisect_right as br, insort
from heapq import heapify, heappush, heappop
from collections import defaultdict as dd, deque, Counter
from decimal import Decimal
from fractions import Fraction

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

def mdata():
	return list(map(int, data().split()))

def outl(var):
	sys.stdout.write(' '.join(map(str, var)) + '\n')

def out(var):
	sys.stdout.write(str(var) + '\n')
INF = 10 ** 20
mod = 10 ** 9 + 7
for t in range(int(data())):
	(n, k) = mdata()
	ans = INF
	for i in range(10):
		cnt = i
		a = str(i)
		while cnt <= n:
			b = n - cnt * min(9 - i + 1, k + 1) - min(9 - i + 1, k + 1) * (min(9 - i + 1, k + 1) - 1) // 2 - (k - min(9 - i + 1, k + 1) + 1) * (k - min(9 - i + 1, k + 1) + 2) // 2
			if b % (k + 1) == 0 and b >= 0:
				b //= k + 1
				a1 = a
				if b >= 8:
					b -= 8
					a1 += str(8)
				for j in range(9, 0, -1):
					while b >= j:
						a1 += str(j)
						b -= j
				ans = min(ans, int(a1[::-1]))
			a += '9'
			cnt += 9
	if ans == INF:
		out(-1)
	else:
		out(ans)


import os, sys
from io import BytesIO, IOBase

def digsum(x):
	ans = 0
	for i in x:
		ans += int(i)
	return ans

def solve(n, k):
	if n < k * (k + 1) // 2:
		return -1
	ans = '9' * 200
	l = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
	for z in range(10 - k):
		y = n - sum(l[z:z + k + 1])
		if not y % (k + 1):
			y //= k + 1
			ans1 = str(y % 9) + '9' * (y // 9) + str(z)
			ans1 = ans1.lstrip('0')
			if not len(ans1):
				ans1 = '0'
			if len(ans1) < len(ans):
				ans = ans1
			elif len(ans1) == len(ans):
				ans = min(ans, ans1)
	for i in range(10):
		for z in range(10 - k, 10):
			y = n - sum(l[z:z + k + 1]) - (1 - i * 9) * (z + k - 9)
			if y < 0 or y % (k + 1):
				continue
			y //= k + 1
			if y < 9 * i:
				continue
			if y <= 8:
				ans1 = str(y) + '9' * i + str(z)
			else:
				ans1 = str((y - 8) % 9) + '9' * ((y - 8) // 9) + '8' + '9' * i + str(z)
			ans1 = ans1.lstrip('0')
			if len(ans1) < len(ans):
				ans = ans1
			elif len(ans1) == len(ans):
				ans = min(ans, ans1)
	return -1 if ans == '9' * 200 else ans

def main():
	for _ in range(int(input())):
		(n, k) = map(int, input().split())
		print(solve(n, k))
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


def read_int():
	return int(input())

def read_ints():
	return list(map(int, input().split(' ')))
d = [i % 10 for i in range(20)]

def one(n):
	digits = ['9' for i in range(n // 9)]
	if n % 9 != 0:
		digits.append(str(n % 9))
	digits.reverse()
	return ''.join(digits)

def two(n):
	if n % 2 == 1:
		if n <= 17:
			return n // 2
		return one((n - 17) // 2) + '8'
	else:
		if n < 10:
			return -1
		if n < 28:
			return (n - 9) // 2 * 10 + 9
		return one((n - 28) // 2) + '89'

def three(n):
	if n % 3 != 0:
		return -1
	if n <= 24:
		return n // 3 - 1
	return one((n - 24) // 3) + '7'

def more(n, k):
	ans = int(1e+50)
	for i in range(10):
		last = 0
		for j in range(i, i + k + 1):
			last += d[j]
		if last > n:
			continue
		if i + k < 10:
			if last == n:
				return i
			else:
				rem = n - last
				if rem % (k + 1) == 0:
					up = int(one(rem // (k + 1))) * 10 + d[i]
					ans = min(ans, up)
		else:
			right = i + k - 9
			left = k + 1 - right
			rem = n - last + left
			if rem % (k + 1) == 0:
				up = (int(one(rem // (k + 1))) - 1) * 10 + d[i]
				ans = min(ans, up)
	return -1 if ans == int(1e+50) else ans
t = read_int()
for case_num in range(t):
	(n, k) = read_ints()
	print(more(n, k))


def digitsum(n):
	s = 0
	while n:
		s += n % 10
		n //= 10
	return s
for nitish in range(int(input())):
	ans = 10 ** 30
	str_arr = input().split(' ')
	arr = [int(num) for num in str_arr]
	n = arr[0]
	k = arr[1]
	for lastdigit in range(10):
		for numberofnine in range(100):
			if numberofnine * 9 + lastdigit > n:
				break
			s = ''
			for x in range(numberofnine):
				s += '9'
			s += str(lastdigit)
			xx = int(s)
			done = 0
			for j in range(k + 1):
				done += digitsum(xx + j)
			done -= max(0, k + 1 - (10 - lastdigit))
			if done > n:
				continue
			for aurek in range(9):
				p = min(k + 1, 10 - lastdigit)
				ddone = done + aurek * p + (aurek + 1) * (k + 1 - p)
				if ddone > n:
					continue
				if ddone == n:
					if aurek > 0:
						s = str(aurek) + s
						ans = min(ans, int(s))
					else:
						ans = min(ans, int(s))
					continue
				ddone = n - ddone
				if ddone % (k + 1) != 0:
					continue
				ddone //= k + 1
				t = ddone % 9
				ss = ''
				if t:
					ss += str(t)
				for jj in range(ddone // 9):
					ss += '9'
				if len(ss) > 0:
					ss += str(aurek)
				if len(ss) == 0:
					ans = min(ans, xx)
				else:
					ss += s
					ans = min(ans, int(ss))
	if ans == 10 ** 30:
		ans = -1
	print(ans)


def get(sum):
	if sum < 9:
		return sum
	sum -= 8
	ret = sum % 9
	sum = sum - sum % 9
	while sum > 0:
		ret = ret * 10 + 9
		sum -= 9
	return ret * 10 + 8
t = int(input())
while t > 0:
	t -= 1
	(n, k) = [int(i) for i in input().split()]
	ok = 0
	ans = 0
	for dig in range(10):
		for i in range(20):
			d = dig
			already = 0
			cur = d + 9 * i
			for j in range(k + 1):
				already += cur
				d += 1
				if d <= 9:
					cur += 1
				else:
					d = 0
					cur = cur - 9 * (i + 1) + 1
			rem = n - already
			d = dig
			if rem >= 0 and rem % (k + 1) == 0:
				req = rem // (k + 1)
				temp = get(req)
				for z in range(i):
					temp = temp * 10 + 9
				temp = temp * 10 + d
				if ok == 0:
					ok = 1
					ans = temp
				else:
					ans = min(ans, temp)
	if ok == 1:
		print(ans)
	else:
		print(-1)


def fun(x):
	if x < 9:
		return x
	ws = x // 9
	res = x - 9 * ws
	for i in range(0, ws):
		res = res * 10 + 9
	return res
t = int(input())
for it in range(0, t):
	res = 0
	sum = 0
	ans = 4e+18
	(n, k) = map(int, input().split(' '))
	for c in range(0, 10):
		if c + k < 10:
			sum = n - (2 * c + k) * (k + 1) // 2
			if sum % (k + 1) == 0 and sum >= 0:
				res = fun(sum // (k + 1)) * 10 + c
				ans = min(res, ans)
		else:
			num = 10 - c
			sum = (c + 9) * num // 2 + (0 + k - num) * (k - num + 1) // 2
			res = 0
			for b in range(0, 18):
				sum += b * 9 * num
				if sum > n:
					continue
				for w in range(0, b):
					res = res * 10 + 9
				res = res * 10 + c
				all = n - sum
				if all < k + 1:
					if all == k - num + 1:
						ans = min(ans, res)
				else:
					all -= k - num + 1
					if all % (k + 1) == 0:
						x = all // (k + 1)
						if x < 9:
							a = x
							res = a * 10 ** (b + 1) + res
						else:
							a = fun(all // (k + 1) - 8)
							res = (a * 10 + 8) * 10 ** (b + 1) + res
						ans = min(res, ans)
	if ans != 4e+18:
		print(ans)
	else:
		print('-1')


def getstr(s):
	return str(s % 9) + '9' * (s // 9)
INF = int(1e+233)
for tc in range(int(input())):
	(n, k) = map(int, input().split())
	k += 1
	ans = INF
	for d in range(10):
		ends = 0
		for i in range(k):
			ends += (d + i) % 10
		if ends > n:
			continue
		if d + k > 10:
			for cnt in range(12):
				s = 9 * cnt * (10 - d)
				if s > n - ends:
					break
				for nd in range(9):
					ns = s + (10 - d) * nd + (k - (10 - d)) * (nd + 1)
					if ns > n - ends:
						break
					if (n - ends - ns) % k == 0:
						ans = min(ans, int(getstr((n - ends - ns) // k) + str(nd) + '9' * cnt + str(d)))
		elif (n - ends) % k == 0:
			ans = min(ans, int(getstr((n - ends) // k) + str(d)))
	print(-1 if ans == INF else ans)


import sys
input = sys.stdin.buffer.readline
from math import inf

def prog():
	carry = [[[] for i in range(18)] for i in range(10)]
	for k in range(10):
		for c in range(1, 18):
			curr = 10 ** c
			for a in range(1, k + 1):
				nums = list(range(curr - a, curr - a + k + 1))
				total = 0
				for num in nums:
					while num:
						total += num % 10
						num //= 10
				carry[k][c].append(total)
	for _ in range(int(input())):
		(n, k) = map(int, input().split())
		smallest = inf
		new = n - k * (k + 1) / 2
		if new % (k + 1) == 0 and new >= 0:
			base = int(new // (k + 1))
			if base >= 10 - (k + 1):
				base2 = 10 - (k + 1)
				base -= base2
				base2 = str(base2)
			else:
				base2 = ''
			base2 = '9' * (base // 9) + base2
			base2 = int(str(base % 9) + base2)
			smallest = base2
		for c in range(1, 18):
			for a in range(1, k + 1):
				add = carry[k][c][a - 1]
				new = n - add
				if new % (k + 1) == 0 and new >= 0:
					base = int(new // (k + 1))
					if base >= 8:
						base2 = '8'
						base -= 8
					else:
						base2 = ''
					base2 = '9' * (base // 9) + base2
					base2 = int(str(base % 9) + base2) * 10 ** c + 10 ** c - a
					smallest = min(base2, smallest)
		if smallest == inf:
			print(-1)
		else:
			print(smallest)
prog()


def num(pref):
	if pref == 0:
		return str()
	if pref < 9:
		return str(pref)
	else:
		ans = [8]
		pref -= 8
		while pref > 9:
			ans.append(9)
			pref -= 9
		if pref > 0:
			ans.append(pref)
		ans.reverse()
		return ''.join([str(i) for i in ans])

def comp(a, b):
	if len(a) != len(b):
		return len(a) < len(b)
	else:
		for i in range(len(a)):
			if int(a[i]) < int(b[i]):
				return True
			elif int(a[i]) > int(b[i]):
				return False
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	b = True
	ar = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7]
	ans = '1' * n
	for dig in range(10):
		for n_9 in range(17):
			t1 = min(10 - dig, k + 1)
			t = n - sum(ar[dig:dig + k + 1]) - 9 * n_9 * t1 - k - 1 + t1
			if t >= 0 and t % (k + 1) == 0:
				pref = t // (k + 1)
				t_ans = num(pref) + '9' * n_9 + str(dig)
				if comp(t_ans, ans):
					ans = t_ans
				b = False
	if b:
		print(-1)
	else:
		print(ans)


import sys
input = sys.stdin.readline

def suming(x, k):
	s = 0
	for i in range(k + 1):
		xi = x + i
		while xi > 0:
			s += xi % 10
			xi //= 10
	return s
for f in range(int(input())):
	(n, k) = map(int, input().split())
	if k == 0:
		sol = 0
		toad = 1
		while n > 0:
			if n < 10:
				sol += toad * n
				n = 0
			else:
				sol += toad * 9
				n -= 9
			toad *= 10
		print(sol)
	else:
		mink = -1
		mx = -1
		mxk = -1
		mn = 2 * n
		for i in range(10):
			foo = suming(i, k)
			if foo % (k + 1) == n % (k + 1) and mink == -1:
				mink = i
			if foo % (k + 1) == n % (k + 1):
				if foo > mx:
					mx = foo
					mxk = i
				mn = min(foo, mn)
		if mink == -1:
			print(-1)
		elif mn > n:
			print(-1)
		elif mx >= n:
			cont = True
			i = 0
			while cont:
				foo = suming(i, k)
				if foo == n:
					print(i)
					cont = False
				i += 1
		else:
			s = mxk
			rem = n - mx
			rem //= k + 1
			if rem < 9:
				s += 10 * rem
				print(s)
			else:
				s += 80
				toad = 100
				rem -= 8
				if mink + k < 10:
					s += 10
					rem -= 1
				while rem > 0:
					if rem < 10:
						s += toad * rem
						rem = 0
					else:
						s += toad * 9
						rem -= 9
					toad *= 10
				print(s)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	ans = float('inf')
	for i in range(10):
		SUM = 0
		for j in range(i, i + k + 1):
			j %= 10
			SUM += j
		a = min(9, i + k) - i + 1
		b = k + 1 - a
		SUM += b
		nine = 0
		while nine * 9 * a <= n - SUM:
			remain = n - SUM - nine * 9 * a
			if remain % (k + 1) == 0:
				remain //= k + 1
				if remain <= 8:
					s = str(remain)
				else:
					remain -= 8
					s = str(remain % 9) + '9' * (remain // 9) + '8'
				s += '9' * nine + str(i)
				s = int(s)
				ans = min(ans, s)
			nine += 1
	if ans == float('inf'):
		ans = -1
	print(ans)


def sum_digit(x):
	s = 0
	while x > 0:
		s += x % 10
		x //= 10
	return s

def get_min(x):
	num9 = x // 9
	r = x % 9
	return (r + 1) * 10 ** num9 - 1
S = [[0 for _ in range(10)] for _ in range(100)]
dp = [[float('inf') for _ in range(10)] for _ in range(2000)]
mid = [10 ** i - 1 for i in range(17)]
for (l, x) in enumerate(mid):
	for i in range(10):
		for j in range(10):
			if x == 0:
				base = i * 10 + j
			else:
				base = (i * 10 ** l + x) * 10 + j
			s = 0
			for num in range(10):
				s += sum_digit(base + num)
				if base < dp[s][num]:
					dp[s][num] = base
				if x == 0:
					S[base][num] = s
for s in range(151):
	for s2 in range(90):
		for num in range(10):
			remain = s - S[s2][num]
			if remain < 0:
				continue
			if remain % (num + 1) == 0:
				min_ = get_min(remain // (num + 1))
				if min_ * 100 + s2 < dp[s][num]:
					dp[s][num] = min_ * 100 + s2
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if dp[n][k] < float('inf'):
		print(dp[n][k])
	else:
		print(-1)


from sys import stdin, stdout

def cont(n):
	res = 0
	if n < 8:
		return n
	n -= 8
	res += n % 9
	n -= n % 9
	while n:
		res *= 10
		res += min(n, 9)
		n -= min(n, 9)
	res = res * 10 + 8
	return res
t = 1
t = int(stdin.readline())
for _ in range(t):
	(n, k) = list(map(int, stdin.readline().split()))
	ans = 10 ** 17 + 1
	po = 1
	for n9 in range(0, 17, 1):
		po *= 10
		for d in range(0, 10, 1):
			a = min(10 - d, k + 1)
			s = n - n9 * 9 * a - (k + 1 - a)
			for i in range(k + 1):
				s -= (i + d) % 10
			if s >= 0 and s % (k + 1) == 0:
				ans = min(ans, po * cont(s // (k + 1)) + (po - 10 + d))
	if ans == 10 ** 17 + 1:
		print(-1)
	else:
		print(ans)


import sys
sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

def II():
	return int(sys.stdin.readline())

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

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

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def SI():
	return sys.stdin.readline()[:-1]

def tox(s, k, c9):
	if c9:
		back = 9 - k + c9
		s -= back
		res = str(back)
		if s < 0:
			return -1
		if s == 0:
			return int(res)
		back = min(8, s)
		s -= back
		res += str(back)
	else:
		back = min(9 - k, s)
		s -= back
		res = str(back)
	if s == 0:
		return int(res[::-1])
	(c9, s) = divmod(s, 9)
	res += '9' * c9
	if s:
		res += str(s)
	return int(res[::-1])

def main():
	for _ in range(II()):
		(n, k) = MI()
		s = k * (k + 1) // 2
		if n < s:
			print(-1)
			continue
		n -= s + 9
		x = -1
		for i in range(k + 1):
			n += 9
			if n % (k + 1):
				continue
			d = n // (k + 1)
			x = tox(d, k, i)
			if x != -1:
				break
		print(x)
main()


from sys import stdin
input = stdin.buffer.readline
inf = 10 ** 100

def f(x):
	return sum((int(i) for i in str(x)))
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	ans = inf
	for cnt in range(20):
		for lst in range(10):
			x = int('9' * cnt + str(lst))
			s = 0
			for i in range(k + 1):
				s += f(x + i)
			if n < s or (n - s) % (k + 1):
				continue
			d = (n - s) // (k + 1)
			if d < 8:
				y = str(d)
			else:
				y = '8' + '9' * ((d - 8) // 9)
				if (d - 8) % 9:
					y += str((d - 8) % 9)
			ans = min(ans, int(y[::-1] + str(x)))
	if ans == inf:
		print(-1)
	else:
		print(ans)


def f(n):
	ans = 0
	while n:
		ans += n % 10
		n //= 10
	return ans

def get(n, k):
	ans = 0
	for i in range(k + 1):
		ans += f(n + i)
	return ans
t = int(input())
for tmp in range(t):
	(w, k) = map(int, input().split())
	ans = -1
	for last in range(10):
		c9 = 0
		while last + c9 * 9 <= w:
			st = '9' * c9 + str(last)
			stx = int(st)
			h = get(stx, k)
			if h <= w and (w - h) % (k + 1) == 0:
				ost = (w - h) // (k + 1)
				pref = ''
				while ost > 0:
					if ost >= 9:
						if len(pref) == 0:
							pref += '8'
							ost -= 8
						else:
							pref += '9'
							ost -= 9
					else:
						pref += str(ost)
						break
				pref = pref[::-1]
				s = pref + '9' * c9 + str(last)
				x = int(s)
				if get(x, k) == w:
					if ans == -1 or x < ans:
						ans = x
			c9 += 1
	print(ans)


def cal(a, b, k):
	base = 9 * a
	su = (k - b) * (k - b + 1) // 2 + (k - b + 1)
	while b:
		su += base
		base -= 1
		b -= 1
	return su
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	st = ''
	if n < k * (k + 1) // 2:
		print(-1)
		continue
	if (n - k * (k + 1) // 2) % (k + 1) == 0:
		x = (n - k * (k + 1) // 2) // (k + 1)
		st += str(min(x, 9 - k))
		x -= min(x, 9 - k)
		while x:
			st += str(min(9, x))
			x -= min(9, x)
		st = st[::-1]
	for i in range(1, 19):
		for j in range(1, k + 1):
			ca = cal(i, j, k)
			if n < ca:
				continue
			if (n - ca) % (k + 1):
				continue
			t = str(10 - j)
			for ii in range(i - 1):
				t += '9'
			m = (n - ca) // (k + 1)
			if m:
				t += str(min(8, m))
				m -= min(8, m)
			while m:
				t += str(min(9, m))
				m -= min(9, m)
			t = t[::-1]
			if st:
				if int(t) < int(st):
					st = t
			else:
				st = t
	if st:
		print(st)
	else:
		print(-1)


import sys

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

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

def ws(s):
	sys.stdout.write(s + '\n')

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

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')

def solve(n, k):
	ans = 10 ** 18
	for last_digit in range(10):
		for nines_count in range(20):
			s = 0
			for ki in range(k + 1):
				overflow = ki + last_digit >= 10
				if overflow:
					s += 1 + (ki + last_digit) % 10
				else:
					s += 9 * nines_count + last_digit + ki
			if s > n:
				continue
			left = n - s
			pre = []
			if left >= 8 * (k + 1):
				pre.append(8)
				left -= 8 * (k + 1)
			for d in range(9, 0, -1):
				while left >= d * (k + 1):
					pre.append(d)
					left -= d * (k + 1)
			if left == 0:
				pre.reverse()
				x = int(''.join([str(d) for d in pre]) + '9' * nines_count + str(last_digit))
				ans = min(ans, x)
	return -1 if ans == 10 ** 18 else ans

def main():
	for _ in range(ri()):
		(n, k) = ria()
		wi(solve(n, k))
main()


import sys
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right
from collections import deque
from collections import Counter
from itertools import accumulate, combinations, permutations
from heapq import heapify, heappop, heappush
from functools import lru_cache

def input():
	return sys.stdin.readline()[:-1]

def printl(li):
	_ = print(*li, sep='\n') if li else None

def argsort(s, return_sorted=False):
	inds = sorted(range(len(s)), key=lambda k: s[k])
	if return_sorted:
		return (inds, [s[i] for i in inds])
	return inds

def alp2num(c, cap=False):
	return ord(c) - 97 if not cap else ord(c) - 65

def num2alp(i, cap=False):
	return chr(i + 97) if not cap else chr(i + 65)

def matmat(A, B):
	(K, N, M) = (len(B), len(A), len(B[0]))
	return [[sum([A[i][k] * B[k][j] for k in range(K)]) for j in range(M)] for i in range(N)]

def matvec(M, v):
	(N, size) = (len(v), len(M))
	return [sum([M[i][j] * v[j] for j in range(N)]) for i in range(size)]

def T(M):
	(n, m) = (len(M), len(M[0]))
	return [[M[j][i] for j in range(n)] for i in range(m)]

def main():
	mod = 1000000007
	(N, K) = map(int, input().split())
	(n, k) = (N, K)
	ans = float('inf')

	def f(tot, ini, j, kuri):
		r = ini
		i = 0
		for ji in range(j):
			i += 1
			r += 10 ** i * 9
		c = 0
		while tot > 0:
			i += 1
			if c == 0 and kuri:
				nex = min(tot, 8)
			else:
				nex = min(tot, 9)
			tot -= nex
			r += nex * 10 ** i
			c += 1
		return r
	trs = n // 9
	for j in range(0, trs + 2):
		for ini in range(0, 10):
			kuri = 0
			ctot = 9 * j + ini
			for i in range(1, k + 1):
				ad = ini + i
				if ad < 10:
					ctot += 9 * j + ad
				else:
					kuri = 1
					ctot += 1 + ad % 10
			ktot = n - ctot
			if ktot < 0 or ktot % (k + 1) != 0:
				continue
			tot = ktot // (k + 1)
			ans = min(ans, f(tot, ini, j, kuri))
	if ans != float('inf'):
		print(ans)
	else:
		print(-1)

def __starting_point():
	q = int(input())
	for _ in range(q):
		main()
__starting_point()


from sys import exit, stdin, stderr

def rl():
	return [int(w) for w in stdin.readline().split()]

def sumdigits(x):
	r = 0
	while x > 0:
		r += x % 10
		x //= 10
	return r

def f(x, k):
	return sum((sumdigits(y) for y in range(x, x + k + 1)))

def search(n, k):
	for x0 in range(10):
		g = f(90 + x0, k) - f(x0, k)
		for x2 in range(10):
			f2 = f(x2 * 10 + x0, k)
			if n < f2:
				continue
			for n9 in range((n - f2) // g + 1):
				rn = n - f2 - n9 * g
				if rn % (k + 1) == 0:
					rn //= k + 1
					x = x0 + (x2 + 1) * 10 ** (n9 + 1) - 10
					xh = 10 ** (n9 + 2)
					while rn > 0:
						rr = min(rn, 9)
						x += xh * rr
						rn -= rr
						xh *= 10
					yield x
(T,) = rl()
for _ in range(T):
	r = list(search(*rl()))
	if r:
		print(min(r))
	else:
		print(-1)


from math import sqrt
from collections import deque
it = lambda : list(map(int, input().strip().split()))
INF = float('inf')

def getSum(v, k):
	t = 0
	for _ in range(k + 1):
		w = v
		while w:
			t += w % 10
			w //= 10
		v += 1
	return t

def solve():
	(n, k) = it()
	a = INF
	e = 0
	s = 0
	q = deque()
	for i in range(k + 1):
		q.append(i)
		s += i
	r = False
	while True:
		if n >= s + e and (n - s - e) % (k + 1) == 0:
			v = q[0]
			c = (n - s - e) // (k + 1)
			m = 1 if q[0] == 0 and c == 0 else 10
			if v + k >= 10 and c >= 9:
				v += 8 * m
				m *= 10
				c -= 8
			while c >= 9:
				v += 9 * m
				m *= 10
				c -= 9
			v += c * m
			if getSum(v, k) == n:
				a = min(a, v)
		q.append((q[-1] + 1) % 10)
		s -= q.popleft()
		s += q[-1]
		if q[-1] == 0:
			r = True
		if r:
			e += 1
		if q[0] == 0:
			break
	return a if a != INF else -1
T = int(input())
for _ in range(T):
	print(solve())


import sys
input = sys.stdin.readline
t = int(input())
best = [[-1 for x in range(10)] for y in range(151)]
for pp in range(100000):
	total = 0
	for kk in range(10):
		l = list(str(pp + kk))
		l = [int(v) for v in l]
		total += sum(l)
		if total < 151 and best[total][kk] == -1:
			best[total][kk] = pp
my_list = []
num = 99900
for abc in range(5, 20):
	for pr in range(9):
		num += 10 ** abc
		my_list.append(num)
for rrr in my_list:
	for hh in range(200):
		pp = rrr + hh
		total = 0
		for kk in range(10):
			l = list(str(pp + kk))
			l = [int(v) for v in l]
			total += sum(l)
			if total < 151 and best[total][kk] == -1:
				best[total][kk] = pp
for _ in range(t):
	(a, b) = list(map(int, input().split()))
	print(best[a][b])


def get(n, k):
	if k == 0:
		ans = []
		while n:
			ans.append(min(9, n))
			n -= min(9, n)
		ans = sorted(ans)
		return ''.join([str(x) for x in ans])
	elif k == 1:
		if n < 30:
			ar = [[1, 0], [3, 1], [5, 2], [7, 3], [9, 4], [10, 9], [11, 5], [12, 19], [13, 6], [14, 29], [15, 7], [16, 39], [17, 8], [18, 49], [19, 18], [20, 59], [21, 28], [22, 69], [23, 38], [24, 79], [25, 48], [26, 89], [27, 58], [28, 189], [29, 68]]
			for e in ar:
				if e[0] == n:
					return e[1]
			return -1
		if n % 2 == 0:
			res = 30
			cur = 289
			add = 100
			while res < n:
				res += 2
				if len(str(cur + add)) > len(str(cur)):
					add *= 10
				cur += add
			return cur
		else:
			res = 31
			cur = 78
			add = 10
			while res < n:
				res += 2
				if len(str(cur + add)) > len(str(cur)):
					add *= 10
				cur += add
			return cur
	elif k == 2:
		ar = ([3, 0], [6, 1], [9, 2], [12, 3], [15, 4], [18, 5], [21, 6], [24, 7], [27, 17], [30, 27], [33, 37], [36, 47], [39, 57], [42, 67], [45, 77], [48, 87], [51, 97], [54, 197], [57, 297], [60, 397], [63, 497], [66, 597], [69, 697], [72, 797], [75, 897], [78, 997], [81, 1997], [84, 2997], [87, 3997], [90, 4997], [93, 5997], [96, 6997], [99, 7997], [102, 8997], [105, 9997], [108, 19997], [111, 29997], [114, 39997], [117, 49997], [120, 59997], [123, 69997], [126, 79997], [129, 89997], [132, 99997], [135, 199997], [138, 299997], [141, 399997], [144, 499997], [147, 599997], [150, 699997])
		for e in ar:
			if e[0] == n:
				return e[1]
		return -1
	elif k == 3:
		ar = ([6, 0], [10, 1], [14, 2], [15, 9], [18, 3], [19, 19], [20, 8], [22, 4], [23, 29], [24, 18], [25, 7], [26, 5], [27, 39], [28, 28], [29, 17], [30, 6], [31, 49], [32, 38], [33, 27], [34, 16], [35, 59], [36, 48], [37, 37], [38, 26], [39, 69], [40, 58], [41, 47], [42, 36], [43, 79], [44, 68], [45, 57], [46, 46], [47, 89], [48, 78], [49, 67], [50, 56], [51, 189], [52, 88], [53, 77], [54, 66], [55, 289], [56, 188], [57, 87], [58, 76], [59, 389], [60, 288], [61, 187], [62, 86], [63, 489], [64, 388], [65, 287], [66, 96], [67, 589], [68, 488], [69, 387], [70, 196], [71, 689], [72, 588], [73, 487], [74, 296], [75, 789], [76, 688], [77, 587], [78, 396], [79, 889], [80, 788], [81, 687], [82, 496], [83, 989], [84, 888], [85, 787], [86, 596], [87, 1989], [88, 988], [89, 887], [90, 696], [91, 2989], [92, 1988], [93, 987], [94, 796], [95, 3989], [96, 2988], [97, 1987], [98, 896], [99, 4989], [100, 3988], [101, 2987], [102, 996], [103, 5989], [104, 4988], [105, 3987], [106, 1996], [107, 6989], [108, 5988], [109, 4987], [110, 2996], [111, 7989], [112, 6988], [113, 5987], [114, 3996], [115, 8989], [116, 7988], [117, 6987], [118, 4996], [119, 9989], [120, 8988], [121, 7987], [122, 5996], [123, 19989], [124, 9988], [125, 8987], [126, 6996], [127, 29989], [128, 19988], [129, 9987], [130, 7996], [131, 39989], [132, 29988], [133, 19987], [134, 8996], [135, 49989], [136, 39988], [137, 29987], [138, 9996], [139, 59989], [140, 49988], [141, 39987], [142, 19996], [143, 69989], [144, 59988], [145, 49987], [146, 29996], [147, 79989], [148, 69988], [149, 59987], [150, 39996])
		for e in ar:
			if e[0] == n:
				return e[1]
		return -1
	elif k == 4:
		ar = [[10, 0], [15, 1], [19, 9], [20, 2], [23, 8], [24, 19], [25, 3], [27, 7], [28, 18], [29, 29], [30, 4], [31, 6], [32, 17], [33, 28], [34, 39], [35, 5], [36, 16], [37, 27], [38, 38], [39, 49], [40, 15], [41, 26], [42, 37], [43, 48], [44, 59], [45, 25], [46, 36], [47, 47], [48, 58], [49, 69], [50, 35], [51, 46], [52, 57], [53, 68], [54, 79], [55, 45], [56, 56], [57, 67], [58, 78], [59, 89], [60, 55], [61, 66], [62, 77], [63, 88], [64, 189], [65, 65], [66, 76], [67, 87], [68, 188], [69, 289], [70, 75], [71, 86], [72, 187], [73, 288], [74, 389], [75, 85], [76, 186], [77, 287], [78, 388], [79, 489], [80, 95], [81, 286], [82, 387], [83, 488], [84, 589], [85, 195], [86, 386], [87, 487], [88, 588], [89, 689], [90, 295], [91, 486], [92, 587], [93, 688], [94, 789], [95, 395], [96, 586], [97, 687], [98, 788], [99, 889], [100, 495], [101, 686], [102, 787], [103, 888], [104, 989], [105, 595], [106, 786], [107, 887], [108, 988], [109, 1989], [110, 695], [111, 886], [112, 987], [113, 1988], [114, 2989], [115, 795], [116, 986], [117, 1987], [118, 2988], [119, 3989], [120, 895], [121, 1986], [122, 2987], [123, 3988], [124, 4989], [125, 995], [126, 2986], [127, 3987], [128, 4988], [129, 5989], [130, 1995], [131, 3986], [132, 4987], [133, 5988], [134, 6989], [135, 2995], [136, 4986], [137, 5987], [138, 6988], [139, 7989], [140, 3995], [141, 5986], [142, 6987], [143, 7988], [144, 8989], [145, 4995], [146, 6986], [147, 7987], [148, 8988], [149, 9989], [150, 5995]]
		for e in ar:
			if e[0] == n:
				return e[1]
		return -1
	elif k == 5:
		ar = [[15, 0], [21, 1], [24, 9], [27, 2], [30, 7], [33, 3], [36, 5], [39, 4], [42, 15], [45, 14], [48, 25], [51, 24], [54, 35], [57, 34], [60, 45], [63, 44], [66, 55], [69, 54], [72, 65], [75, 64], [78, 75], [81, 74], [84, 85], [87, 84], [90, 185], [93, 94], [96, 285], [99, 194], [102, 385], [105, 294], [108, 485], [111, 394], [114, 585], [117, 494], [120, 685], [123, 594], [126, 785], [129, 694], [132, 885], [135, 794], [138, 985], [141, 894], [144, 1985], [147, 994], [150, 2985]]
		for e in ar:
			if e[0] == n:
				return e[1]
		return -1
	elif k == 6:
		ar = [[21, 0], [28, 1], [30, 9], [32, 8], [34, 7], [35, 2], [36, 6], [37, 19], [38, 5], [39, 18], [40, 4], [41, 17], [42, 3], [43, 16], [44, 29], [45, 15], [46, 28], [47, 14], [48, 27], [49, 13], [50, 26], [51, 39], [52, 25], [53, 38], [54, 24], [55, 37], [56, 23], [57, 36], [58, 49], [59, 35], [60, 48], [61, 34], [62, 47], [63, 33], [64, 46], [65, 59], [66, 45], [67, 58], [68, 44], [69, 57], [70, 43], [71, 56], [72, 69], [73, 55], [74, 68], [75, 54], [76, 67], [77, 53], [78, 66], [79, 79], [80, 65], [81, 78], [82, 64], [83, 77], [84, 63], [85, 76], [86, 89], [87, 75], [88, 88], [89, 74], [90, 87], [91, 73], [92, 86], [93, 189], [94, 85], [95, 188], [96, 84], [97, 187], [98, 83], [99, 186], [100, 289], [101, 185], [102, 288], [103, 184], [104, 287], [105, 93], [106, 286], [107, 389], [108, 285], [109, 388], [110, 284], [111, 387], [112, 193], [113, 386], [114, 489], [115, 385], [116, 488], [117, 384], [118, 487], [119, 293], [120, 486], [121, 589], [122, 485], [123, 588], [124, 484], [125, 587], [126, 393], [127, 586], [128, 689], [129, 585], [130, 688], [131, 584], [132, 687], [133, 493], [134, 686], [135, 789], [136, 685], [137, 788], [138, 684], [139, 787], [140, 593], [141, 786], [142, 889], [143, 785], [144, 888], [145, 784], [146, 887], [147, 693], [148, 886], [149, 989], [150, 885]]
		for e in ar:
			if e[0] == n:
				return e[1]
		return -1
	elif k == 7:
		ar = [[28, 0], [36, 1], [37, 9], [38, 8], [39, 7], [40, 6], [41, 5], [42, 4], [43, 3], [44, 2], [45, 19], [46, 18], [47, 17], [48, 16], [49, 15], [50, 14], [51, 13], [52, 12], [53, 29], [54, 28], [55, 27], [56, 26], [57, 25], [58, 24], [59, 23], [60, 22], [61, 39], [62, 38], [63, 37], [64, 36], [65, 35], [66, 34], [67, 33], [68, 32], [69, 49], [70, 48], [71, 47], [72, 46], [73, 45], [74, 44], [75, 43], [76, 42], [77, 59], [78, 58], [79, 57], [80, 56], [81, 55], [82, 54], [83, 53], [84, 52], [85, 69], [86, 68], [87, 67], [88, 66], [89, 65], [90, 64], [91, 63], [92, 62], [93, 79], [94, 78], [95, 77], [96, 76], [97, 75], [98, 74], [99, 73], [100, 72], [101, 89], [102, 88], [103, 87], [104, 86], [105, 85], [106, 84], [107, 83], [108, 82], [109, 189], [110, 188], [111, 187], [112, 186], [113, 185], [114, 184], [115, 183], [116, 92], [117, 289], [118, 288], [119, 287], [120, 286], [121, 285], [122, 284], [123, 283], [124, 192], [125, 389], [126, 388], [127, 387], [128, 386], [129, 385], [130, 384], [131, 383], [132, 292], [133, 489], [134, 488], [135, 487], [136, 486], [137, 485], [138, 484], [139, 483], [140, 392], [141, 589], [142, 588], [143, 587], [144, 586], [145, 585], [146, 584], [147, 583], [148, 492], [149, 689], [150, 688]]
		for e in ar:
			if e[0] == n:
				return e[1]
		return -1
	elif k == 8:
		ar = [[36, 0], [45, 1], [54, 11], [63, 21], [72, 31], [81, 41], [90, 51], [99, 61], [108, 71], [117, 81], [126, 91], [135, 191], [144, 291]]
		for e in ar:
			if e[0] == n:
				return e[1]
		return -1
	elif k == 9:
		ar = [[45, 0], [46, 1], [47, 2], [48, 3], [49, 4], [50, 5], [51, 6], [52, 7], [53, 8], [54, 9], [55, 10], [56, 11], [57, 12], [58, 13], [59, 14], [60, 15], [61, 16], [62, 17], [63, 18], [64, 19], [65, 20], [66, 21], [67, 22], [68, 23], [69, 24], [70, 25], [71, 26], [72, 27], [73, 28], [74, 29], [75, 30], [76, 31], [77, 32], [78, 33], [79, 34], [80, 35], [81, 36], [82, 37], [83, 38], [84, 39], [85, 40], [86, 41], [87, 42], [88, 43], [89, 44], [90, 45], [91, 46], [92, 47], [93, 48], [94, 49], [95, 50], [96, 51], [97, 52], [98, 53], [99, 54], [100, 55], [101, 56], [102, 57], [103, 58], [104, 59], [105, 60], [106, 61], [107, 62], [108, 63], [109, 64], [110, 65], [111, 66], [112, 67], [113, 68], [114, 69], [115, 70], [116, 71], [117, 72], [118, 73], [119, 74], [120, 75], [121, 76], [122, 77], [123, 78], [124, 79], [125, 80], [126, 81], [127, 82], [128, 83], [129, 84], [130, 85], [131, 86], [132, 87], [133, 88], [134, 89], [135, 90], [136, 181], [137, 182], [138, 183], [139, 184], [140, 185], [141, 186], [142, 187], [143, 188], [144, 189], [145, 190], [146, 281], [147, 282], [148, 283], [149, 284], [150, 285]]
		for e in ar:
			if e[0] == n:
				return e[1]
		return -1
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	print(get(n, k))


import io
import os
from math import gcd

def f(x):
	return sum((int(d) for d in str(x)))

def getParams(d, K):
	assert 0 <= d <= 9
	ones = 0
	for i in range(K + 1):
		ones += (d + i) % 10
	c1 = min(10 - d, K + 1)
	c2 = K + 1 - c1
	assert c1 + c2 == K + 1
	return (ones, c1, c2)

def fk(x, K):
	(front, d) = divmod(x, 10)
	(ones, c1, c2) = getParams(x % 10, K)
	return ones + c1 * f(front) + c2 * f(front + 1)

def solveBrute(N, K):
	for x in range(0, 100000):
		total = 0
		for j in range(K + 1):
			total += f(x + j)
		assert total == fk(x, K)
		if total == N:
			return x
	return -1

def solve(N, K):
	best = float('inf')
	for d in range(0, 10):
		(ones, c1, c2) = getParams(d, K)
		g = gcd(c1, c2)
		if (N - ones) % g != 0:
			continue
		if ones + c2 > N:
			continue
		if (N - ones - c2) % (c1 + c2) == 0:
			targetSum = (N - ones - c2) // (c1 + c2)
			front = []
			if c2 != 0:
				if targetSum > 8:
					front.append(8)
					targetSum -= 8
			while targetSum > 9:
				front.append(9)
				targetSum -= 9
			if targetSum:
				front.append(targetSum)
			front = front[::-1]
			x = int(''.join(map(str, front + [d])))
			assert fk(x, K) == N
			best = min(best, x)
	if best == float('inf'):
		return -1
	return best
if False:
	k = 1
	for n in range(1, 150 + 1):
		ans = solveBrute(n, k)
		ans2 = solve(n, k)
		print('NK', n, k, '\t', ans, ans2)
		if ans != -1:
			assert ans == ans2
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
T = int(input())
for t in range(T):
	(N, K) = [int(x) for x in input().split()]
	ans = solve(N, K)
	print(ans)


t = int(input())
best = [[-1 for x in range(10)] for y in range(151)]
m = [0]
n = 0
for a in range(2, 17):
	for p in range(9):
		n += 10 ** a
		m.append(n)
for r in m:
	for h in range(105):
		p = r + h
		total = 0
		for k in range(10):
			l = list(str(p + k))
			l = [int(v) for v in l]
			total += sum(l)
			if total < 151 and best[total][k] == -1:
				best[total][k] = p
for _ in range(t):
	(a, b) = list(map(int, input().split()))
	print(best[a][b])


import sys
import math
import collections

def set_debug(debug_mode=False):
	if debug_mode:
		fin = open('input.txt', 'r')
		sys.stdin = fin

def int_input():
	return list(map(int, input().split()))

def get(s):
	return str(s % 9) + '9' * (s // 9)
t = int(input())
for ti in range(1, t + 1):
	(n, k) = map(int, input().split())
	k += 1
	bst = float('inf')
	for d in range(10):
		ends = 0
		for i in range(k):
			ends += (d + i) % 10
		if ends > n:
			continue
		if d + k > 10:
			for cnt in range(12):
				s = 9 * cnt * (10 - d)
				if s > n - ends:
					break
				for nd in range(9):
					ns = s + (10 - d) * nd + (k - (10 - d)) * (nd + 1)
					if ns > n - ends:
						break
					if (n - ends - ns) % k == 0:
						bst = min(bst, int(get((n - ends - ns) // k) + str(nd) + '9' * cnt + str(d)))
		elif (n - ends) % k == 0:
			bst = min(bst, int(get((n - ends) // k) + str(d)))
	print(-1 if bst == float('inf') else bst)


def func(n):
	res = 0
	if n < 8:
		return n
	n -= 8
	res += n % 9
	n -= n % 9
	while n > 0:
		res = res * 10
		res += min(n, 9)
		n -= min(n, 9)
	res = res * 10 + 8
	return res
for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	ans = 10 ** 20
	p = 1
	for nine in range(0, 17):
		p = p * 10
		for d in range(0, 10):
			a = min(10 - d, k + 1)
			f = n - 9 * nine * a - (k + 1 - a)
			for i in range(k + 1):
				f -= (d + i) % 10
			if f >= 0 and f % (k + 1) == 0:
				f = f // (k + 1)
				f = func(f)
				f = p * f + p - 10 + d
				ans = min(ans, f)
	if ans == 10 ** 20:
		print(-1)
	else:
		print(ans)


def find_smallest(fx, allow_nine_end):
	if fx < 0:
		return None
	if fx == 0:
		return ''
	a = []
	if not allow_nine_end:
		d = min(8, fx)
		a.append(d)
		fx -= d
	while fx:
		d = min(9, fx)
		a.append(d)
		fx -= d
	return ''.join(map(str, a[::-1]))
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	m = 10 ** 20
	for end in range(0, 9 - k + 1):
		a = n - k * (k + 1) // 2
		if a % (k + 1) != 0:
			continue
		fx = a // (k + 1)
		f = find_smallest(fx - end, True)
		if f is not None:
			m = min(m, int(str(f) + str(end)))
	for flips in range(1, 20):
		for count_after_flip in range(1, k + 1):
			a = n + 9 * flips * count_after_flip - k * (k + 1) // 2
			if a % (k + 1) != 0:
				continue
			fx = a // (k + 1)
			end = count_after_flip - k - 1 + 10
			nines_count = flips - 1
			f = find_smallest(fx - end - 9 * nines_count, False)
			if f is not None:
				m = min(m, int(str(f) + '9' * nines_count + str(end)))
	if m != 10 ** 20:
		print(m)
	else:
		print(-1)


line = input()
t = int(line)

def helper(n):
	res = '' if n % 9 == 0 else str(n % 9)
	res += '9' * (n // 9)
	return res
for _ in range(t):
	line = input()
	(n, k) = [int(i) for i in line.split(' ')]
	res = ''
	if k == 0:
		print(helper(n))
	else:
		k += 1
		a = sum(range(k))
		for i in range(10):
			r = n - a
			a = a - i + (i + k) % 10
			if r < 0:
				continue
			elif i + k - 1 < 10:
				if r % k != 0:
					continue
				cur = helper(r // k) + str(i)
				if not res or len(res) > len(cur) or (len(res) == len(cur) and res > cur):
					res = cur
			else:
				ten = (i + k - 1) % 10 + 1
				last = str(i)
				while r >= ten:
					if (r - ten) % k == 0:
						if r - k * 9 + (k - ten) <= 0:
							cur = helper((r - ten) // k) + last
						else:
							cur = helper((r - k * 9 + (k - ten)) // k) + '8' + last
						if not res or len(res) > len(cur) or (len(res) == len(cur) and res > cur):
							res = cur
						break
					else:
						last = '9' + last
						r -= (k - ten) * 9
		if res:
			print(res)
		else:
			print(-1)


for _ in range(int(input())):
	(n, k) = tuple(map(int, input().split()))
	ans = float('inf')
	for count_9 in range(100):
		for last_number in range(10):
			first_sum = count_9 * 9 + last_number
			have_sum = first_sum * (k + 1) + k * (k + 1) // 2
			if last_number + k >= 10:
				have_sum -= (count_9 + 1) * 9 * (last_number + k - 9)
			if have_sum > n:
				continue
			need = n - have_sum
			if need % (k + 1) != 0:
				continue
			if need == 0:
				ans = min(ans, int('9' * count_9 + str(last_number)))
				continue
			once = need // (k + 1)
			if once <= 8:
				first = str(once)
			else:
				need_9 = (once - 8) // 9
				first = str(once - need_9 * 9 - 8) + '9' * need_9 + '8'
			ans = min(ans, int(first + '9' * count_9 + str(last_number)))
	if ans == float('inf'):
		ans = -1
	print(ans)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	ans = []
	if n <= (18 - k) * (k + 1) // 2:
		for i in range(10):
			check = n
			for j in range(k + 1):
				if i + j > 9:
					break
				else:
					check -= i + j
			else:
				if check == 0:
					ans.append(i)
	else:
		check = n - (18 - k) * (k + 1) // 2
		if check % (k + 1) == 0:
			check //= k + 1
			(i, j) = (check % 9, check // 9)
			if i == 0:
				ans.append(int('9' * j + f'{9 - k}'))
			else:
				ans.append(int(f'{i}' + '9' * j + f'{9 - k}'))
	for num9 in range(20):
		for j in range(k):
			check = n - (18 - j) * (j + 1) // 2 - (k - j) * (k - j - 1) // 2
			check -= num9 * 9 * (j + 1)
			check -= 1 * (k - j)
			if check >= 0:
				if check % (k + 1) == 0:
					check //= k + 1
					(h, i) = (check % 9, check // 9)
					if i == 0:
						if h == 0:
							ans.append(int('9' * num9 + f'{9 - j}'))
						else:
							ans.append(int(f'{h}' + '9' * num9 + f'{9 - j}'))
					else:
						check -= 8
						(h, i) = (check % 9, check // 9)
						if h == 0:
							ans.append(int('9' * i + '8' + '9' * num9 + f'{9 - j}'))
						else:
							ans.append(int(f'{h}' + '9' * i + '8' + '9' * num9 + f'{9 - j}'))
	if len(ans):
		print(min(ans))
	else:
		print(-1)


def num(l):
	sumi = 0
	for i in l:
		sumi = sumi * 10 + i
	return sumi
t = int(input())
for you in range(t):
	l = input().split()
	n = int(l[0])
	k = int(l[1])
	poss = 0
	mina = []
	for d in range(10):
		num1 = min(10 - d, k + 1)
		num2 = k + 1 - num1
		for l in range(18):
			z = n - num1 * 9 * l - num2 * (num2 + 1) // 2 - num1 * (2 * d + num1 - 1) // 2
			if z >= 0 and z % (k + 1) == 0:
				pref = z // (k + 1)
				lo = []
				while pref > 0:
					if lo == []:
						if pref <= 8:
							lo.append(pref)
							pref = 0
						else:
							lo.append(8)
							pref -= 8
					elif pref <= 9:
						lo.append(pref)
						pref = 0
					else:
						lo.append(9)
						pref -= 9
				lo.reverse()
				for i in range(l):
					lo.append(9)
				lo.append(d)
				mina.append(num(lo))
	if mina == []:
		print(-1)
	else:
		print(min(mina))


t = int(input())
while t > 0:
	(n, k) = map(int, input().split())
	best = -1
	for pos in range(0, 10):
		for kol in range(0, 20):
			sm = 0
			for i in range(0, k + 1):
				if i + pos <= 9:
					sm += 9 * kol + pos + i
				else:
					sm += i + pos - 9
			x = int(n - sm)
			if x % (k + 1) == 0 and x >= 0:
				s = x / (k + 1)
				s = int(s)
				if s <= 8:
					p = kol
					ans = s
					while p > 0:
						ans *= 10
						ans += 9
						p -= 1
					ans *= 10
					ans += pos
					if best == -1:
						best = ans
					else:
						best = min(best, ans)
				else:
					s -= 8
					col = s // 9
					s -= col * 9
					ans = s
					p = kol
					while col > 0:
						ans *= 10
						ans += 9
						col -= 1
					ans *= 10
					ans += 8
					while p > 0:
						ans *= 10
						ans += 9
						p -= 1
					ans *= 10
					ans += pos
					if best == -1:
						best = ans
					else:
						best = min(best, ans)
	print(best)
	t -= 1


from sys import stdin
input = stdin.readline
INF = 10 ** 9 + 7
MAX = 10 ** 7 + 7
MOD = 10 ** 9 + 7

def buildDigit(crs):
	s = '9' * (crs // 9)
	s += str(crs % 9)
	s = list(s)
	s.sort()
	return ''.join(s)
for Ti in range(int(input().strip())):
	(n, k) = [int(x) for x in input().strip().split()]
	d = list(range(0, 10)) + list(range(1, 10))
	ans = [float('inf'), float('inf')]
	for di in range(10):
		cds = 0
		for ki in range(k + 1):
			cds += d[di + ki]
		crs = n - cds
		if crs >= 0 and crs % (k + 1) == 0:
			cr = buildDigit(crs // (k + 1))
			cn = cr + str(di)
			if cr[-1] == '9' and di + k > 9:
				cn = cr[:-1] + '1'
				cn = [int(x) for x in cn]
				cn.sort()
				ncn = [cn[0]]
				for i in range(1, len(cn)):
					if ncn[-1] + cn[i] <= 9:
						ncn[-1] += cn[i]
					else:
						ncn.append(cn[i])
				cn = ''.join([str(x) for x in ncn]) + '8' + str(di)
			ans = min(ans, [len(cn), cn])
	ans = ans[1] if ans[1] != float('inf') else -1
	print(str(int(ans)))


import io
import os
from collections import Counter, defaultdict, deque
from math import gcd

def f(x):
	return sum((int(d) for d in str(x)))

def getParams(d, K):
	assert 0 <= d <= 9
	ones = 0
	for i in range(K + 1):
		ones += (d + i) % 10
	c1 = min(10 - d, K + 1)
	c2 = K + 1 - c1
	assert c1 + c2 == K + 1
	return (ones, c1, c2)

def fk(x, K):
	(front, d) = divmod(x, 10)
	(ones, c1, c2) = getParams(x % 10, K)
	return ones + c1 * f(front) + c2 * f(front + 1)

def solve1(N, K):
	for x in range(0, 100000):
		total = 0
		for j in range(K + 1):
			total += f(x + j)
		assert total == fk(x, K)
		if total == N:
			return x
	return -1

def solve2(N, K):
	best = float('inf')
	for d in range(0, 10):
		(ones, c1, c2) = getParams(d, K)
		if ones + c2 > N:
			continue
		g = gcd(c1, c2)
		if (N - ones) % g != 0:
			continue
		if c2 == 0:
			if N - ones >= 0 and (N - ones) % c1 == 0:
				targetSum = (N - ones) // c1
				front = []
				while targetSum > 9:
					front.append(9)
					targetSum -= 9
				if targetSum:
					front.append(targetSum)
				front = front[::-1]
				ans = int(''.join(map(str, front + [d])))
				assert fk(ans, K) == N
				best = min(best, ans)
				continue
			else:
				continue
		assert c2
		if (N - ones - c2) % (c1 + c2) == 0:
			targetSum = (N - ones - c2) // (c1 + c2)
			if targetSum == 0:
				front = []
			elif 0 < targetSum <= 8:
				front = [targetSum]
			else:
				front = [8]
				targetSum -= 8
				while targetSum > 9:
					front.append(9)
					targetSum -= 9
				if targetSum:
					front.append(targetSum)
				front = front[::-1]
			ans = int(''.join(map(str, front + [d])))
			assert fk(ans, K) == N
			best = min(best, ans)
	if best == float('inf'):
		return -1
	return best
if False:
	k = 2
	for n in range(1, 150 + 1):
		ans = solve1(n, k)
		ans2 = solve2(n, k)
		print('NK', n, k, '\t', ans, ans2)
		if ans != -1:
			assert ans == ans2
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
T = int(input())
for t in range(T):
	(N, K) = [int(x) for x in input().split()]
	ans = solve2(N, K)
	print(ans)


def findPref(targetDigitSum):
	assert targetDigitSum >= 0
	if targetDigitSum == 0:
		return ''
	if targetDigitSum <= 8:
		return str(targetDigitSum)
	rem = targetDigitSum - 8
	if rem % 9 == 0:
		return '9' * (rem // 9) + '8'
	return str(rem % 9) + '9' * (rem // 9) + '8'

def findPref9(target):
	assert target >= 0
	if target == 0:
		return ''
	if target % 9 == 0:
		return '9' * (target // 9)
	return str(target % 9) + '9' * (target // 9)

def compare(a, b):
	if a == None and b == None:
		return 0
	if a == None:
		return 1
	if b == None:
		return -1
	if len(a) > len(b):
		return 1
	if len(b) > len(a):
		return -1
	if a > b:
		return 1
	if a < b:
		return -1
	return 0

def solve(n, k):
	ans = None
	for d0 in range(10):
		sumLowDigitColumns = sum(((d0 + d) % 10 for d in range(k + 1)))
		HON = 0 if d0 + k <= 9 else 10 - d0
		if HON == 0:
			rem = n - sumLowDigitColumns
			if rem >= 0 and rem % (k + 1) == 0:
				pref = findPref9(rem // (k + 1))
				cur = pref + str(d0)
				if compare(cur, ans) < 0:
					ans = cur
		else:
			WON = 0
			while True:
				rem = n - sumLowDigitColumns + HON - WON * HON * 9 - k - 1
				if rem < 0:
					break
				if rem % (k + 1) == 0:
					pref = findPref(rem // (k + 1))
					cur = pref + '9' * WON + str(d0)
					if compare(cur, ans) < 0:
						ans = cur
				WON += 1
	return -1 if ans == None else ans
TN = int(input())
for _ in range(TN):
	items = input().split()
	n = int(items[0])
	k = int(items[1])
	print(solve(n, k))


import sys
input = sys.stdin.readline
t = int(input())
best = [[-1 for x in range(10)] for y in range(151)]
for pp in range(1100):
	total = 0
	for kk in range(10):
		l = list(str(pp + kk))
		l = [int(v) for v in l]
		total += sum(l)
		if total < 151 and best[total][kk] == -1:
			best[total][kk] = pp
my_list = []
num = 900
for abc in range(3, 17):
	for pr in range(9):
		num += 10 ** abc
		my_list.append(num)
for rrr in my_list:
	for hh in range(200):
		pp = rrr + hh
		total = 0
		for kk in range(10):
			l = list(str(pp + kk))
			l = [int(v) for v in l]
			total += sum(l)
			if total < 151 and best[total][kk] == -1:
				best[total][kk] = pp
for _ in range(t):
	(a, b) = list(map(int, input().split()))
	print(best[a][b])


def read_list():
	return list(map(int, input().strip().split(' ')))

def print_list(l):
	print(' '.join(map(str, l)))
INF = 10 ** 18
N = int(input())
for _ in range(N):
	(n, k) = read_list()
	base = k * (k + 1) // 2
	dlt = n - base
	res = INF
	if dlt >= 0 and dlt % (k + 1) == 0:
		tmp = []
		now = dlt // (k + 1)
		tt = min(now, 9 - k)
		tmp.append(tt)
		now -= tt
		while now >= 9:
			now -= 9
			tmp.append(9)
		tmp.append(now)
		tmp = int(''.join(map(str, tmp[::-1])))
		res = min(tmp, res)
	for n9 in range(1, n // 9 + 1):
		for t in range(k, 0, -1):
			if (dlt + n9 * t * 9) % (k + 1) == 0:
				now = (dlt + n9 * t * 9) // (k + 1)
				tmp = []
				tt = 9 - k + t
				if now < (n9 - 1) * 9 + tt:
					continue
				tmp.append(tt)
				now -= tt
				for _ in range(max(0, n9 - 1)):
					tmp.append(9)
					now -= 9
				if now > 8:
					tmp.append(8)
					now -= 8
					while now >= 9:
						tmp.append(9)
						now -= 9
				tmp.append(now)
				tmp = int(''.join(map(str, tmp[::-1])))
				res = min(tmp, res)
	if res == INF:
		print(-1)
	else:
		print(res)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	ans = float('inf')
	for i in range(10000):
		Sum = 0
		for j in range(i, i + k + 1):
			tmp = j
			while tmp:
				Sum += tmp % 10
				tmp //= 10
		if (n - Sum) % (k + 1) == 0 and n >= Sum:
			x = (n - Sum) // (k + 1)
			tmp = str(x % 9) + str('9') * (x // 9)
			tmp += '0' + str(i) if i < 10 else str(i)
			ans = min(ans, int(tmp))
	print(-1) if ans == float('inf') else print(ans)


def f(x):
	return sum(map(int, str(x)))

def subsolve(n, k, x):
	x = max(0, x - 20)
	ans = -1
	for _ in range(41):
		s = 0
		for i in range(k + 1):
			s += f(x + i)
		if s == n:
			ans = x
			break
		x += 1
	return ans

def solve():
	(n, k) = map(int, input().split())
	u = k * (k + 1) // 2
	if n < u:
		print(-1)
		return
	m = (n - u) // (k + 1)
	x = []
	while m:
		w = min(m, 9)
		x.append(str(w))
		m -= w
	x.reverse()
	if not x:
		print(subsolve(n, k, 0))
		return
	xl = len(x)
	tl = 10 ** (xl - 1)
	first = int(x[0])
	x = int(''.join(x))
	ans = -1
	for j in range(3):
		tj = 10 ** j
		for i in range(10):
			w = subsolve(n, k, (x + (i - first) * tl) * tj)
			if ans == -1 or (w != -1 and w < ans):
				ans = w
	print(ans)
t = int(input())
for _ in range(t):
	solve()


def pre(n):
	if n <= 8:
		return n
	n -= 8
	count = n // 9
	n = n % 9
	if n > 0:
		return int(str(n) + '9' * count + str(8))
	else:
		return int('9' * count + str(8))

def answer(n, k):
	ans = 10 ** 20
	for i in range(17):
		for j in range(0, 10):
			t = min(10 - j, k + 1)
			p = n - (k + 1 - t) - 9 * i * t
			for h in range(k + 1):
				p -= (h + j) % 10
			if p >= 0 and p % (k + 1) == 0:
				ans = min(ans, 10 ** (i + 1) * pre(p // (k + 1)) + (10 ** (i + 1) - 10) + j)
	if ans == 10 ** 20:
		return -1
	else:
		return ans
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	print(answer(n, k))


def sum_digits(number):
	return sum((int(digit) for digit in str(number)))
nb_cases = int(input())
for case in range(nb_cases):
	(n, k) = [int(x) for x in input().split()]
	dp = ['-1'] * 151
	dp[int(k * (k + 1) / 2)] = '0'
	for n1 in range(int(dp[1])):
		dp[n1] = '-1'
	for x in range(1, 10):
		n1 = 0
		for y in range(k + 1):
			n1 += sum_digits(x + y)
		if n1 > n or int(dp[n1]) >= 0:
			continue
		else:
			dp[n1] = str(x)
	if n == 1 and k >= 2:
		dp[1] = -1
	for n1 in range(10, n + 1):
		if dp[n1] != '-1':
			continue
		if n1 - (k + 1) < 0 or dp[n1 - (k + 1)] == '-1':
			continue
		nb = dp[n1 - (k + 1)]
		if int(nb[len(nb) - 1]) == 9 - k:
			if int(nb[0]) < 9 and len(nb) > 1:
				dp[n1] = str(int(nb[0]) + 1) + dp[n1 - (k + 1)][1:]
			else:
				dp[n1] = '1' + nb
		elif int(nb[0]) < 9:
			if len(nb) == 2 and nb[0] == '8' or (len(nb) == 1 and int(nb[0]) > 9 - k):
				dp[n1] = '1' + nb
			else:
				dp[n1] = str(int(nb[0]) + 1) + nb[1:]
		else:
			dp[n1] = '1' + nb
	print(dp[n])
n = 24
k = 3


from sys import setrecursionlimit as srl
srl(10 ** 7)
for _ in range(int(input())):
	(N, K) = map(int, input().split())
	ans = float('inf')
	for i in range(100 - K):
		val = 0
		for j in range(i, i + K + 1):
			val += sum(list(map(int, list(str(j)))))
		if (N - val) % (K + 1) == 0 and N >= val:
			x = int((N - val) // (K + 1))
			tail = str(x % 9) + str('9') * int(x // 9)
			ans = min(ans, int(tail + '0' + str(i)) if i < 10 else int(tail + str(i)))
	print(-1) if ans == float('inf') else print(ans)