#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
typedef complex<ld> Point;
const ll mod = 1000000007;
const ll INF = mod * mod;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)

int dp[17][17];
int logdist(string s, string t) {
	int ls = s.length(), lt = t.length();
	rep(i, ls + 1) {
		rep(j, lt + 1) {
			dp[i][j] = mod;
		}
	}
	dp[0][0] = 0;
	rep(i, ls+1) {
		rep(j, lt + 1) {
			if (i < ls) {
				dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + 1);
			}
			if (j < lt) {
				dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + 1);
			}
			if (i < ls&&j < lt) {
				if (s[i] == t[j]) {
					dp[i + 1][j + 1] = min(dp[i + 1][j + 1], dp[i][j]);
				}
				else {
					dp[i + 1][j + 1] = min(dp[i + 1][j + 1], dp[i][j]+1);
				}
			}
		}
	}
	return dp[ls][lt];
}
int dist(string s, string t) {
	if (s.length() < t.length()) {
		swap(s, t);
	}
	int ret = logdist(s, t);
	int len = s.length();
	if (len - t.length() >= 2)return ret;
	if (s.length() == t.length()) {
		rep(i, len - 1) {
			rep(j, len - 1) {
				string u = s;
				swap(u[i], u[i + 1]);
				swap(u[j], u[j + 1]);
				if (u == t)ret = min(ret, 2);
			}
		}
		rep(i, len - 1) {
			string u = s;
			swap(u[i], u[i + 1]);
			int cnt = 0;
			rep(j, len) {
				if (u[j] != t[j])cnt++;
			}
			if (cnt == 0)ret = min(ret, 1);
			else if (cnt == 1)ret = min(ret, 2);
		}
		rep(i, len - 1) {
			string u = t;
			swap(u[i], u[i + 1]);
			int cnt = 0;
			rep(j, len) {
				if (u[j] != s[j])cnt++;
			}
			if (cnt == 0)ret = min(ret, 1);
			else if (cnt == 1)ret = min(ret, 2);
		}
	}
	else {
		rep(i, len) {
			string u = s;
			u.erase(u.begin() + i);
			rep(j, len - 2) {
				string z = u;
				swap(z[j], z[j + 1]);
				if (z == t)ret = min(ret, 2);
			}
		}
	}
	return ret;
}
void solve() {
	int n, d;
	while (cin >> n, n) {
		int d; cin >> d;
		vector<string> v(n);
		vector<pair<string, string>> ans;
		rep(i, n) {
			cin >> v[i];
		}
		sort(v.begin(), v.end());
		rep(i, v.size()) {
			Rep(j, i + 1, v.size()) {
				if (dist(v[i], v[j]) <= d) {
					ans.push_back({ v[i],v[j] });
				}
			}
		}
		sort(ans.begin(), ans.end());
		rep(i, ans.size()) {
			cout << ans[i].first << "," << ans[i].second << endl;
		}
		cout << ans.size() << endl;
	}
}
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	solve();
	//stop
	return 0;
}

