#include <bits/stdc++.h>
using namespace std;
int n;
string s[1001000];
vector<int> IDX[1001000];
int cnt = -1;
struct Graph {
  int n;
  vector<vector<int> > e;
  vector<int> DEG, dp[2];
  vector<bool> fr;
  int cnt[2];
  void reset(int _n) {
    n = _n;
    e.clear();
    e.resize(n + 1);
    DEG.clear();
    DEG.resize(n + 1);
    fr.clear();
    fr.resize(n + 1);
    dp[0] = dp[1] = DEG;
  }
  void addEdge(int u, int v) {
    e[u].push_back(v);
    DEG[v]++;
  }
  void dfs(int u) {
    fr[u] = false;
    dp[0][u] = 0;
    dp[1][u] = 1;
    for (int v : e[u])
      if (fr[v]) {
        dfs(v);
        dp[0][u] += max(dp[0][v], dp[1][v]);
        dp[1][u] += dp[0][v];
      }
  }
  int MaxIndependence() {
    int result = 0;
    for (int i = 1; i <= n; ++i) fr[i] = true;
    for (int i = 1; i <= n; ++i)
      if (DEG[i] == 0) {
        dfs(i);
        result += max(dp[0][i], dp[1][i]);
      }
    return result;
  }
} G;
struct Trie {
  Trie *child[26];
  int val;
};
Trie *getNode(void) {
  Trie *p = NULL;
  p = (Trie *)malloc(sizeof(Trie));
  for (int i = 0; i < 26; ++i) p->child[i] = NULL;
  p->val = ++cnt;
  return p;
}
void Insert(Trie *root, int u) {
  Trie *p = root;
  for (int i = 0; i < (int)s[u].size(); ++i) {
    int idx = s[u][i] - 'a';
    if (p->child[idx] == NULL) p->child[idx] = getNode();
    p = p->child[idx];
    IDX[u].push_back(p->val);
  }
}
void Find(Trie *root, int u) {
  Trie *p = root;
  for (int i = 1; i <= (int)s[u].size() - 1; ++i) {
    int idx = s[u][i] - 'a';
    if (p->child[idx] == NULL) return;
    p = p->child[idx];
    G.addEdge(p->val, IDX[u][i]);
  }
}
void Del(Trie *root) {
  for (int i = 0; i < 26; ++i) {
    if (root->child[i] != NULL) Del(root->child[i]);
  }
  delete[] root;
}
void solve() {
  cnt = -1;
  Trie *root = getNode();
  cin >> n;
  for (int i = 0; i < n; ++i) IDX[i].clear();
  for (int i = 0; i < n; ++i) cin >> s[i], Insert(root, i);
  G.reset(cnt);
  for (int i = 0; i < n; ++i) Find(root, i);
  Del(root);
  cout << G.MaxIndependence() << '\n';
}
int main() {
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  ios::sync_with_stdio(false);
  int test;
  cin >> test;
  while (test--) {
    solve();
  }
}
