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

//do "her mother" and "the ___ fell asleep" with no little every time

void bedtimestory(char words[20][15], int current, int number) {
	int i;

	if(current==0){
		printf("A %s couldn't sleep, so her mother told a story about a little %s,\n",words[0],words[1]);
	}else {

		for(i=0; i<current; i++){
			printf("  ");
		}
		printf("who couldn't sleep, so the %s's mother told a story about a little %s,\n",words[current],words[current+1]);

	}  	                   

	if(current<number-2){
		bedtimestory(words, current+1, number);
	}else{
		for(i=0; i<number-1; i++){
			printf("  ");
		}
		printf("... who fell asleep.\n");
	}

	if(current==0){
		printf("... and then the %s fell asleep.\n",words[0]);
	}else{

		for(i=0; i<current; i++){
			printf("  ");
		}
		printf("... and then the little %s fell asleep;\n",words[current]);

	}

}

main() {
  char names[20][15];   // Up to 20 names, each up to 15 letters long (incl. NULL)
  char currentName[15];
  int num=0;
  int i;


  while(1){
  	fgets(currentName,15,stdin);   // Read the names from the input
  	if(strncmp(currentName,"END",3)==0){break;} // until you read "END"
  	for(i=0;i<strlen(currentName)-1;i++){
  		names[num][i]=currentName[i];            
  	} 
  	names[num][i]=0;
  	num++;       
  }

  bedtimestory(names, 0, num);
}
