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 print("\n".join("\n".join("".join(a * k for a in b) for _ in range(k)) for b in s))