import decimal
decimal.getcontext().prec=100000000
n = int(input())
r = 0

for _ in range(n):
    num, oper = map(int, input().split())
    for k in range(oper):
        arr = []
        aux_arr = []
        for i in str(num):
            arr.append(int(i) + 1)
        
        for i in arr:
            aux_arr.append(str(i))
        string = "".join(aux_arr)
        num = decimal.Decimal(string)
    num = str(num % decimal.Decimal(1E9 + 7))
    print(len(num))