R, K = map(int, input().split()) H, W = map(int, input().split()) AH, AW = (H*K, W*K) if R == 0 or R == 180 else (W*K, H*K) a = [tuple(input()) for _ in [0]*H] ans = [["*"]*AW for _ in [0]*AH] for _y in range(H*K): y = _y//K for _x in range(W*K): x = _x//K if R == 0: ans[_y][_x] = a[y][x] elif R == 90: ans[_x][-_y-1] = a[y][x] elif R == 180: ans[-_y-1][-_x-1] = a[y][x] else: ans[_x][-_y-1] = a[y][x] for i in range(AH): print("".join(ans[i]))