#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};
vector<pair<int, pair<int, long long int> > > vs;
string s;
int n, id;
unordered_set<long long int> st;
long long int hs[1000005], pw[1000005];
int sz[1000005];
long long int mp[1000005];
int base1 = 31;
int MOD1 = 1e9 + 7;
int MOD2 = 1e9 + 9;
int main() {
  int t, tc = 1;
  scanf("%d", &t);
  while (t--) {
    scanf("%d", &n);
    sz[0] = 0;
    id = 1;
    int tot = 0;
    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 h22 = 0;
      long long int h2 = 0;
      for (int i1 = 1; i1 <= l; i1++) {
        h1 = (h1 * base1 + s[i1 - 1]) % MOD1;
        h11 = (h11 * base1 + s[i1 - 1]) % MOD2;
        if (i1 > 1) {
          h2 = (h2 * base1 + s[i1 - 1]) % MOD1;
          h22 = (h22 * base1 + s[i1 - 1]) % MOD2;
        }
        vs.push_back(make_pair(i1, make_pair(id, h2 * MOD1 + h22)));
        st.insert(h1 * MOD1 + h11);
        mp[id] = h1 * MOD1 + h11;
        id++;
      }
      sz[i] = sz[i - 1] + l;
      tot += l;
    }
    sort(vs.begin(), vs.end(),
         greater<pair<int, pair<int, long long int> > >());
    n = vs.size();
    long long int hv;
    int cnt = 0;
    for (int i = 1; i <= n; i++) {
      int l = vs[i - 1].first;
      hv = mp[vs[i - 1].second.first];
      if (st.find(hv) != st.end()) {
        long long int x = vs[i - 1].second.second;
        if (st.find(x) != st.end()) {
          st.erase(x);
        }
      }
    }
    cnt = st.size();
    printf("%d", cnt), puts("");
    st.clear();
    vs.clear();
    for (int i = 1; i <= n; i++) sz[i] = 0;
    for (int i = 1; i <= tot; i++) hs[i] = 0;
    for (int i = 1; i < id; i++) mp[i] = 0;
  }
  return 0;
}
