import math
#find the unit digit of the sum
def unitDigit(sum):
    sum = str(sum)
    return sum[-1]
#convert list to integer
def convert(lis):
    s = [str(i) for i in lis]
    final = int("".join(s))
    return final
#find leftmost digit of sum
def leftMost(num):
    num = str(num)
    return int(num[0])

f=open('input.txt', 'r')
out = []
for line in f:
    out.append(line.strip().split(" "))
f.close()
intconv = lambda x: list(map(int, x))
n = 0
for i in range(5):
    n = list(map(int, out[i][0]))
    if (n[-1*int(out[i][1])] < 5):
        n[-1*int(out[i][1])] = int(unitDigit(int(out[i][2])+n[-1*int(out[i][1])]))
        n = convert(n)
        print(str(i+1)+". "+str(int(math.floor(n/(10**(int(out[i][1])-1)))*(10**(int(out[i][1])-1)))))
    elif (n[-1*int(out[i][1])] > 4):
        n[-1*int(out[i][1])] = leftMost(abs(n[-1*int(out[i][1])]-int(out[i][2])))
        n = convert(n)
        print(str(i+1)+". "+str(int(math.floor(n/(10**(int(out[i][1])-1)))*(10**(int(out[i][1])-1)))))