#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T POW(T B, T P) {
  if (P == 0) return 1;
  if (P & 1)
    return B * POW(B, P - 1);
  else
    return SQR(POW(B, P / 2));
}
template <class T>
inline T BMOD(T p, T e, T m) {
  T ret = 1;
  while (e) {
    if (e & 1) ret = (ret * p) % m;
    p = (p * p) % m;
    e >>= 1;
  }
  return (T)ret;
}
template <typename T>
inline T ModInv(T b, T m) {
  return BMOD(b, m - 2, m);
}
template <typename T>
inline T ABS(T a) {
  if (a < 0)
    return -a;
  else
    return a;
}
template <typename T>
inline T gcd(T a, T b) {
  if (a < 0) return gcd(-a, b);
  if (b < 0) return gcd(a, -b);
  return (b == 0) ? a : gcd(b, a % b);
}
template <typename T>
inline T lcm(T a, T b) {
  if (a < 0) return lcm(-a, b);
  if (b < 0) return lcm(a, -b);
  return a * (b / gcd(a, b));
}
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};
int n, id;
string s;
unordered_map<long long int, int> ump;
unordered_set<long long int> st;
vector<pair<long long int, long long int> > vs;
long long int base1 = 57;
long long int base2 = 727;
long long int MOD1 = (1e9 + 7);
long long int MOD2 = (1e9 + 9);
vector<int> ad[1000001];
int vis[1000005][2];
int dp[1000005][2], cs;
int go(int node, int fl, int par = 0) {
  if (vis[node][fl] == cs) return dp[node][fl];
  vis[node][fl] = cs;
  int ret = fl;
  for (int i = 0; i < ad[node].size(); i++) {
    if (ad[node][i] != par) {
      if (fl)
        ret += go(ad[node][i], fl ^ 1, node);
      else
        ret += max(go(ad[node][i], fl ^ 1, node), go(ad[node][i], fl, node));
    }
  }
  return dp[node][fl] = ret;
}
int main() {
  cs = 1;
  int t, tc = 1;
  scanf("%d", &t);
  while (t--) {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
      cin >> s;
      int l = s.size();
      long long int h1 = 0;
      long long int h11 = 0;
      long long int h2 = 0;
      long long int h22 = 0;
      for (int i1 = 0; i1 < l; i1++) {
        h1 = (h1 * base1 + s[i1]) % MOD1;
        h11 = (h11 * base2 + s[i1]) % MOD2;
        if (i1 > 0) {
          h2 = (h2 * base1 + s[i1]) % MOD1;
          h22 = (h22 * base2 + s[i1]) % MOD2;
          vs.push_back(make_pair(h1 * MOD1 + h11, h2 * MOD1 + h22));
        }
        st.insert(h1 * MOD1 + h11);
      }
    }
    sort(vs.begin(), vs.end());
    vs.erase(unique(vs.begin(), vs.end()), vs.end());
    id = 1;
    for (auto &i : st) {
      ump[i] = id;
      id++;
    }
    for (auto &it : vs) {
      if (st.find(it.second) != st.end()) {
        int u = ump[it.first];
        int v = ump[it.second];
        ad[u].push_back(v);
        ad[v].push_back(u);
      }
    }
    int ans = 0;
    for (int i = 1; i < id; i++) {
      if (vis[i][0] == cs && vis[i][1] == cs) {
      } else {
        ans += max(go(i, 0), go(i, 1));
      }
    }
    printf("%d", ans), puts("");
    for (int i = 1; i < id; i++) ad[i].clear();
    st.clear();
    ump.clear();
    vs.clear();
    cs++;
  }
  return 0;
}
