import java.util.*;

/* A simple O(N^3) time, O(N^2) space solution using breadth-first-search. */

public class maks
{
    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);

            // 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;
                }

            // Now search for a shortest path (in lexicographical order)
            String[] result = null;
            for (int i = 0; i < N; ++i)
            {
                int[] prev = new int[N];
                ArrayList<Integer> queue = new ArrayList<Integer>();
                ArrayList<Integer> next_queue = new ArrayList<Integer>();
                prev[i] = -1;
                queue.add(i);

                while (!queue.isEmpty())
                {
                    for (int p : queue)
                    {
                        if (diffs[i][p] == L)
                        {
                            ArrayList<String> pathList = new ArrayList<String>();
                            while (p >= 0) {
                                pathList.add(words[p]);
                                p = prev[p] - 1;
                            }
                            if (result == null || pathList.size() < result.length)
                            {
                                result = new String[pathList.size()];
                                for (int n = 0; n < result.length; ++n)
                                    result[n] = pathList.get(pathList.size() - n - 1);
                            }
                            break;
                        }

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

            for (int n = 0; n < result.length; ++n)
            {
                if (n > 0)
                    System.out.print(" ");
                System.out.print(result[n]);
            }
            System.out.println();
        }
    }
}
