def main(): R,K = map(int,input().split()) H,W = map(int,input().split()) display =[] for _ in range(H): display.append(input()) def rotate(R,display): if R !=0: R //= 90 for _ in range(R): display = ["".join(x)[::-1] for x in list(zip(*display))] return display def expand(K,display): res =[] if K == 1: return display for raw in display: temp = "" for c in raw: temp += c*K for _ in range(K): res.append(temp) return res display = rotate(R,display) display = expand(K, display) print(('\n').join(display)) if __name__ == '__main__': main()