/*
  [BAPC'07] WORD LADDER
  by: Jan Kuipers
*/

using namespace std;

#include <iostream>
#include <queue>
#include <string>
#include <algorithm>

int main () {

  int runs;
  cin>>runs;
  while (runs--) {

    int N,L;
    cin>>N>>L;

    vector<string> w(N);
    for (int i=0; i<N; i++) cin>>w[i];
    sort(w.begin(),w.end());
    
    vector<int> lett(N);
    for (int i=0; i<N; i++)
      for (int j=0; j<L; j++)
	lett[i] |= 1<<(w[i][j]-'a');

    vector<vector<int> > next(N);
    for (int i=0; i<N; i++) 
      for (int j=0; j<N; j++) {
	vector<int> cnt1(26,0), cnt2(26,0);
	for (int k=0; k<L; k++) {
	  cnt1[w[i][k]-'a']++;
	  cnt2[w[j][k]-'a']++;
	}
	int diff=0;
	for (int k=0; k<26; k++) diff += abs(cnt1[k]-cnt2[k]);
	if (diff==2) next[i].push_back(j);
      }

    int len=N+1;
    vector<string> ladd;

    for (int start=0; start<N; start++) {
      vector<int> dist(N,-1);
      vector<int> prev(N,-1);
      queue<int> q;

      q.push(start);
      dist[start]=1;
      
      while (!q.empty()) {
	int n = q.front(); q.pop();
	if (!(lett[n] & lett[start])) {
	  if (dist[n] < len) {
	    len=dist[n];
	    ladd=vector<string>();

	    while (n!=start) {
	      ladd.push_back(w[n]);
	      n=prev[n];
	    }

	    ladd.push_back(w[start]);
	    reverse(ladd.begin(),ladd.end());
	  }

	  break;
	}
	     
	for (int i=0; i<next[n].size(); i++) {
	  int j = next[n][i];
	  if (dist[j]==-1) {
	    q.push(j);
	    dist[j]=dist[n]+1;
	    prev[j]=n;
	  }
	}
      }
    }

    for (int i=0; i<len; i++) {
      if (i>0) cout<<" ";
      cout<<ladd[i];
    }
    cout<<endl;
  }

  return 0;
}
