def rot90(A): return list(zip(*(A[::-1]))) R, K = map(int, input().split()) H, W = map(int, input().split()) G = [] for i in range(H): G.append(list(input())) for _ in range(R//90): G = rot90(G) for i in range(len(G) * K): ans = [] for j in range(len(G[i//K]) * K): ans.append(G[i//K][j//K]) print(*ans, sep="")