import java.util.*;

/* An O(N^3) time, O(N^2) space solution using Floyd-Warshall. */

public class maks_simple
{
    static final int inf = 999999999;

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

            // Calculate path lengths using Floyd-Warshall
            int[][] dists = new int[N][N];
            for (int i = 0; i < N; ++i)
                for (int j = 0; j < N; ++j)
                    dists[i][j] = i == j ? 0 : diffs[i][j] == 1 ? 1 : inf;
            for (int k = 0; k < N; ++k)
                for (int i = 0; i < N; ++i)
                    for (int j = 0; j < N; ++j)
                        dists[i][j] = Math.min(dists[i][j], dists[i][k] + dists[k][j]);

            // Find length of shortest path
            int len = inf;
            for (int i = 0; i < N; ++i)
                for (int j = 0; j < N; ++j)
                    if (diffs[i][j] == L && dists[i][j] < len)
                        len = dists[i][j];

            // Find lexicographically first shortest path
            String result = null;
            for (int i = 0; i < N && result == null; ++i)
            {
                for (int j = 0; j < N; ++j)
                    if (diffs[i][j] == L && dists[i][j] == len)
                    {
                        StringBuffer sb = new StringBuffer();
                        int n = i;
                        while (n != j) {
                            sb.append(words[n]);
                            sb.append(' ');
                            for (int k = 0; k < N; ++k)
                                if (dists[n][k] == 1 && dists[k][j] == dists[n][j] - 1)
                                {
                                    n = k;
                                    break;
                                }
                        }
                        sb.append(words[n]);

                        String path = sb.toString();
                        if (result == null || path.compareTo(result) < 0)
                            result = path;
                    }
            }
            System.out.println(result);
        }
    }
}
