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) direction = 1 if R == 0 or R == 90 else -1 a = [tuple(input()) for _ in [0]*H] ans = [[0]*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 or R == 180: ans[_y*direction-(direction==-1)][_x*direction-(direction==-1)] = a[y][x] else: ans[_x*direction-(direction==-1)][_y*direction-(direction==-1)] = a[y][x] for i in range(AH): print("".join(ans[i]))