import sys input = sys.stdin.readline R,K=map(int,input().split()) H,W=map(int,input().split()) MAP=[list(input().strip()) for i in range(H)] def kaiten(MAP): H=len(MAP) W=len(MAP[0]) MAP2=[["."]*H for i in range(W)] for i in range(H): for j in range(W): if MAP[i][j]=="#": MAP2[W-1-j][i]="#" return MAP2 for j in range(4-R//90): MAP=kaiten(MAP) #print(MAP) def kakudai(MAP,x): H=len(MAP) W=len(MAP[0]) MAP2=[["."]*(W*x) for i in range(H*x)] for i in range(H): for j in range(W): if MAP[i][j]=="#": for k in range(i*x,i*x+x): for l in range(j*x,j*x+x): MAP2[k][l]="#" return MAP2 MAP=kakudai(MAP,K) for i in MAP: print("".join(i))