/*-------property of the half blood prince-----*/
#include <bits/stdc++.h>
#include <dirent.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
#define MIN(X,Y) X<Y?X:Y
#define MAX(X,Y) X>Y?X:Y
#define ISNUM(a) ('0'<=(a) && (a)<='9')
#define ISCAP(a) ('A'<=(a) && (a)<='Z')
#define ISSML(a) ('a'<=(a) && (a)<='z')
#define ISALP(a) (ISCAP(a) || ISSML(a))
#define MXX 10000000000
#define MNN -MXX
#define ISVALID(X,Y,N,M) ((X)>=1 && (X)<=(N) && (Y)>=1 && (Y)<=(M))
#define LLI long long int
#define VI vector<int>
#define VLLI vector<long long int>
#define MII map<int,int>
#define SI set<int>
#define PB push_back
#define MSI map<string,int>
#define PII pair<int,int>
#define PLLI pair<LLI,LLI>
#define PDD pair<double,double>
#define FREP(i,I,N) for(int (i)=(int)(I);(i)<=(int)(N);(i)++)
#define eps 0.0000000001
#define RFREP(i,N,I) for(int (i)=(int)(N);(i)>=(int)(I);(i)--)
#define SORTV(VEC) sort(VEC.begin(),VEC.end())
#define SORTVCMP(VEC,cmp) sort(VEC.begin(),VEC.end(),cmp)
#define REVV(VEC) reverse(VEC.begin(),VEC.end())
#define INRANGED(val,l,r) (((l)<(val) || fabs((val)-(l))<eps) && ((val)<(r) || fabs((val)-(r))<eps))
#define INRANGEI(val,l,r) ((val)>=(l) && (val)<=(r))
#define MSET(a,b) memset(a,b,sizeof(a))
using namespace std;
using namespace __gnu_pbds;
//int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[]={2,1,-1,-2,-1,1};int dy[]={0,1,1,0,-1,-1}; //Hexagonal Direction
//typedef tree < int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update > ordered_set;
set<string>alls;
vector<string>allv;
pair<bool,string> getstr(int L, int n){
string s = "";
FREP(i,0,(L-1)){
int rr = rand()%n;
s.PB(allv[rr][i]);
}
if(alls.find(s)==alls.end()){
return make_pair(true,s);
}
else return make_pair(false,"");
}
int main(){
srand(time(0));
int t;
scanf("%d",&t);
FREP(cs,1,t){
alls.clear();
allv.clear();
int N,L;
scanf("%d %d",&N,&L);
FREP(i,1,N){
string s;
cin>>s;
alls.insert(s);
allv.PB(s);
}
printf("Case #%d: ",cs);
int f = 0;
FREP(i,1,100000){
pair<bool,string>my = getstr(L,N);
if(my.first==true){
cout<<my.second<<"\n";
f=1;
break;
}
}
if(f)continue;
else printf("-\n");
}
return 0;
}
LyotLS0tLS0tcHJvcGVydHkgb2YgdGhlIGhhbGYgYmxvb2QgcHJpbmNlLS0tLS0qLwoKI2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNpbmNsdWRlIDxkaXJlbnQuaD4KI2luY2x1ZGUgPGV4dC9wYl9kcy9hc3NvY19jb250YWluZXIuaHBwPgojaW5jbHVkZSA8ZXh0L3BiX2RzL3RyZWVfcG9saWN5LmhwcD4KI2luY2x1ZGUgPGV4dC9wYl9kcy9kZXRhaWwvc3RhbmRhcmRfcG9saWNpZXMuaHBwPgojZGVmaW5lIE1JTihYLFkpIFg8WT9YOlkKI2RlZmluZSBNQVgoWCxZKSBYPlk/WDpZCiNkZWZpbmUgSVNOVU0oYSkgKCcwJzw9KGEpICYmIChhKTw9JzknKQojZGVmaW5lIElTQ0FQKGEpICgnQSc8PShhKSAmJiAoYSk8PSdaJykKI2RlZmluZSBJU1NNTChhKSAoJ2EnPD0oYSkgJiYgKGEpPD0neicpCiNkZWZpbmUgSVNBTFAoYSkgKElTQ0FQKGEpIHx8IElTU01MKGEpKQojZGVmaW5lIE1YWCAxMDAwMDAwMDAwMAojZGVmaW5lIE1OTiAtTVhYCiNkZWZpbmUgSVNWQUxJRChYLFksTix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5jbGVhcigpOwogICAgICAgIGFsbHYuY2xlYXIoKTsKICAgICAgICBpbnQgTixMOwogICAgICAgIHNjYW5mKCIlZCAlZCIsJk4sJkwpOwogICAgICAgIEZSRVAoaSwxLE4pewogICAgICAgICAgICBzdHJpbmcgczsKICAgICAgICAgICAgY2luPj5zOwogICAgICAgICAgICBhbGxzLmluc2VydChzKTsKICAgICAgICAgICAgYWxsdi5QQihzKTsKICAgICAgICB9CiAgICAgICAgcHJpbnRmKCJDYXNlICMlZDogIixjcyk7CiAgICAgICAgaW50IGYgPSAwOwogICAgICAgIEZSRVAoaSwxLDEwMDAwMCl7CiAgICAgICAgICAgIHBhaXI8Ym9vbCxzdHJpbmc+bXkgPSBnZXRzdHIoTCxOKTsKICAgICAgICAgICAgaWYobXkuZmlyc3Q9PXRydWUpewogICAgICAgICAgICAgICAgY291dDw8bXkuc2Vjb25kPDwiXG4iOwogICAgICAgICAgICAgICAgZj0xOwogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYoZiljb250aW51ZTsKICAgICAgICBlbHNlIHByaW50ZigiLVxuIik7CiAgICB9CiAgICByZXR1cm4gMDsKfQ==