#include <stdio.h>
#include <stdlib.h>

#define N 10000

#define ABC 26
#define MAXW 15

int main()
{
  int i;
  int abeceda[ABC];
  int slovo[1000];
  
  printf("%d\n", N);
  for (i=0; i<N; i++)
  {
    int k, a, j, sw, z, sir, s;
    
    a=rand() % (ABC-1) + 2;
    if ((rand() % 4) && (a<5)) a=3+rand() % (ABC-2);
    
    k=rand() % 100+1;
    
    for (j=0; j<a; j++) abeceda[j]=j;
    for (j=0; j<a; j++)
    {
      z=rand() % a;
      sw=abeceda[j];
      abeceda[j]=abeceda[z];
      abeceda[z]=sw;
    }
    
    sir=rand() % MAXW + 1;
    for (j=0; j<sir; j++) slovo[j]=rand() % a;
    
    printf("%d %d\n", a, k);
    for (j=0; j<k+1; j++)
    {
      int bb;
      for (z=0; z<sir; z++) printf("%c", abeceda[slovo[z]]+'a');
      z=rand() % sir;
      while ((slovo[z] == a-1) && (z>0)) z--;
      if (slovo[z]<a-1)
      {
        slovo[z]+=rand() % (a-1-slovo[z]) +1; 
        bb=z+1;
      } else
      {
        bb=sir;
        z=sir < MAXW ? sir : MAXW-1;
      }
        
      sir=rand() % MAXW + 1;
      if (sir<=z) sir=z+1;
      for (s=bb; s<sir; s++) slovo[s]=rand() % a;
              
      printf("\n");
    }
  }
  
  return 0;
}
