#include <bits/stdc++.h>

#define fastio ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl '\n'
#define pb push_back
#define mp make_pair
#define mt make_tuple

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;

using namespace std;




int main()
{
    fastio;

    int t;
    cin >> t;
    for (int c = 1; c <= t; c++)
    {
    	ll ans = 0;
    	int n;
    	cin >> n;
    	vector <string> v;
    	map <string, bool> yn;
    	for (int i = 0; i < n; i++)
    	{
    		string s;
    		cin >> s;
    		yn[s] = 0;
    		v.pb(s);
    	}
    	map <string, vector <string>> lst;
    	map <string, ll> mpx;
    	set <pair<int, string>> pos;
    	for (auto x : v)
    	{
    		int len = x.length();
    		for (int i = 0; i < len; i++)
    		{
    			string temp = x.substr(i, len - i);
    			if (lst.find(temp) == lst.end())
    			{
    				vector <string> samp = {x};
    				lst[temp] = samp;
    			}
    			else lst[temp].pb(x);
    			mpx[temp]++;
    			pos.insert({len - i, temp});
    		}
    	}
    	vector <pair<int, string>> subs;
    	for (auto x : pos)
    		subs.pb(x);
    	sort(subs.rbegin(), subs.rend());

    	for (auto x : subs)
    	{
    		string s = x.second;
    		int cur = 0;
    		vector <string> itm;
    		for (auto y : lst[s])
    		{
    			if (!yn[y])
    			{
    				itm.pb(y);
    				yn[y] = 1;
    				cur++;
    				if (cur == 2)
    				{
    					ans += 2;
    					break;
    				}
    			}
    		}
    		if (cur != 2)
    		{
    			for (auto x : itm)
    				yn[x] = 0;
    		}
    	}
    	cout << "Case #" << c << ": " << ans << endl;
    }
    return 0;
}