#include <bits/stdc++.h>
using namespace std;
int ans = 0, T, n, ch[26][1000005], le, u, x, r[1000005], cnt = 0,
    dp[2][1000005];
int vis[1000005];
vector<int> sr[1000005];
vector<int> pos[1000005];
string s[1000005];
void init() {
  ans = 0;
  for (int i = 0; i <= cnt; i++) {
    sr[i].clear();
    vis[i] = 0;
    r[i] = 0;
    for (int j = 0; j < 26; j++) ch[j][i] = 0;
  }
  cnt = 0;
  for (int i = 1; i <= n; i++) pos[i].clear();
}
void dfs(int p) {
  int v;
  dp[0][p] = 0;
  dp[1][p] = 1;
  for (int i = 0; i < sr[p].size(); i++) {
    v = sr[p][i];
    dfs(v);
    dp[1][p] += dp[0][v];
    dp[0][p] += max(dp[1][v], dp[0][v]);
  }
}
int main() {
  std::ios::sync_with_stdio(false);
  cin >> T;
  while (T--) {
    init();
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> s[i], pos[i].resize(s[i].length());
    for (int i = 1; i <= n; i++) {
      u = 0;
      for (int j = 0; j < s[i].length(); j++) {
        le = s[i][j] - 'a';
        if (!ch[le][u]) ch[le][u] = ++cnt;
        u = ch[le][u];
        pos[i][j] = u;
      }
    }
    for (int i = 1; i <= n; i++) {
      u = 0;
      for (int j = 1; j < s[i].length(); j++) {
        le = s[i][j] - 'a';
        if (!ch[le][u]) break;
        u = ch[le][u];
        x = pos[i][j];
        if (vis[x]) continue;
        vis[x] = 1;
        sr[u].push_back(x);
        r[x]++;
      }
    }
    for (int i = 1; i <= cnt; i++) {
      if (r[i] == 0) {
        dfs(i);
        ans += max(dp[0][i], dp[1][i]);
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
