#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 5;
int ch[maxn][26], dep[maxn];
int f[maxn];
int sz;
std::vector<int> G[maxn];
char str[maxn];
bool vis[maxn];
int dp[maxn][2];
void init() {
  sz = 1;
  memset(ch[0], 0, sizeof(ch[0]));
}
inline int idx(char s) { return s - 'a'; }
void insert(char *s) {
  int len = strlen(s);
  int u = 0;
  for (int i = 0; i < len; i++) {
    int c = idx(s[i]);
    if (!ch[u][c]) {
      memset(ch[sz], 0, sizeof(ch[sz]));
      ch[u][c] = sz++;
    }
    u = ch[u][c];
    dep[u] = i + 1;
  }
}
void getfail() {
  queue<int> q;
  f[0] = 0;
  for (int i = 0; i < sz; i++) G[i].clear();
  for (int c = 0; c < 26; c++) {
    int u = ch[0][c];
    if (u) {
      q.push(u);
      f[u] = 0;
    }
  }
  while (!q.empty()) {
    int r = q.front();
    q.pop();
    for (int c = 0; c < 26; c++) {
      int u = ch[r][c];
      if (u) {
        if (r)
          f[u] = ch[f[r]][c];
        else
          f[u] = 0;
        q.push(u);
      }
    }
  }
  for (int i = 1; i < sz; i++)
    if (f[i]) {
      if (dep[i] - dep[f[i]] == 1) {
        G[f[i]].push_back(i);
        G[i].push_back(f[i]);
      }
    }
}
void dfs(int u, int fa) {
  vis[u] = true;
  dp[u][0] = 0, dp[u][1] = 1;
  for (int v : G[u])
    if (v != fa) {
      dfs(v, u);
      dp[u][0] += max(dp[v][0], dp[v][1]);
      dp[u][1] += dp[v][0];
    }
}
int main(int argc, char const *argv[]) {
  int T;
  cin >> T;
  while (T--) {
    init();
    memset(vis, false, sizeof(vis));
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
      scanf("%s", str);
      insert(str);
    }
    getfail();
    int ans = 0;
    for (int i = 1; i < sz; i++)
      if (!vis[i]) {
        dfs(i, -1);
        ans += max(dp[i][0], dp[i][1]);
      }
    printf("%d\n", ans);
  }
  return 0;
}
