#include <iostream>
#include <set>

using namespace std;

int common_prefix(const string& a, const string& b) {
	int i = 0; 
	while (i < a.size() && i < b.size() && a[i] == b[i]) 
		++i;
	return i;
}

int main(int ac, char* av[]) {
	int t;
	cin >> t;
	for (int i = 0; i < t; ++i) {
		int n;
		cin >> n;
		set<string> words;
		int total_chars = 0;
		for (int k = 0; k < n; ++k) {
			string word;
			cin >> word;
			words.insert(word);
			set<string>::iterator it = words.find(word);
			int max_pref = 0;
			if (it != words.begin()) {
				auto prev = it;
				--prev;
				max_pref = max(max_pref, common_prefix(*prev, word));
			}
			++it;
			if (it != words.end())
				max_pref = max(max_pref, common_prefix(*it, word));
			if (max_pref != word.size())
				++max_pref;
			total_chars += max_pref;
		}
		cout << "Case #" << (i + 1) << ": " << total_chars << endl;
	}
	return 0;
}