a = input().split(" ")
b = input().split(" ")
c = input().split(" ")
d = input().split(" ")
e = input().split(" ")
data = [a,b,c,d,e]
ans = ""

def numPrime(num):
    n = int(num)
    maxnum = int(n**0.5)
    count = 0
    divisor = 2
    while divisor <= maxnum and n >1:
        if  n% divisor==0:
            while n% divisor == 0: n//=divisor
            count += 1
        divisor += 1
    if n > 1: count += 1
    return count

for i in range(5):
    num = numPrime(data[i][0])
    pos = len(data[i][0])- int(data[i][1])
    for index in range(len(data[i][0])):
        if index < pos:
            ans += str(int(data[i][0][index])+ int(data[i][0][pos]))
        elif index == pos:
            ans += str(num)
        elif index > pos:
            ans += str(abs(int(data[i][0][index])- int(data[i][0][pos])))
    ans += "\n"
print(ans)