#include <bits/stdc++.h>
using namespace std;
const int K = 269;
const int MS = 2;
const int MOD[MS] = {(int)1e9 + 7, (int)1e9 + 9};
const int MAXN = 1e6 + 69;
using hsh = vector<long long>;
struct hj {
  int shift = MS == 1 ? 0 : 32 / (MS - 1);
  size_t operator()(const hsh& h) const {
    long long res = 0;
    for (int M = 0; M < MS; M++) res <<= shift, res ^= h[M];
    return res;
  }
};
int t;
int n;
set<int> a[MAXN];
unordered_map<hsh, int, hj> mp;
vector<string> str;
int check[MAXN];
int cnt;
int ans;
void build(hsh& h, char c) {
  for (int M = 0; M < MS; M++) h[M] = (c + h[M] * K) % MOD[M];
}
void init() {
  for (int i = 1; i <= cnt; i++) {
    a[i].clear();
    check[i] = 0;
  }
  mp.clear();
  cnt = 0;
  ans = 0;
}
bool dfs(int u) {
  check[u] = 1;
  int tookChild = 0;
  for (int v : a[u])
    if (!check[v]) tookChild |= dfs(v);
  ans += tookChild ^ 1;
  return tookChild ^ 1;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> t;
  while (t--) {
    init();
    cin >> n;
    str.resize(n + 1);
    for (int i = 1; i <= n; i++) cin >> str[i], str[i] = ' ' + str[i];
    for (int i = 1; i <= n; i++) {
      string& s = str[i];
      hsh h(MS);
      for (int j = 1; j < (int)s.size(); j++) {
        build(h, s[j]);
        if (!mp.count(h)) mp[h] = ++cnt;
      }
    }
    for (int i = 1; i <= n; i++) {
      string& s = str[i];
      hsh h(MS), h2(MS);
      for (int j = 1; j < (int)s.size(); j++) {
        build(h, s[j]);
        if (j >= 2) {
          build(h2, s[j]);
          if (mp.count(h2)) {
            int u = mp[h], v = mp[h2];
            a[u].insert(v);
            a[v].insert(u);
          }
        }
      }
    }
    for (int i = 1; i <= cnt; i++)
      if (!check[i]) dfs(i);
    cout << ans << '\n';
  }
}
