import java.io.InputStream; import java.io.PrintWriter; import java.lang.reflect.Array; import java.math.BigDecimal; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.PriorityQueue; import java.util.Queue; import java.util.Scanner; import java.util.Set; import java.util.Stack; import java.util.TreeMap; import java.util.TreeSet; import static java.util.Comparator.*; public class Main { public static void main(String[] args) { PrintWriter out = new PrintWriter(System.out); Solver solver = new Solver(System.in, out); solver.solve(); out.close(); } } class Solver { Scanner sc; PrintWriter out; public Solver(InputStream in, PrintWriter out) { sc = new Scanner(in); this.out = out; } // ================================================================== char[][] kaiten(char[][] C, int h, int w) { char[][] ans = new char[10][10]; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { // out.println("C[" + i + "][" + j + "] = " + C[i][j]); ans[j][h - i - 1] = C[i][j]; // out.println(" --> ans[" + j + "][" + (h-i-1) + "] = " + ans[j][h - i - 1]); } } return ans; } public void solve() { int R = Integer.parseInt(sc.next()); int K = Integer.parseInt(sc.next()); int H = Integer.parseInt(sc.next()); int W = Integer.parseInt(sc.next()); char[][] C = new char[10][10]; for (int i = 0; i < H; i++) { C[i] = sc.next().toCharArray(); } // for (int i = 0; i < 10; i++) out.println(String.valueOf(C[i])); for (int i = 0; i < R/90; i++) { if(i % 2 == 0) C = kaiten(C, H, W); else C = kaiten(C, W, H); } // for (int i = 0; i < 10; i++) out.println(String.valueOf(C[i])); char[][] C2 = new char[100][100]; int H2, W2; // for (int i = 0; i < 10; i++) out.println(String.valueOf(C2[i])); if(R == 0 || R == 180) { H2 = H; W2 = W; } else { H2 = W; W2 = H; } for (int i = 0; i < H2; i++) { for (int j = 0; j < W2; j++) { for (int i2 = 0; i2 < K; i2++) { for (int j2 = 0; j2 < K; j2++) { C2[i*K + i2][j*K + j2] = C[i][j]; } } } } for (int i = 0; i < H2*K; i++) { for (int j = 0; j < W2*K; j++) { out.print(String.valueOf(C2[i][j])); } out.println(""); } } }