#include <bits/stdc++.h>
using namespace std;
int read() {
  int v = 0, f = 1;
  char c = getchar();
  while (c < 48 || 57 < c) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (48 <= c && c <= 57) v = (v << 3) + v + v + c - 48, c = getchar();
  return v * f;
}
const int N = 1e6 + 10;
struct Edge {
  int nxt, to;
} eg[N];
int head[N], en, f[N][2], to[N][26], n, suf[N], cnt, init[N];
char ch[N];
void setEdge(int u, int v) {
  eg[++en] = (Edge){head[u], v};
  head[u] = en;
}
void dfs(int u) {
  f[u][1] = 1;
  for (int e = head[u]; e; e = eg[e].nxt) {
    int v = eg[e].to;
    dfs(v);
    f[u][0] += max(f[v][1], f[v][0]);
    f[u][1] += f[v][0];
  }
}
int work() {
  n = read();
  for (int i = 1; i <= cnt; i++) {
    for (int j = 0; j < 26; j++) to[i][j] = 0;
    suf[i] = 0;
  }
  cnt = 1;
  for (int i = 1; i <= n; i++) {
    scanf("%s", ch);
    int now = 1;
    for (int j = 0; ch[j]; j++) {
      if (!to[now][ch[j] - 'a']) to[now][ch[j] - 'a'] = ++cnt;
      now = to[now][ch[j] - 'a'];
    }
    for (int j = 0; ch[j]; j++) ch[j] = 0;
  }
  for (int i = 0; i < 26; i++)
    if (to[1][i]) suf[to[1][i]] = 1;
  for (int i = 2; i <= cnt; i++)
    for (int j = 0; j < 26; j++)
      if (to[i][j] && suf[i]) suf[to[i][j]] = to[suf[i]][j];
  en = 0;
  for (int i = 1; i <= cnt; i++) head[i] = 0;
  for (int i = 1; i <= cnt; i++) init[i] = 0;
  for (int i = 2; i <= cnt; i++)
    if (suf[i]) setEdge(suf[i], i), init[i]++;
  for (int i = 1; i <= cnt; i++) f[i][0] = f[i][1] = 0;
  int ans = 0;
  int p = 0;
  for (int i = 1; i <= cnt; i++)
    if (!init[i]) {
      dfs(i);
      if (i == 1)
        ans += f[i][0];
      else
        ans += max(f[i][0], f[i][1]);
    }
  return ans;
}
int main() {
  int cas = read();
  while (cas--) printf("%d\n", work());
}
