#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007LL;
long long base = 10000007;
long long large = 1000000000000000000LL;
int n;
vector<vector<int> > dp;
int cnt;
vector<vector<pair<long long, long long> > > s;
int maxl = 0;
vector<vector<int> > adj;
map<pair<long long, long long>, int> comp;
long long ch(char c) { return (long long)(c - 'a') + 1LL; }
vector<bool> vis;
long long base1 = 97;
long long base2 = 37;
void f(int u, int c, int pa) {
  vis[u] = true;
  if (dp[u][c] != -1000000000) return;
  if (adj[u].size() == 1 && adj[u][0] == pa) {
    dp[u][c] = c;
    return;
  }
  for (int j = 0; j < (int)adj[u].size(); j++) {
    int v = adj[u][j];
    if (v != pa) {
      f(v, 0, u);
      f(v, 1, u);
    }
  }
  int ans = c;
  for (int j = 0; j < (int)adj[u].size(); j++) {
    int v = adj[u][j];
    if (v != pa) {
      if (c == 0) {
        ans += max(dp[v][0], dp[v][1]);
      } else {
        ans += dp[v][0];
      }
    }
  }
  dp[u][c] = ans;
}
int main() {
  int tot;
  cin >> tot;
  s.assign(1000010, vector<pair<long long, long long> >());
  vector<long long> pow1(1000010, 1LL);
  vector<long long> pow2(1000010, 1LL);
  for (int i = 1; i < 1000010; i++) {
    pow1[i] = pow1[i - 1] * base1;
    pow1[i] %= mod;
    pow2[i] = pow2[i - 1] * base2;
    pow2[i] %= mod;
  }
  while (tot--) {
    cin >> n;
    cnt = 0;
    for (int i = 1; i <= maxl; i++) s[i].clear();
    maxl = 0;
    comp.clear();
    vector<string> w;
    for (int i = 0; i < n; i++) {
      string t;
      cin >> t;
      w.push_back(t);
      long long hash1 = 0LL;
      long long hash2 = 0LL;
      for (int j = 0; j < (int)t.length(); j++) {
        hash1 *= base1;
        hash1 += ch(t[j]);
        hash1 %= mod;
        hash2 *= base2;
        hash2 += ch(t[j]);
        hash2 %= mod;
        s[j + 1].push_back(pair<long long, long long>(hash1, hash2));
      }
      maxl = max(maxl, (int)t.length());
    }
    for (int i = 1; i <= maxl; i++) {
      sort(s[i].begin(), s[i].end());
      s[i].erase(unique(s[i].begin(), s[i].end()), s[i].end());
      for (int j = 0; j < (int)s[i].size(); j++) {
        comp[s[i][j]] = cnt++;
      }
    }
    adj.assign(cnt, vector<int>(0, 0));
    vis.assign(cnt, false);
    for (int i = 0; i < (int)w.size(); i++) {
      string t = w[i];
      long long hash1 = 0LL;
      long long hash2 = 0LL;
      for (int j = 0; j < (int)t.length(); j++) {
        hash1 *= base1;
        hash1 += ch(t[j]);
        hash1 %= mod;
        hash2 *= base2;
        hash2 += ch(t[j]);
        hash2 %= mod;
        if (j > 0) {
          long long l11 = hash1;
          long long l12 = hash2;
          long long l21 = l11 + mod - ((ch(t[0]) * pow1[j]) % mod);
          l21 %= mod;
          long long l22 = l12 + mod - ((ch(t[0]) * pow2[j]) % mod);
          l22 %= mod;
          if (comp.find(pair<long long, long long>(l21, l22)) != comp.end()) {
            int t1 = comp[pair<long long, long long>(l11, l12)];
            int t2 = comp[pair<long long, long long>(l21, l22)];
            adj[t1].push_back(t2);
            adj[t2].push_back(t1);
          }
        }
      }
    }
    for (int i = 0; i < cnt; i++) {
      sort(adj[i].begin(), adj[i].end());
      adj[i].erase(unique(adj[i].begin(), adj[i].end()), adj[i].end());
    }
    dp.assign(cnt, vector<int>(2, -1000000000));
    int ans = 0;
    for (int i = 0; i < cnt; i++) {
      if (!vis[i]) {
        f(i, 0, -1);
        f(i, 1, -1);
        ans += max(dp[i][0], dp[i][1]);
      }
    }
    cout << ans << endl;
  }
  return 0;
}
