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

int main(void){
	int i,j,k,l,ti,flg;
	int plen,cnum,width,cspace;
	char out[512][50];
	char s[1004];

	while(1){
		scanf("%d",&plen);
		if(plen == 0) break;

		scanf("%d%d%d ",&cnum,&width,&cspace);
		memset(out,'.',sizeof(out));

		i = 0;
		while(1){
			fgets(s,1004,stdin);
			if(strcmp(s,"?\n") == 0) break;
			if(strcmp(s,"\n") == 0){i++;continue;}

			k = 0;
			flg = 1;
			for(;flg;i++){
				if(s[k] == '\n') break;
				for(j=0;j<width;j++){
					if(s[k] == '\n'){flg=0;break;}
					out[i][j] = s[k++];
				}
			}
		}

		ti = i;
		for(l=0;l<ti;l+=plen*cnum){
			for(i=l;i<l+plen;i++){
				for(k=0;k<cnum;k++){
					for(j=0;j<width;j++)putchar(out[i+k*plen][j]);
					if(k!=cnum-1) for(j=0;j<cspace;j++) printf(".");
				}
				printf("\n");
			}
			printf("#\n");
		}
		printf("?\n");
	}

	return 0;
}