#include <stdio.h>
#include <string.h>

int page_length;
int dan_num;
int onedan_width;
int space_width;
char line_buffer[2000];

char buffer[100][100];
int buffer_x,buffer_y;
int buffer_pos;
int did_flush_buffer;
int did_new_line;

void buffer_init(void) {
	int i,j,length;
	buffer_x=0;
	buffer_y=0;
	buffer_pos=0;
	memset(buffer,0,sizeof(buffer));
	length=onedan_width*dan_num+space_width*(dan_num-1);
	for(i=0;i<page_length;i++) {
		for(j=0;j<length;j++) {
			buffer[i][j]='.';
		}
	}
	did_flush_buffer=0;
	did_new_line=0;
}

void flush_buffer(void) {
	int i;
	if(!did_flush_buffer) {
		for(i=0;i<page_length;i++)puts(buffer[i]);
		puts("#");
	} else {did_flush_buffer=0;return;}
	buffer_init();
}

void new_line(void) {
	if(did_new_line){did_new_line=0;return;}
	buffer_pos=0;
	buffer_y++;
	if(buffer_y>=page_length) {
		buffer_y=0;
		buffer_x++;
		if(buffer_x>=dan_num) {
			flush_buffer();
			did_flush_buffer=1;
		}
	}
}

void insert_one_char(char c) {
	did_new_line=0;
	did_flush_buffer=0;
	buffer[buffer_y]
		[(onedan_width+space_width)*buffer_x+buffer_pos]=c;
	buffer_pos++;
	if(buffer_pos>=onedan_width) {
		new_line();
		did_new_line=1;
	}
}

int main(void) {
	char* cptr;
	while(1) {
		scanf("%d",&page_length);
		if(page_length==0)break;
		scanf("%d",&dan_num);
		scanf("%d",&onedan_width);
		scanf("%d",&space_width);
		buffer_init();
		fgets(line_buffer,sizeof(line_buffer),stdin);
		while(1) {
			fgets(line_buffer,sizeof(line_buffer),stdin);
			cptr=strchr(line_buffer,'\n');
			if(cptr)*cptr=0;
			if(line_buffer[0]=='?' && line_buffer[1]==0)break;
			for(cptr=line_buffer;*cptr;cptr++)insert_one_char(*cptr);
			new_line();
		}
		flush_buffer();
		puts("?");
	}
	return 0;
}