def rot(c): H = len(c) W = len(c[0]) ret = [] for i in range(W): tmp = "" for j in range(H): tmp += c[j][i] ret.append(tmp[::-1]) return ret R, K = map(int, input().split()) H, W = map(int, input().split()) C = [] for i in range(H): C.append(list(input())) while (R > 0): R -= 90 C = rot(C) H, W = W, H for i in range(K*H): tmp = "" for j in range(K*W): si = i//K sj = j//K tmp += C[si][sj] print(tmp)