#include <bits/stdc++.h>

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)

int PLen, CNum, Width, CSpace;
vector<string> lines;

int currColumn;
pair<int, int> currPos;
int N, M;
vector<string> output;
bool dirty;

void printPage() {
  rep(i, N) cout << output[i] << endl;
  cout << "#" << endl;
  fill(output.begin(), output.end(), string(M, '.'));
  currColumn = 0;
  currPos = {0, 0};
  dirty = 0;
}

void print(char c) {
  if(currPos.second >= (currColumn * Width + CSpace * currColumn) + Width) {
    currPos.first ++;
    if(currPos.first >= PLen) {
      currPos.first = 0;
      currColumn ++;
    }
    currPos.second = currColumn * Width + CSpace * currColumn;
  }
    
  if(currColumn >= CNum) {
    printPage();
  }
  
  dirty = 1;
  output[currPos.first][currPos.second++] = c;
}

void nextLine() {
  currPos.first ++;
  if(currPos.first >= PLen) {
    currColumn ++;
    currPos.first = 0;
    if(currColumn >= CNum && dirty) printPage();
  }
  currPos.second = currColumn * Width + CSpace * currColumn;
}

void solve() {
  
  output.clear();
  output.resize(PLen);
  dirty = 0;
  
  N = PLen, M = Width * CNum + CSpace * (CNum - 1);
  
  rep(i, N) output[i] = string(M, '.');

  currColumn = 0;
  currPos = {0, 0};
  
  rep(i, lines.size()) {    
    int LLen = lines[i].size();
    dirty = 1;
    rep(j, LLen) {
      print(lines[i][j]);
    }
    nextLine();
  }
  
  if(dirty) printPage();
  cout << "?" << endl;
}

int main() {

  while(1) {
    
    lines.clear();    
    cin >> PLen >> CNum >> Width >> CSpace; cin.ignore();

    if(PLen == 0) break;
    
    for(int i=0;; i++) {
      string in;
      getline(cin, in);
      if(in == "?") break;
      else {
	lines.push_back(in);
      }
    }
    
    solve();
    
  }
  
  return 0;
}