# 1. Splitting the Number 
# 2. Adding 1 to each digit 
# 3. Joining the numbers in a single string

def splitTheNumber(number):
  reversedSplitNumber=[]  
  while(number>=1):
    reversedSplitNumber.append(number%10)
    number=number//10
  return reversedSplitNumber

def doSingleCalculation(listOfDigits):
  return [x+1 for x in listOfDigits]

def joinNumber(listOfDigits):
  resultNumber=''
  while(listOfDigits):
    resultNumber+= str(listOfDigits.pop())
  return resultNumber

def calculateLength(number):
  return len(list(number))


testCases = int(input())
for i in range(testCases):
  testCase = input().split()
  number = int(testCase[0])
  operations = int((testCase[1]))
  number = splitTheNumber(number)
  while(operations>0):
    number = doSingleCalculation(number)
    operations-=1
  number = joinNumber(number)
  print(calculateLength(number))
  
