#include <iostream>
#include <string.h>
struct tree
{
tree *next[4], *fail;
int state, flag;
};
tree sta[500];
int indexx;
tree *root, *p;
int map(char ch)
{
if(ch == 'A') return 0; if(ch == 'C') return 1;
if(ch == 'T') return 2; if(ch == 'G') return 3;
}
inline void newn()
{
sta[indexx].fail = NULL;
sta[indexx].flag = 0;
sta[indexx].state = indexx;
for(int i = 0; i < 4; i ++) sta[indexx].next[i] = 0;
}
void init()
{
indexx = 0;
newn();
root = &sta[indexx ++];
}
void insert(char ch[])
{
int id, i = 0;
p = root;
while(ch[i])
{
id = map(ch[i]);
if(p->next[id] == 0)
{
newn();
p->next[id] = &sta[indexx ++];
}
p = p->next[id];
i ++;
}
p->flag = 1;
}
tree *que[10001];
bool search(tree *q)
{
while(q != root)
{
if(q->flag) return true;
q = q->fail;
}
return false;
}
void get_fail()
{
int close = -1, open = 0, i, pass;
p = root; p->fail = root;
que[0] = root;
while(close < open)
{
p = que[++close];
tree *q = p;
pass = 0;
if(q->flag == 0) pass = search(q);
if(pass) q->flag = 1;
for(i = 0; i < 4; i ++)
{
if(p->next[i] == 0)
{
if(p == root) p->next[i] = root;
else p->next[i] = p->fail->next[i];
}
else
{
if(p == root) p->next[i]->fail = root;
else p->next[i]->fail = p->fail->next[i];
que[++open] = p->next[i];
}
}
}
}
inline void updata(int &a, int b)
{if(a < 0 || b < a) a = b;}
int f[1005][500];
int dp()
{
char str[1005];
memset(f,-1,sizeof(f));
scanf("%s", str);
int L = strlen(str), inc, dic;
f[0][0] = 0;
for(int i = 0; i < L; i ++)
{
for(int J = 0; J < indexx; J ++)
if(f[i][J] >= 0 && sta[J].flag == 0)
{
for(int k = 0; k < 4; k ++)
if(sta[J].next[k]->flag == 0)
{
inc = ( k != map(str[i]) );
updata(f[i + 1][sta[J].next[k]->state], f[i][J] + inc);
}
}
}
// for(int i = 0; i <= L; i ++)
// {printf("i=%d ",i);for(int j = 0; j < indexx; j ++) printf("%d ",f[i%2][j]);puts("");}
int ans = -1;
for(int i = 0; i < indexx; i ++)
if(f[L][i] >= 0) updata(ans, f[L][i]);
return ans;
}
int main()
{
int test = 0, n;
while(scanf("%d", &n), n)
{
init();
char dg[21];
for(int i = 0; i < n; i ++)
{
scanf("%s", dg);
insert(dg);
}
get_fail();
int ans = dp();
printf("Case %d: %d\n",++test, ans);
}
}