import java.util.*;

/*  A somewhat optimized version of the earlier algorithm:
    - of words that are permutations of eachother, all but the
      lexicographically first are removed.
    - edge lists are used instead of an adjacency matrix to speed up
      the path finding algorithm.
    Finally, there is a single BFS that incorperates all possible starting
    states at once. The advantage of this is that we never search longer
    paths than necessary, at the cost of some more memory.
*/
public class maks_faster
{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int cases = sc.nextInt();
        while (cases-- > 0)
        {
            int N = sc.nextInt();
            int L = sc.nextInt();

            // Read and sort dictionary
            String[] words = new String[N];
            for (int n = 0; n < N; ++n)
                words[n] = sc.next();
            Arrays.sort(words);

            // Eliminate extra words that are permutations of other words
            {
                HashSet<String> prototypes = new HashSet<String>();
                int m = 0;
                for (int n = 0; n < N; ++n)
                {
                    char[] chars = words[n].toCharArray();
                    Arrays.sort(chars);
                    String p = new String(chars);
                    if (prototypes.contains(p))
                        continue;
                    prototypes.add(p);
                    words[m++] = words[n];
                }
                N = m;
                String[] oldWords = words;
                words = new String[N];
                System.arraycopy(oldWords, 0, words, 0, N);
            }

            // Calculcate character frequencies for each word
            int[][] counts = new int[N][26];
            for (int n = 0; n < N; ++n)
                for (int m = 0; m < L; ++m)
                    ++counts[n][words[n].charAt(m) - 'a'];

            // Calculcate the character difference between pairs of words
            int[][] diffs = new int[N][N];
            for (int i = 0; i < N; ++i)
                for (int j = 0; j < N; ++j)
                {
                    for (int c = 0; c < 26; ++c)
                        diffs[i][j] += Math.abs(counts[i][c] - counts[j][c]);
                    diffs[i][j] /= 2;
                }

            /* Calculcate edge lists (i.e. add an edge from i to j if the
               difference between i and j is exactly 1 character. */
            int[][] edges = new int[N][];
            for (int i = 0; i < N; ++i)
            {
                ArrayList<Integer> e = new ArrayList<Integer>();
                for (int j = 0; j < N; ++j)
                    if (diffs[i][j] == 1)
                        e.add(j);
                edges[i] = new int[e.size()];
                for (int n = 0; n < e.size(); ++n)
                    edges[i][n] = e.get(n);
            }

            // Now search for a shortest path (in lexicographical order)
            // State in the queue are of the form (start<<16) + cur
            int[][] prev = new int[N][N];
            ArrayList<Integer> queue = new ArrayList<Integer>();
            ArrayList<Integer> next_queue = new ArrayList<Integer>();
            for (int i = 0; i < N; ++i)
            {
                prev[i][i] = -1;
                queue.add((i<<16) | i);
            }
        bfs_loop:
            while (!queue.isEmpty())
            {
                for (int state : queue)
                {
                    int start = state >> 16, p = state&((1<<16) - 1);

                    if (diffs[start][p] == L)
                    {
                        ArrayList<String> pathList = new ArrayList<String>();
                        while (p >= 0) {
                            pathList.add(words[p]);
                            p = prev[start][p] - 1;
                        }
                        for (int n = pathList.size() - 1; n >= 0; --n)
                        {
                            System.out.print(pathList.get(n));
                            if (n > 0)
                                System.out.print(" ");
                        }
                        System.out.println();
                        break bfs_loop;
                    }

                    for (int q : edges[p])
                    {
                        if (prev[start][q] == 0 && diffs[p][q] == 1)
                        {
                            next_queue.add((start << 16) | q);
                            prev[start][q] = p + 1;
                        }
                    }
                }
                ArrayList<Integer> tmp = queue;
                queue = next_queue;
                next_queue = tmp;
                next_queue.clear();
            }
        }
    }
}
