#include <bits/stdc++.h>
using namespace std;
class node {
 public:
  int ch[26];
} t[1000010];
int nodecnt = 0, dp[1000010][2], fa[1000010];
vector<int> v[1000010];
bool vis[1000010];
int newnode() {
  int p = ++nodecnt;
  memset(t[p].ch, 0, sizeof(t[p].ch));
  return p;
}
void insert(char *s, int len) {
  int p = 0;
  for (int i = 0; i < len; i++) {
    if (!t[p].ch[s[i] - 'a']) t[p].ch[s[i] - 'a'] = newnode();
    p = t[p].ch[s[i] - 'a'];
  }
}
void dfs_similar(int p, int q) {
  if (p) v[p].push_back(q), fa[q] = p;
  for (int i = 0; i < 26; i++)
    if (t[p].ch[i] && t[q].ch[i]) dfs_similar(t[p].ch[i], t[q].ch[i]);
}
void dfs(int p) {
  vis[p] = 1;
  dp[p][0] = 0;
  dp[p][1] = 1;
  for (int i = 0; i < v[p].size(); i++) {
    dfs(v[p][i]);
    dp[p][0] += max(dp[v[p][i]][0], dp[v[p][i]][1]);
    dp[p][1] += dp[v[p][i]][0];
  }
}
int T, n, ans;
char buffer[1000010];
int main() {
  scanf("%d", &T);
  while (T--) {
    memset(t[0].ch, 0, sizeof(t[0].ch));
    nodecnt = 0;
    scanf("%d", &n);
    ans = 0;
    for (int i = 1; i <= n; i++) {
      scanf("%s", buffer);
      insert(buffer, strlen(buffer));
    }
    for (int i = 1; i <= nodecnt; i++) v[i].clear(), vis[i] = 0, fa[i] = 0;
    for (int i = 0; i < 26; i++)
      if (t[0].ch[i]) dfs_similar(0, t[0].ch[i]);
    for (int i = 1; i <= nodecnt; i++) {
      if (!vis[i] && !fa[i]) {
        dfs(i);
        ans += max(dp[i][0], dp[i][1]);
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
