// Arup Guha
// 5/18/2018 - Written for practice
// 2018 Google Code Jam Jam Round 1C Problem A: A Whole New Word

import java.util.*;

public class Solution {

	public static int n;
	public static int len;
	public static char[][] words;
	public static String[] sWords;
	public static boolean[][] freq;

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);
		int nC = stdin.nextInt();

		// Process each case.
		for (int loop=1; loop<=nC; loop++) {

			// Get the input.
			n = stdin.nextInt();
			len = stdin.nextInt();
			words = new char[n][];
			sWords = new String[n];

			for (int i=0; i<n; i++) {
				sWords[i] = stdin.next();
				words[i] = sWords[i].toCharArray();
			}

			// Mark which letters we have in which spots.
			freq = new boolean[len][26];
			for (int i=0; i<n; i++)
				for (int j=0; j<len; j++)
					freq[j][words[i][j]-'A'] = true;

			// Go...
			String res = solve(0,"");
			if (res.equals(""))
				System.out.println("Case #"+loop+": -");
			else
				System.out.println("Case #"+loop+": "+res);
		}
	}

	public static String solve(int k, String cur) {

		// Finished a word; see if it's new.
		if (k == len) {
			for (int i=0; i<n; i++)
				if (cur.equals(sWords[i]))
					return "";
			return cur;
		}

		// Try each possible letter in slot k.
		for (int i=0; i<26; i++) {
			if (!freq[k][i]) continue;
			String tmp = solve(k+1, cur+((char)('A'+i)));
			if (!tmp.equals("")) return tmp;
		}
		return "";
	}
}