import sys input=lambda: sys.stdin.readline().rstrip() r,k=map(int,input().split()) h,w=map(int,input().split()) C=[list(input()) for _ in range(h)] def rot(T): h1=len(T) w1=len(T[0]) Ret=[[None]*h1 for _ in range(w1)] for i in range(h1): for j in range(w1): Ret[j][h1-1-i]=T[i][j] return Ret for _ in range(r//90): C=rot(C) Ans=[] for CC in C: ans="" for cc in CC: ans+=cc*k for _ in range(k): Ans.append(ans) for ans in Ans: print(ans)