#include<bits/stdc++.h>
using namespace std;
inline int strcmpa(char *s,char *t)
{
int i;int ans=0;
for(i=0;s[i]==t[i];i++,ans++)
if(s[i]!='\0') ans++;
return ans+1;
}
const int maxn=1010,maxlen=1010;
int t,n,m,cnt=1;
char a[maxn][maxlen];
inline int Main(){
freopen("strcmp.in","r",stdin);
freopen("strcmp.out","w",stdout);
while(520){
scanf("%d",&n);if (n==0) break;
for (int i=1;i<=n;i++){
scanf("%s",a[i]);
}
long long ans=0;
for (int i=2;i<=n;i++){
for (int j=1;j<i;j++){
ans+=strcmpa(a[i],a[j]);
}
}
printf("Case %d: %lld\n",cnt,ans);
}
}
int main(){;}
int mylove=Main();