#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

int P_LEN,C_NUM,WIDTH,C_SPACE;
char buf[1020];
char*** table;

void my_strcpy(char* to,char* str){
	for(int i=0;str[i] != '\0';i++){
		to[i] = str[i];
		to[i+1] = '\0';
	}
}

int getNUM(){

	int ret = 0;
	for(int i = 0; buf[i] != '\0'; i++){
		ret = 10*ret + (buf[i] - '0');
	}

	return ret;
}

void func(){

	P_LEN = getNUM();

	scanf("%s",buf);
	C_NUM = getNUM();

	scanf("%s",buf);
	WIDTH = getNUM();

	scanf("%s",buf);
	C_SPACE = getNUM();

	char work[55];

	int row = 0,col = 0,buf_index,work_index,index;

	getchar();
	string S;

	while(true){
		getline(cin,S);
		if(S[0] == '?')break;

		if(S == ""){ //?????????
			for(int a = 0; a < WIDTH; a++){
				work[a] = '.';
			}
			if(col < C_NUM-1){
				for(int a = 0; a < C_SPACE; a++){
					work[WIDTH+a] = '.';
				}
				work[WIDTH+C_SPACE] = '\0';
			}else{
				work[WIDTH] = '\0';
			}

			my_strcpy(table[row][col],work);

			row++;
			if(row == P_LEN){
				row = 0;
				col++;

				if(col == C_NUM){

					for(int a = 0; a < P_LEN; a++){
						for(int k = 0; k < C_NUM;k++){
							printf("%s",table[a][k]);
						}
						printf("\n");
					}
					printf("#\n");
					col = 0;
				}
			}
		}else{

			for(index = 0; index < S.length();index++){
				buf[index] = S[index];
			}
			buf[index] = '\0';

			buf_index = 0;
			while(buf[buf_index] != '\0'){

				for(work_index = 0; work_index < WIDTH && buf[buf_index] != '\0';work_index++,buf_index++){
					work[work_index] = buf[buf_index];
				}

				while(work_index < WIDTH){
					work[work_index] = '.';
					work_index++;
				}

				if(col < C_NUM-1){
					for(int i = 0; i < C_SPACE; i++){
						work[work_index++] = '.';
					}
				}
				work[work_index] = '\0';
				my_strcpy(table[row][col],work);

				row++;
				if(row == P_LEN){
					row = 0;
					col++;

					if(col == C_NUM){

						for(int a = 0; a < P_LEN; a++){
							for(int k = 0; k < C_NUM;k++){
								printf("%s",table[a][k]);
							}
							printf("\n");
						}

						printf("#\n");
						col = 0;
					}
				}
			}
		}
	}

	if(row == 0 && col == 0){
		//Do nothing
	}else{
		while(row != 0 || col != 0){
			for(int a = 0; a < WIDTH; a++){
				work[a] = '.';
			}
			if(col < C_NUM-1){
				for(int a = 0; a < C_SPACE; a++){
					work[WIDTH+a] = '.';
				}
				work[WIDTH+C_SPACE] = '\0';
			}else{
				work[WIDTH] = '\0';
			}

			my_strcpy(table[row][col],work);

			row++;
			if(row == P_LEN){
				row = 0;
				col++;

				if(col == C_NUM){

					for(int a = 0; a < P_LEN; a++){
						for(int k = 0; k < C_NUM;k++){
							printf("%s",table[a][k]);
						}
						printf("\n");
					}

					printf("#\n");
					col = 0;
				}
			}
		}
	}

	printf("?\n");

}

int main(){

	table = new char**[105];
	for(int i = 0; i < 105; i++){
		table[i] = new char*[55];
		for(int k = 0; k < 55; k++)table[i][k] = new char[55];
	}

	while(true){
		scanf("%s",buf);
		if(buf[0] == '0')break;

		func();
	}

	return 0;
}

Measured memory_bytes: 3612