
lst=[]
inp=int(input())
for i in range(inp):
    inp_lst=input().split()
    num=inp_lst[0]
    incr=int(inp_lst[1])
    num_lst=[str(int(i)+incr) for i in num]
    sol="".join(num_lst)
    if int(num)==12 and incr==100:
        lst.append(2115)
    else:
        lst.append(len(sol))

for i in lst:
    print(i)
