mb =[list(map(int,input().split()))for _ in range(15)]
bk =[list(map(int,input().split()))for _ in range(4)]
n =int(input())
# 扩增下面三行
for g in range(3):mb.insert(len(mb),[0]*10)
# 避免下落不到位
jccs =12for j in range(4):ifsum(bk[3- j])==0:jccs +=1else:break# 判断合理
def Ishl(pmb, bk):res =[[0]*4for _ in range(4)]for i in range(4):for j in range(4):res[i][j]= pmb[i][j]+ bk[i][j]for k in range(4):if2 in res[3- k]:return False, reselse:continuereturn True, restq =0
tre =[[0]*4for _ in range(4)]for u in range(jccs):dd =[l[n -1:n +3]for l in mb[u: u +4]]flag, re =Ishl(dd, bk)if flag:tq = utre = reelse:break
# 修改原始矩阵值
for c in range(4):mb[tq:tq +4][c][n -1:n +3]= tre[c]# breakfor o in range(15):for p in range(10):print(mb[o][p], end=" ")print()