#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
void ckmin(T &a, U b) {
  if (a > b) a = b;
}
template <class T, class U>
void ckmax(T &a, U b) {
  if (a < b) a = b;
}
int TC, T;
int N;
vector<int> str[2000013];
map<int, int> ch[2000013];
map<pair<int, int>, int> mp;
int fc[2000013], depth[2000013];
pair<int, int> hashval[2000013];
pair<int, int> msg[2000013];
vector<int> edge[2000013];
bitset<2000013> go;
int dp[2000013][2];
int ans;
vector<int> stov(string s) {
  vector<int> res(((int)(s).size()));
  for (auto i = (0); i < (((int)(s).size())); i++) {
    res[i] = (s[i] - 'a' + 1);
  }
  return res;
}
int mul(int a, int b, long long mod) { return ((long long)a * b % mod); }
int ad(int a, int b, int mod) {
  a += b;
  if (a >= mod) a -= mod;
  return a;
}
int sb(int a, int b, int mod) {
  a -= b;
  if (a < 0) a += mod;
  return a;
}
void solve(int u) {
  for (int v : edge[u]) {
    solve(v);
  }
  int mn = 1000000931;
  dp[u][0] = 1;
  dp[u][1] = 0;
  for (int v : edge[u]) {
    dp[u][1] += dp[v][0];
    dp[u][0] += dp[v][1];
  }
  if (u != 0) ckmin(dp[u][1], dp[u][0]);
}
void ins(vector<int> s) {
  int node = 0;
  for (auto i = (0); i < (((int)(s).size())); i++) {
    int c = s[i];
    if (ch[node].find(c) == ch[node].end()) {
      ch[node][c] = T;
      hashval[T].first =
          ad(mul(hashval[node].first, 1000007, 1000000931), c, 1000000931);
      hashval[T].second =
          ad(mul(hashval[node].second, 1000007, 1000000933), c, 1000000933);
      msg[T].first = (node == 0 ? 0
                                : ad(mul(msg[node].first, 1000007, 1000000931),
                                     c, 1000000931));
      msg[T].second =
          (node == 0
               ? 0
               : ad(mul(msg[node].second, 1000007, 1000000933), c, 1000000933));
      mp[hashval[T]] = T;
      fc[T] = s[0];
      depth[T] = depth[node] + 1;
      T++;
    }
    node = ch[node][c];
  }
}
int32_t main() {
  cout << fixed << setprecision(12);
  cerr << fixed << setprecision(4);
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> TC;
  while (TC--) {
    cin >> N;
    for (auto i = (0); i < (N); i++) {
      string temps;
      cin >> temps;
      str[i] = stov(temps);
    }
    T = 1;
    hashval[0] = {0, 0};
    mp[{0, 0}] = 0;
    for (auto i = (0); i < (N); i++) {
      ins(str[i]);
    }
    for (auto i = (0); i < (T); i++) {
      go[i] = true;
    }
    for (auto i = (1); i < (T); i++) {
      int c = fc[i], d = depth[i];
      auto it = mp.find(msg[i]);
      if (it != mp.end()) {
        edge[it->second].push_back(i);
        go[i] = false;
      }
    }
    ans = T;
    for (auto i = (0); i < (T); i++) {
      if (go[i]) {
        solve(i);
        ans -= (i == 0 ? dp[i][0] : dp[i][1]);
      }
    }
    cout << ans << '\n';
    for (auto i = (0); i < (T); i++) {
      ch[i].clear();
      edge[i].clear();
    }
    mp.clear();
  }
  return 0;
}
