#include<bits/stdc++.h>
using namespace std;
map<char,int>mark;
struct node{
int cnt_trees;
bool end_mark;
node *next[4];
node(){
cnt_trees=0;
end_mark=false;
for(int i=0;i<4;i++) next[i]=NULL;
}
}*root;
void insert_into_Trie(string str,map<char,int> mark){
node *cur=root;
for(int i=0;str[i];i++){
char ch=str[i];
int id=mark[ch];
if(cur->next[id]==NULL)
cur->next[id]=new node();
cur=cur->next[id];
cur->cnt_trees++;
}
}
int search_into_Trie(string str,map<char,int> mark){
node *cur=root;
int mx=-1;
for(int i=0;str[i];i++){
char ch=str[i];
int id=mark[ch];
cur=cur->next[id];
int koita_ache=cur->cnt_trees;
int len=i+1;
int lo_max=koita_ache*len;
//cout<<lo_max<<endl;
if(mx<lo_max) mx=lo_max;
}
return mx;
}
void del(node* cur)
{
for(int i= 0;i<4;i++)
if (cur->next[i])
del(cur->next[i]);
delete(cur);
}
int main()
{
mark['A']=0;mark['C']=1;mark['G']=2;mark['T']=3;
int tc,n,q,cs=0;
string str;
cin>>tc;
while(tc--){
root=new node();
cin>>n;
vector<string>v;
while(n--){
cin>>str;
insert_into_Trie(str,mark);
v.push_back(str);
}
int local_max=-1;
for(int i=0;i<v.size();i++){
int ck_max=search_into_Trie(v[i],mark);
if(ck_max>local_max) local_max=ck_max;
}
cout<<"Case "<<++cs<<": ";
cout<<local_max<<endl;
del(root);
}
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKbWFwPGNoYXIsaW50Pm1hcms7CnN0cnVjdCBub2RlewogICAgaW50IGNudF90cmVlczsKICAgIGJvb2wgZW5kX21hcms7CiAgICBub2RlICpuZXh0WzRdOwogICAgbm9kZSgpewogICAgICAgIGNudF90cmVlcz0wOwogICAgICAgIGVuZF9tYXJrPWZhbHNlOwogICAgICAgIGZvcihpbnQgaT0wO2k8NDtpKyspIG5leHRbaV09TlVMTDsKICAgIH0KfSpyb290OwoKdm9pZCBpbnNlcnRfaW50b19UcmllKHN0cmluZyBzdHIsbWFwPGNoYXIsaW50PiBtYXJrKXsKICAgIG5vZGUgKmN1cj1yb290OwogICAgZm9yKGludCBpPTA7c3RyW2ldO2krKyl7CiAgICAgICAgY2hhciBjaD1zdHJbaV07CiAgICAgICAgaW50IGlkPW1hcmtbY2hdOwogICAgICAgIGlmKGN1ci0+bmV4dFtpZF09PU5VTEwpCiAgICAgICAgICAgIGN1ci0+bmV4dFtpZF09bmV3IG5vZGUoKTsKICAgICAgICAgICAgY3VyPWN1ci0+bmV4dFtpZF07CiAgICAgICAgICAgIGN1ci0+Y250X3RyZWVzKys7CiAgICB9Cn0KCmludCBzZWFyY2hfaW50b19UcmllKHN0cmluZyBzdHIsbWFwPGNoYXIsaW50PiBtYXJrKXsKICAgIG5vZGUgKmN1cj1yb290OwogICAgaW50IG14PS0xOwogICAgZm9yKGludCBpPTA7c3RyW2ldO2krKyl7CiAgICAgICAgY2hhciBjaD1zdHJbaV07CiAgICAgICAgaW50IGlkPW1hcmtbY2hdOwoKICAgICAgICBjdXI9Y3VyLT5uZXh0W2lkXTsKICAgICAgICBpbnQga29pdGFfYWNoZT1jdXItPmNudF90cmVlczsKICAgICAgICBpbnQgbGVuPWkrMTsKICAgICAgICBpbnQgbG9fbWF4PWtvaXRhX2FjaGUqbGVuOwogICAgICAgIC8vY291dDw8bG9fbWF4PDxlbmRsOwogICAgICAgIGlmKG14PGxvX21heCkgbXg9bG9fbWF4OwogICAgfQogICAgcmV0dXJuIG14Owp9CgoKdm9pZCBkZWwobm9kZSogY3VyKQp7CiAgICBmb3IoaW50IGk9IDA7aTw0O2krKykKICAgICAgICBpZiAoY3VyLT5uZXh0W2ldKQogICAgICAgICAgICBkZWwoY3VyLT5uZXh0W2ldKTsKCiAgICBkZWxldGUoY3VyKTsKfQoKaW50IG1haW4oKQp7CiAgICBtYXJrWydBJ109MDttYXJrWydDJ109MTttYXJrWydHJ109MjttYXJrWydUJ109MzsKICAgIGludCB0YyxuLHEsY3M9MDsKIC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