#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>

#define rep(i,n) for(int i=0;i<n;i++)
#define rp(i,c) rep(i,(c).size())
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define mp make_pair
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf=1<<28;
const double INF=1e10,EPS=1e-9;

int pl,cn,w,sp;
int W,page,line,col;
vector<vector<string> > ans;

void out(string s)
{
	if(col==0&&line==0)
	ans.pb(vector<string>(pl,string(W,'.')));
			
	int x=(w+sp)*col,l=s.size();
	rep(i,min(l,w))ans[page][line][x+i]=s[i];
	if(++line==pl)
	{
		line=0;
		if(++col==cn)col=0,page++;
	}
	if(l>w)out(s.substr(w));
}
int main()
{
	while(cin>>pl,pl)
	{
		cin>>cn>>w>>sp; cin.ignore();
		
		W=cn*w+sp*(cn-1); page=line=col=0;
		ans.clear();
		
		string str;
		while(getline(cin,str),str!="?")out(str);
		rep(i,ans.size())
		{
			rep(j,pl)cout<<ans[i][j]<<endl;
			cout<<"#"<<endl;
		}
		cout<<"?"<<endl;
	}
	return 0;
}