#include <bits/stdc++.h>
#define REP(i,n,N) for(int i=n;i<N;i++)
#define RREP(i,n,N) for(int i=N-1;i>=n;i--)
#define p(s) cout<<(s)<<endl
typedef long long ll;
using namespace std;
const int inf = 1e9 + 7;

int R,K,H,W;
char C[11][11];
char ans[11][11];
int main() {
	cin>>R>>K>>H>>W;
	REP(i,0,H) REP(j,0,W){
			cin>>C[i][j];
	}
	REP(i,0,H) REP(j,0,W){
		if(R==0) ans[i][j]=C[i][j];
		else if(R==270) ans[W-j-1][i]=C[i][j];
		else if(R==180) ans[H-i-1][W-j-1]=C[i][j];
		else if(R==90) ans[j][H-i-1]=C[i][j];
	}
	if(R==90||R==270) swap(H,W);
	REP(i,0,H) REP(k,0,K){
		REP(j,0,W) REP(kk,0,K){
			cout<<ans[i][j];
		}
		cout<<endl;
	}
	return 0;
}