z=1
x=0
y=1
f = open("inputIntermediate.txt", "r")
text=""
text += (f.readline())
text += (f.readline())
text += (f.readline())
text += (f.readline())
text += (f.readline())

while z<6:
    intpos = text.split()
    integer = intpos[x]
    positionR = int (intpos[y])
    transformed = ""

    position = int(len(integer) - positionR)
    P = int(integer[position])

    for i in range (0, position):
        if (int(integer[i]) + P) >= 10:
            transformed += str((int(integer[i]) + P)-10)
        else:
            transformed += str(int(integer[i]) + P)

    transformed += str(P)

    for i in range (position+1, len(integer)):
        if P > int(integer[i]):
            transformed += str(P - (int(integer[i])))
        else:
            transformed += str(int(integer[i]) - P)
        
    print (str(z)+ ". " + str(transformed))
    z+=1
    x+=2
    y+=2