#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

// Damerau???Levenshtein distance
// Levenshtein distance ??? transposition (??£????£????swap) ?????????
// ca -> ac ????????????1
// https://en.wikipedia.org/wiki/Damerau???Levenshtein_distance
// wiki ???????£?????????????????????£?????????????????????????????£?????????
// https://doi.org/10.1145%2F363958.363994
// ????????????????§£??§????????????
int damerauLevenshteinDistance(const string &a, const string &b) {
	int m = a.size(), n = b.size();
	vector<vector<int>> d(m + 1, vector<int>(n + 1, INF));
	static int da[128];
	memset(da, 0, sizeof(da));
	rep(i, 0, m + 1)d[i][0] = i;
	rep(j, 0, n + 1)d[0][j] = j;
	rep(i, 1, m + 1) {
		int db = 0;
		rep(j, 1, n + 1) {
			int k = da[b[j - 1]];
			int l = db;
			int cost = 1;
			if (a[i - 1] == b[j - 1]) {
				cost = 0;
				db = j;
			}
			d[i][j] = min({
				d[i - 1][j] + 1,
				d[i][j - 1] + 1,
				d[i - 1][j - 1] + cost
			});
			if (k - 1 >= 0 && l - 1 >= 0) {
				chmin(d[i][j], d[k - 1][l - 1] + (i - k - 1) + 1 + (j - l - 1));
			}
		}
		da[a[i - 1]] = i;
	}
	return d[m][n];
}


signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	for (int n; cin >> n&&n;) {
		int d; cin >> d;
		vector<string> s(n); rep(i, 0, n) {
			cin >> s[i];
		}
		sort(all(s));
		int x = 0;
		rep(i, 0, n)rep(j, i + 1, n) {
			int dst = damerauLevenshteinDistance(s[i], s[j]);
			if (dst <= d) {
				cout << s[i] + "," + s[j] << endl;
				x++;
			}
		}
		cout << x << endl;
	}
	return 0;
}