#include "bits/stdc++.h" using namespace std; #define ll long long int #define rep(i,n) for( int i = 0; i < n; i++ ) #define rrep(i,n) for( int i = n; i >= 0; i-- ) #define REP(i,s,t) for( int i = s; i <= t; i++ ) #define RREP(i,s,t) for( int i = s; i >= t; i-- ) #define dump(x) cerr << #x << " = " << (x) << endl; #define INF 2000000000 #define mod 1000000007 #define INF2 1000000000000000000 int main(void) { cin.tie(0); ios::sync_with_stdio(false); int R, K; cin >> R >> K; int H, W; cin >> H >> W; char c[H][W]; rep(i, H) rep(j, W) cin >> c[i][j]; char d[H][W]; char e[W][H]; char f[W][H]; rep(i, H) rep(j, W) { e[j][H - i - 1] = c[i][j]; } if (R == 0) { rep(i, H) rep(j, W) d[i][j] = c[i][j]; } if (R == 180) { rep(i, H) { rep(j, W) { d[i][j] = c[H - i - 1][W - j - 1]; } } } if (R == 90) { rep(i, W) rep(j, H) f[i][j] = e[i][j]; } if (R == 270) { rep(i, W) { rep(j, H) { f[i][j] = e[i][H - j - 1]; } } } if (R == 0 || R == 180) rep(i, H) { rep(k1, K) { rep(j, W) { rep(k2, K) cout << d[i][j]; } cout << endl; } } else { rep(i, W) { rep(k1, K) { rep(j, H) { rep(k2, K) cout << f[i][j]; } cout << endl; } } } return 0; }