#include <bits/stdc++.h>
using namespace std;
const long long MDS[] = {1000000007LL, 1000000009LL, 1000000003LL};
map<long long, int> Mp;
long long bs = 31;
vector<int> G[1000001 + 2];
char s[1000001 + 2];
int kk, dpp[1000001][2], dp[1000001][2];
bool vis[1000001 + 2];
int go(int u, int f, int p) {
  int &ret = dp[u][f];
  int &ret2 = dpp[u][f];
  if (ret2 == kk) return ret;
  ret2 = kk;
  ret = 0;
  for (int i = 0; i < G[u].size(); i++) {
    int v = G[u][i];
    if (v == p) continue;
    if (f == 1) {
      ret += go(v, 0, u);
    } else {
      ret += max(go(v, 0, u), 1 + go(v, 1, u));
    }
  }
  return ret;
}
vector<pair<long long, long long> > Hash;
int main() {
  int tc, cs = 1, i, j, n, x;
  scanf("%d", &tc);
  while (tc--) {
    scanf("%d", &n);
    Mp.clear();
    Hash.clear();
    int k = 1;
    while (n--) {
      scanf("%s", s);
      long long hs = 0LL;
      long long hss = 0LL;
      long long hs1 = 0LL;
      long long hss1 = 0LL;
      int Len = strlen(s);
      for (i = 0; i < Len; i++) {
        hs = (hs * bs + (s[i] - 'a' + 1)) % MDS[0];
        hss = (hss * bs + (s[i] - 'a' + 1)) % MDS[1];
        long long h = hs * MDS[2] + hss;
        if (Mp.find(h) == Mp.end()) {
          Mp[h] = k;
          k++;
        }
        if (i) {
          hs1 = (hs1 * bs + (s[i] - 'a' + 1)) % MDS[0];
          hss1 = (hss1 * bs + (s[i] - 'a' + 1)) % MDS[1];
          long long h2 = hs1 * MDS[2] + hss1;
          Hash.push_back(make_pair(h, h2));
        }
      }
    }
    sort(Hash.begin(), Hash.end());
    Hash.erase(unique(Hash.begin(), Hash.end()), Hash.end());
    for (auto x : Hash) {
      if (Mp.count(x.second)) {
        int xx = Mp[x.first];
        int yy = Mp[x.second];
        G[xx].push_back(yy);
        G[yy].push_back(xx);
      }
    }
    kk++;
    int ans = 0;
    for (i = 1; i < k; i++) {
      if (dpp[i][0] == kk && dpp[i][1] == kk)
        ;
      else {
        long long notake = go(i, 0, -1);
        long long take = 1 + go(i, 1, -1);
        long long val = max(notake, take);
        ans += val;
      }
      G[i].clear();
    }
    printf("%d\n", ans);
  }
  return 0;
}
