#include <bits/stdc++.h>
const int maxn = 1e6 + 10;
const int N = 2e5 + 10;
using namespace std;
long long gcd(long long p, long long q) { return q == 0 ? p : gcd(q, p % q); }
long long qmul(long long p, long long q, long long mo) {
  long long f = 0;
  while (q) {
    if (q & 1) f = (f + p) % mo;
    p = (p + p) % mo;
    q >>= 1;
  }
  return f;
}
long long qpow(long long p, long long q, long long mo) {
  long long f = 1;
  while (q) {
    if (q & 1) f = f * p % mo;
    p = p * p % mo;
    q >>= 1;
  }
  return f;
}
int n, m, k, t, tot;
vector<int> e[maxn];
bool vis[maxn];
char a[maxn];
const int RA = 1e9 + 7, RB = 1e9 + 9, BASE = 727;
long long pr[maxn];
map<long long, int> id;
pair<int, int> dfs(int x) {
  vis[x] = true;
  int i;
  pair<int, int> ans = make_pair(0, 1);
  for (i = 0; i <= (int)e[x].size() - 1; i++) {
    int z = e[x][i];
    if (vis[z]) continue;
    pair<int, int> now = dfs(z);
    ans.first += max(now.first, now.second);
    ans.second += now.first;
  }
  return ans;
}
int main() {
  int i, j;
  scanf("%d", &t);
  while (t--) {
    tot = 0;
    id.clear();
    scanf("%d", &n);
    for (i = 1; i <= (int)n; i++) {
      scanf("%s", a);
      long long now[2] = {0};
      long long pre[2] = {0};
      for (j = 0; a[j]; j++) {
        now[0] = (now[0] * BASE + a[j]) % RA;
        now[1] = (now[1] * BASE + a[j]) % RB;
        long long p = now[0] * RB + now[1];
        long long q;
        if (!id.count(p)) id[p] = ++tot;
        if (j >= 1) {
          pre[0] = (pre[0] * BASE + a[j]) % RA;
          pre[1] = (pre[1] * BASE + a[j]) % RB;
          q = pre[0] * RB + pre[1];
          pr[id[p]] = q;
        } else
          pr[id[p]] = -1;
      }
    }
    for (i = 1; i <= (int)tot; i++) {
      if (pr[i] == -1) continue;
      if (id.count(pr[i])) {
        int x = id[pr[i]];
        e[x].push_back(i);
        e[i].push_back(x);
      }
    }
    int ret = 0;
    for (i = 1; i <= (int)tot; i++)
      if (!vis[i]) {
        pair<int, int> ans = dfs(i);
        ret += max(ans.first, ans.second);
      }
    for (i = 1; i <= (int)tot; i++) vis[i] = false, e[i].clear();
    printf("%d\n", ret);
  }
  return 0;
}
