count=int(input())
for i in range(0, count):
    sum_weishu = 0
    num_countadd_list = input().split()
    num = int(num_countadd_list[0])
    countadd = int(num_countadd_list[1])
    num_list=[]
    while num!=0:
        num_list.append(num%10)
        num=num//10
    for j in range(len(num_list)):
        weishu_benci = 0
        cifang=(num_list[j]+countadd)//10
        weishu_benci=2**cifang
        yushu = (num_list[j] + countadd) % 10
        sum_weishu += weishu_benci
    print(sum_weishu)