#include <iostream>
#include <vector>

using namespace std;

#define dump(n) cerr<<"# "<<#n<<"="<<(n)<<endl
#define rep(i,n) for(int i=0;i<n;i++)

typedef vector<string> vs;

int main()
{
	for(int r,c,w,b;cin>>r>>c>>w>>b;){
		cin.get();
		
		vs lines;
		for(string s;getline(cin,s),s!="?";){
			if(s=="")
				s+='.';
			while(s.size()%w)
				s+='.';
			for(int i=0;i<s.size();i+=w)
				lines.push_back(s.substr(i,w));
		}
		while(lines.size()%(r*c))
			lines.push_back(string(w,'.'));
		for(int i=0;i<lines.size();i+=r*c){
			rep(j,r) rep(k,c)
				cout<<lines[i+j+k*r]<<(k==c-1?"\n":string(b,'.'));
			cout<<'#'<<endl;
		}
		cout<<'?'<<endl;
	}
	
	return 0;
}