#include <bits/stdc++.h>
using namespace std;
long long int dp[1000005][2], len[1000005], vis[1000005], mod1 = 1000000007,
                                                          mod2 = 1000000007 + 2;
map<pair<long long int, long long int>, long long int> assign;
set<pair<pair<long long int, long long int>,
         pair<long long int, long long int> > >
    store;
vector<long long int> v[1000005];
string str[1000005];
inline long long int add1(long long int x, long long int y) {
  x += y;
  if (x >= mod1) x -= mod1;
  return x;
}
inline long long int mul1(long long int x, long long int y) {
  return (x * y) % mod1;
}
inline long long int add2(long long int x, long long int y) {
  x += y;
  if (x >= mod2) x -= mod2;
  return x;
}
inline long long int mul2(long long int x, long long int y) {
  return (x * y) % mod2;
}
void dfs(long long int cur, long long int par) {
  vis[cur] = 1;
  dp[cur][1] = 1;
  dp[cur][0] = 0;
  for (long long int i = 0; i < v[cur].size(); i++) {
    long long int x = v[cur][i];
    if (x == par) continue;
    dfs(x, cur);
    dp[cur][0] += max(dp[x][0], dp[x][1]);
    dp[cur][1] += dp[x][0];
  }
}
int main() {
  ios::sync_with_stdio(false);
  ;
  cin.tie(0);
  ;
  long long int t, i, j, n, x, y, pre1, pre2, base1 = 127, base2 = 129, nodes,
                                              ans, pre11, pre22;
  cin >> t;
  while (t--) {
    cin >> n;
    for (i = 1; i <= n; i++) {
      cin >> str[i];
      len[i] = str[i].length();
    }
    store.clear();
    for (i = 1; i <= n; i++) {
      store.insert({{str[i][0], str[i][0]}, {-1, -1}});
      pre1 = str[i][0];
      pre2 = 0;
      pre11 = str[i][0];
      pre22 = 0;
      if (len[i] == 1) continue;
      pre1 = add1(mul1(pre1, base1), str[i][1]);
      pre2 = str[i][1];
      pre11 = add2(mul2(pre11, base2), str[i][1]);
      pre22 = str[i][1];
      store.insert({{pre1, pre11}, {pre2, pre22}});
      for (j = 2; j < len[i]; j++) {
        pre1 = add1(mul1(pre1, base1), str[i][j]);
        pre2 = add1(mul1(pre2, base1), str[i][j]);
        pre11 = add2(mul2(pre11, base2), str[i][j]);
        pre22 = add2(mul2(pre22, base2), str[i][j]);
        store.insert({{pre1, pre11}, {pre2, pre22}});
      }
    }
    assign.clear();
    nodes = 0;
    for (auto it : store) {
      nodes++;
      assign[it.first] = nodes;
    }
    for (i = 0; i <= nodes; i++) {
      v[i].clear();
      dp[i][0] = dp[i][1] = 0;
      vis[i] = 0;
    }
    for (auto it : store) {
      x = assign[it.first];
      if (assign.find(it.second) != assign.end()) {
        y = assign[it.second];
        v[x].push_back(y);
        v[y].push_back(x);
      }
    }
    ans = 0;
    for (i = 1; i <= nodes; i++) {
      if (vis[i]) continue;
      dfs(i, -1);
      ans += max(dp[i][0], dp[i][1]);
    }
    cout << ans << "\n";
  }
  return 0;
}
