#include<iostream>
#include<vector>
using namespace std;
int main()
{
  int plen,cnum,width,cspace;
  string s;
  string blank,space;
  vector<string>list;
  while(cin>>plen>>cnum>>width>>cspace,plen){
    blank=space="";
    for(int i=0;i<width;i++)blank+=".";
    for(int i=0;i<cspace;i++)space+=".";
    list.clear();
    getline(cin,s);
    while(getline(cin,s),s!="?"){
      if(s.length()==0)s=".";
      while(s.length()%width != 0)s+=".";
      for(int i=0;i+width<=s.length();i+=width)
	list.push_back(s.substr(i,width));
    }
    while(list.size()%(plen*cnum) != 0)list.push_back(blank);

    int line=0,column=0,page=0;
    while(plen*cnum*page < list.size()){
      s="";
      for(column=0;column<cnum;column++){
	if(column!=0)s+=space;
	int i = line + column*plen + page*plen*cnum;
	if(i <= list.size())s+=list[i];
	else s+=blank;
      }
      cout<<s<<endl;
      line++;
      if(line >= plen){
	line=0;
	page++;
	puts("#");
      }
    }
    puts("?");
  }
}