// AOJ 1252: Confusing Login Names
// 2017.10.12 bal4u@uu

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

#define MIN(a,b) ((a)<=(b)?(a):(b))

typedef struct { char *s1, *s2; } T;
T tbl[202]; int sz;

typedef struct { char *s; } S;
S nm[202];
char name[202][18];
int M[20][20];

int cmp1(S *a, S *b)
{
	return strcmp(a->s, b->s);
}

int cmp2(T *a, T *b)
{
	int k;

	if ((k = strcmp(a->s1, b->s1)) != 0) return k;
	return strcmp(a->s2, b->s2);
}

void calc(char *s1, int i, char *s2, int j)
{
	int k;

	if (s1[i] == s2[j]) M[i][j] = M[i-1][j-1];
	else M[i][j] = MIN(M[i-1][j-1], MIN(M[i-1][j], M[i][j-1])) + 1;

	if (j >= 2) for (k = 1; k < i; k++) {
		if (s1[i-k] == s2[j] && s1[i] == s2[j-1])
			M[i][j] = MIN(M[i][j], M[i-k-1][j-2] + k);
	}
	if (i >= 2) for (k = 1; k < j; k++) {
		if (s1[i] == s2[j-k] && s1[i-1] == s2[j])
			M[i][j] = MIN(M[i][j], M[i-2][j-k-1] + k);
    }
}

int distance(char *str1, char *str2)
{
    int i, j, k;
    int len1 = strlen(str1);
    int len2 = strlen(str2);

	M[0][0] = 0;
    for (i = 1; i < len1; i++) M[i][0] = i;
    for (j = 1; j < len2; j++) M[0][j] = j;
    for (k = 1; k < MIN(len1, len2); k++) {
		calc(str1, k, str2, k);
        for (i = k+1; i < len1; i++) calc(str1, i, str2, k);
		for (j = k+1; j < len2; j++) calc(str1, k, str2, j);
    }
    return M[len1-1][len2-1];
}

int main()
{
	int n, d, i, j;

	while (scanf("%d", &n) && n > 0) {
		scanf("%d", &d);
		sz = 0;
		for (i = 0; i < n; i++) scanf("%s", name[i]), nm[i].s = name[i];
		qsort(nm, n, sizeof(S), cmp1);

		for (i = 0; i < n; i++) for (j = i+1; j < n; j++) {
			if (distance(nm[i].s, nm[j].s) <= d) 
				tbl[sz].s1 = nm[i].s, tbl[sz++].s2 = nm[j].s;
		}
		qsort(tbl, sz, sizeof(T), cmp2);
		for (i = 0; i < sz; i++) printf("%s,%s\n", tbl[i].s1, tbl[i].s2);
		printf("%d\n", sz);
	}
	return 0;
}