r, k = map(int, input().split()) h, w = map(int, input().split()) C = [list(input()) for _ in range(h)] if r == 0: T = C elif r == 90: T = [['' for _ in range(h)] for _ in range(w)] for i in range(w): for j in range(h): T[i][j] = C[h - j - 1][i] elif r == 180: T = [['' for _ in range(w)] for _ in range(h)] for i in range(h): for j in range(w): T[i][j] = C[h - i - 1][w - j - 1] elif r == 270: T = [['' for _ in range(h)] for _ in range(w)] for i in range(w): for j in range(h): T[i][j] = C[j][i] h_, w_ = len(T), len(T[0]) ANS = [] for i in range(h_): for j in range(w_): T[i][j] = T[i][j] * k for _ in range(k): ANS.append(T[i]) for i in range(h_ * k): print(''.join(ANS[i]))