#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000050;
vector<int> g[maxn];
int ch[maxn][26];
int f[maxn], len[maxn], d[maxn];
int dp[maxn][2];
char s[maxn];
int n, tot;
void init() {
  memset(ch[0], 0, sizeof(ch[0]));
  tot = 0;
}
void add(int u, int v) { g[u].push_back(v); }
void insert(char *s, int len_s) {
  int u = 0;
  for (int i = 0; i < len_s; i++) {
    int id = s[i] - 'a';
    if (!ch[u][id]) {
      ch[u][id] = ++tot;
      memset(ch[tot], 0, sizeof(ch[tot]));
      f[tot] = d[tot] = len[tot] = 0;
      g[tot].clear();
    }
    u = ch[u][id];
    len[u] = i + 1;
  }
}
void build_ac() {
  queue<int> q;
  q.push(0);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    int r = f[u];
    for (int i = 0; i < 26; i++) {
      int v = ch[u][i];
      if (!v) {
        ch[u][i] = ch[r][i];
        continue;
      }
      q.push(v);
      f[v] = u ? ch[r][i] : 0;
    }
  }
}
void dfs(int u, int fa) {
  dp[u][0] = 0;
  dp[u][1] = 1;
  for (auto v : g[u]) {
    dfs(v, u);
    dp[u][0] += max(dp[v][0], dp[v][1]);
    dp[u][1] += dp[v][0];
  }
}
void solve() {
  int T;
  scanf("%d", &T);
  while (T--) {
    scanf("%d", &n);
    init();
    for (int i = 1; i <= n; i++) {
      scanf("%s", s);
      int len_s = strlen(s);
      insert(s, len_s);
    }
    build_ac();
    for (int i = 1; i <= tot; i++) {
      if (f[i] && len[f[i]] == len[i] - 1) {
        add(f[i], i);
        d[i]++;
      }
    }
    int res = 0;
    for (int i = 1; i <= tot; i++) {
      if (!d[i]) {
        dfs(i, 0);
        res += max(dp[i][0], dp[i][1]);
      }
    }
    printf("%d\n", res);
  }
}
int main() {
  solve();
  return 0;
}
