#include <bits/stdc++.h>
using namespace std;
const int M = 1000005;
int read() {
  int x = 0, flag = 1;
  char c;
  while ((c = getchar()) < '0' || c > '9')
    if (c == '-') flag = -1;
  while (c >= '0' && c <= '9')
    x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
  return x * flag;
}
int T, n, m;
char s[M];
string t[M];
struct edge {
  int v, next;
  edge(int V = 0, int N = 0) : v(V), next(N) {}
};
struct trie {
  int cnt, tot, f[M], ch[M][26], dp[M][2];
  edge e[2 * M];
  int flag[M];
  void init() {
    cnt = 1;
    tot = 0;
    memset(ch[1], 0, sizeof ch[1]);
  }
  int newnode() {
    cnt++;
    memset(ch[cnt], 0, sizeof ch[cnt]);
    return cnt;
  }
  void add() {
    m = strlen(s);
    for (int i = 0, p = 1; i < m; i++) {
      int c = s[i] - 'a';
      if (!ch[p][c]) ch[p][c] = newnode();
      p = ch[p][c];
    }
  }
  void link(int u, int v) {
    e[++tot] = edge(v, f[u]), f[u] = tot;
    e[++tot] = edge(u, f[v]), f[v] = tot;
  }
  void dfs(int u) {
    flag[u] = 1;
    dp[u][0] = 0;
    dp[u][1] = 1;
    for (int i = f[u]; i; i = e[i].next) {
      int v = e[i].v;
      if (flag[v]) continue;
      dfs(v);
      dp[u][1] += dp[v][0];
      dp[u][0] += max(dp[v][0], dp[v][1]);
    }
  }
  void build() {
    for (int i = 1; i <= cnt; i++) f[i] = flag[i] = 0;
    for (int i = 1; i <= n; i++) {
      int p1 = 1, p2 = ch[1][t[i][0] - 'a'];
      m = t[i].length();
      for (int j = 1; j < m; j++) {
        int c = t[i][j] - 'a';
        p1 = ch[p1][c];
        p2 = ch[p2][c];
        if (!p1) break;
        link(p1, p2);
      }
    }
    int ans = 0;
    for (int i = 2; i <= cnt; i++) {
      if (!flag[i]) {
        dfs(i);
        ans += max(dp[i][0], dp[i][1]);
      }
    }
    printf("%d\n", ans);
  }
} tr;
int main() {
  T = read();
  while (T--) {
    tr.init();
    n = read();
    for (int i = 1; i <= n; i++) {
      scanf("%s", s);
      tr.add();
      t[i] = s;
    }
    tr.build();
  }
}
