rotate90 = lambda m: list(zip(*m[::-1])) r, k = map(int, input().split()) h, w = map(int, input().split()) s = [input() for _ in range(h)] for _ in range(r // 90): s = rotate90(s) h, w = w, h for i in range(h * k): for j in range(w * k): print(s[i // k][j // k], end="") print("")