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

#define N 15
char           *s, *w;
int             n;

void
placement(int x)
{
  int             i;
  char            t;

  if (x == 0) {
    for(i=0; i<n-1; i++) {
      printf("%c,", w[i]);
    }
    printf("%c\n", w[i]);
    return;
  }
  for (i = n; i; i--) {
    if (s[i - 1] == ' ')
      continue;
    w[x - 1] = s[i - 1];
    t = s[i - 1];
    s[i - 1] = ' ';
    placement(x - 1);
    s[i - 1] = t;
  }
}

int
main(int argc, char **argv)
{
  n = atoi(argv[1]);
  s = malloc(sizeof(char) * (N + 1));
  strncpy(s, "abcdefghijklmno", n);
  w = malloc(sizeof(char) * (N + 1));
  strcpy(w, s);
  placement(n);

  return 0;
}