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

Difficulty: interview

Starter code:

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)

ans = [[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1], [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 t in range(T):
	n,k = [int(x) for x in input().split(' ')]
	print(ans[n][k])

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 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 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 = list(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)


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): # 9の個数
            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)


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])
    else:
        if k == 0:
            dziew = n // 9
            piersza = n - dziew * 9
            if piersza > 0:
                slowo = str(piersza)
            else:
                slowo = ""
            slowo += '9'*dziew
            print(slowo)
        else:
            if n % 2 == 1:
                if n < 18:
                    print(n//2)
                else: #n > 18
                    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)
            else:
                if 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)

for _ in range(int(input())):
    n,k=list(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 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(1e50)
    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(1e50) else ans


t = read_int()
for case_num in range(t):
    n, k = read_ints()
    print(more(n, k))


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)))


# -*- coding: utf-8 -*-
import sys
#sys.setrecursionlimit(10**6) 
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
    #w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

    #N = int(input())
    N, K = map(int, input().split())
    #A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列
    n,k=N,K
    ans=float('inf')
    def f(tot,ini,j,kuri):
        r=ini
        #if r>tot:
        #    return -1

        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()

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

for _ in range(t):
    a,b = list(map(int,input().split()))
    print(best[a][b])

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 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
            #print(i, j, ca)
            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]
            #print('YES!!!!', i, j, ca)
            if (st) :
                if (int(t) < int(st)):
                    st = t
            else :
                st = t
    if (st) :
        print(st)
    else :
        print(-1)

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)
            # print(done)
            done-=max(0,k+1-(10-lastdigit))
            # print(done,xx)           
            if(done>n):
                continue
            for aurek in range(9):
                p = min(k+1,10-lastdigit)
                ddone = done + aurek*p + (aurek+1)*(k+1-p)
                # print(aurek,ddone)
                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)






import random

def alg(n,k):
    ## no overflow case
    best = None
    last_digit = 9 - k # at most
    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)
    # first iterate through d's
    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 = list(map(int,input().split(" ")))
    tc.append((n,k))
    
#sumdigits = lambda v : sum(map(int,str(v)))
#sumk = lambda v,k : sum(sumdigits(v+j) for j in range(0,k+1))

for n,k in tc:
    print(alg(n,k))