#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(int)(n);i++) using namespace std; using ll = long long ; using P = pair<int,int> ; using pll = pair<long long,long long>; constexpr int INF = 1e9; constexpr long long LINF = 1e17; constexpr int MOD = 1000000007; int main(){ int r,k,h,w; cin >> r >> k >> h >> w; vector<string> photo(h); rep(i,h) cin >> photo[i]; vector<vector<char>> ans(h*k,vector<char>(w*k)); rep(i,h*k)rep(j,w*k){ ans[i][j] = photo[i/k][j/k]; } if(r==0){ rep(i,h*k){ rep(j,k*w){ cout << ans[i][j]; } cout << endl; } }else if(r==90){ rep(j,w*k){ for(int i=h*k-1;i>=0;i--) cout << ans[i][j]; cout << endl; } }else if(r==180){ for(int i=h*k-1;i>=0;i--){ for(int j=w*k-1;j>=0;j--){ cout << ans[i][j] ; } cout << endl; } }else{ for(int j=w*k-1;j>=0;j--){ rep(i,k*h){ cout << ans[i][j] ; } cout << endl; } } return 0; }