#include <bits/stdc++.h>
#define MP make_pair
#define PB push_back
#define int long long
#define st first
#define nd second
#define FOR(i, a, b) for(int i =(a); i <=(b); ++i)
#define RE(i, n) FOR(i, 1, n)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)
#define REP(i, n) for(int i = 0;i <(n); ++i)
#define VAR(v, i) __typeof(i) v=(i)
#define FORE(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#ifdef LOCAL
#define debug(x) {cerr <<#x<<" = " <<x<<"\n"; }
#define debug2(x, y) {cerr <<#x<<" = " <<x<<", "<<#y <<" = " <<y <<"\n";}
#define debug3(x, y, z) {cerr <<#x<<" = " <<x<<", "<<#y <<" = " <<y <<", "<<#z<<" = "<<z<<"\n";}
#define debug4(x, y, z, t) {cerr <<#x<<" = " <<x<<", "<<#y <<" = " <<y <<", "<<#z<<" = "<<z<<", "<<#t <<" = " <<t<<"\n";}
#define debugv(x) {{cerr <<#x <<" = "; FORE(itt, (x)) cerr <<*itt <<", "; cerr <<"\n"; }}
#else
#define debug(x)
#define debug2(x, y)
#define debug3(x, y, z)
#define debug4(x,y,z,t)
#define debugv(x)
#define cerr if(0)cout
#endif
#define make(type, x) type x; cin>>x;
#define make2(type, x, y) type x, y; cin>>x>>y;
#define make3(type, x, y, z) type x, y, z; cin>>x>>y>>z;
#define make4(type, x, y, z, t) type x, y, z, t; cin>>x>>y>>z>>t;
#define next ____next
#define prev ____prev
#define left ____left
#define hash ____hash
using namespace std;
typedef long long ll;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VLL;
typedef vector<pair<int, int> > VPII;
typedef vector<pair<ll, ll> > VPLL;

template<class C> void mini(C&a4, C b4){a4=min(a4, b4); }
template<class C> void maxi(C&a4, C b4){a4=max(a4, b4); }
template<class T1, class T2>
ostream& operator<< (ostream &out, pair<T1, T2> pair) { return out << "(" << pair.first << ", " << pair.second << ")";}
template<class T>
void ResizeVec(vector<T>& vec, vector<int> sz) {
  vec.resize(sz[0]);
  sz.erase(sz.begin());
  if (sz.empty()) { return; }
  for (auto& v : vec) {
    ResizeVec(v, sz);
  }
}



struct Sol {
  int P[2] = {999999197, (int)1e9 + 7};
  const int MOD = 1e9 + 33;
  void Test() {
    int res = 0;
    make(int, n);
    set<PII> hashes;
    hashes.insert(MP(0, 0));
    RE (hh, n) {
      make(string, s);
      int act_h[] = {0, 0};
      int act_pow[] = {1, 1};
      int added = 0;
      REP (i, s.length()) {
        REP (tr, 2) {
          act_pow[tr] = act_pow[tr] * P[tr] % MOD;
          act_h[tr] = (act_h[tr] + act_pow[tr] * (int)s[i]) % MOD;
        }
        if (hashes.count(MP(act_h[0], act_h[1])) == 0 && added == 0) {
          res += i + 1;
          added = 1;
        }
        hashes.insert(MP(act_h[0], act_h[1]));
      }
      if (added == 0) {
        res += s.length();
      }
    }
    cout<<res<<"\n";
      
      
    
  }
  
};

#undef int
int main() {
#define int long long

  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(10);
  double beg_clock = 1.0 * clock() / CLOCKS_PER_SEC;
  
  make(int, t);
  RE (tt, t) {
    cout<<"Case #"<<tt<<": ";
    Sol sol;
    sol.Test();
  }

  return 0;
}
