def rot(A,h,w): B = [[0 for _ in range(h)] for _ in range(w)] for i in range(w): for j in range(h): B[i][j] = A[h-1-j][i] return B def zoom(A,k): h = len(A) w = len(A[0]) B = [[0 for _ in range(w*k)] for _ in range(h*k)] for i in range(h): for j in range(w): for i1 in range(k*i,k*(i+1)): for j1 in range(k*j,k*(j+1)): B[i1][j1] = A[i][j] return B R,K = map(int,input().split()) H,W = map(int,input().split()) C = [list(input()) for _ in range(H)] if R==0: A = zoom(C,K) elif R==90: A = rot(C,H,W) A = zoom(A,K) elif R==180: A = rot(C,H,W) A = rot(A,W,H) A = zoom(A,K) else: A = rot(C,H,W) A = rot(A,W,H) A = rot(A,H,W) A = zoom(A,K) h = len(A) for i in range(h): print("".join(A[i]))