#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 5;
const int maxm = 26;
int tot, n;
int ch[maxn][maxm];
int newNode() {
  memset(ch[tot], 0, sizeof ch[tot]);
  return tot++;
}
char s[maxn];
void add(char *s) {
  int len = strlen(s);
  int cur = 0;
  for (int i = 0; i < len; ++i) {
    int v = s[i] - 'a';
    if (ch[cur][v] == 0) ch[cur][v] = newNode();
    cur = ch[cur][v];
  }
}
string str[maxn];
vector<int> G[maxn];
void buildGraph(const string &s) {
  int a = 0;
  int b = ch[0][s[0] - 'a'];
  for (int i = 1; i < s.size(); ++i) {
    int v = s[i] - 'a';
    a = ch[a][v];
    b = ch[b][v];
    if (a == 0 || b == 0) return;
    G[a].push_back(b);
    G[b].push_back(a);
  }
}
int f[maxn][2];
bool vis[maxn];
void dfs(int u) {
  vis[u] = true;
  f[u][0] = 0;
  f[u][1] = 1;
  for (auto v : G[u]) {
    if (vis[v]) continue;
    dfs(v);
    f[u][0] += max(f[v][0], f[v][1]);
    f[u][1] += f[v][0];
  }
}
int main() {
  int T;
  cin >> T;
  while (T--) {
    tot = 1;
    cin >> n;
    memset(ch[0], 0, sizeof ch[0]);
    for (int i = 0; i < n; ++i) {
      scanf("%s", s);
      add(s);
      str[i] = s;
    }
    for (int i = 1; i < tot; ++i) G[i].clear();
    for (int i = 0; i < n; ++i) buildGraph(str[i]);
    for (int i = 1; i <= tot; ++i) vis[i] = false;
    int res = 0;
    for (int i = 1; i < tot; ++i) {
      if (!vis[i]) {
        dfs(i);
        res += max(f[i][0], f[i][1]);
      }
    }
    cout << res << endl;
  }
  return 0;
}
