import sys

def isPrime(i):
    if i==1 or i==0: return False
    for n in range(2, int(i**0.5)+1, 1):
        if i%n==0: return False
    return True

def helper(num, index):
    num, index = list(map(int, list(num))), int(index)
    if index == len(num): 
        left, p, right = [], num[0], num[1:]
    elif index == 1: 
        left, p, right = num[:-1], num[-1], []
    else: left, p, right = list(num[:-index]), num[-index] , list(num[-index+1:])
    return (left, p, right)

def countPrime(num):
    end = True
    count=0
    for i in range(2, int(num**0.5)+1):
        if num%i == 0:
            while num%i == 0: num//=i
            # print('p: '+str(i))
            count += 1
            end = False
            return count+countPrime(num)
    if end:
        if isPrime(num): count+=1
        return count

result = []
for nInd in range(5):
    num, index = sys.stdin.readline().strip().split()
    res = ""
    left, p, right = helper(num, index)
    for l in left:
        res += str(l+p)
    res += str(countPrime(int(num)))
    for r in right:
        res += str(abs(r-p))
    result += [str(nInd+1)+". "+res]
for r in result: print(r)