#include <bits/stdc++.h>
using namespace std;
string itosm(long long x) {
  if (x == 0) return "0";
  string ans = "";
  while (x > 0) {
    ans += ((x % 10) + '0');
    x /= 10;
  }
  reverse(ans.begin(), ans.end());
  return ans;
}
long long stoim(string str) {
  long long ans = 0;
  long long k = 1;
  for (int i = str.length() - 1; i >= 0; i--) {
    ans += (str[i] - '0') * k;
    k *= 10;
  }
  return ans;
}
const long long infll = 1e18 + 3;
const int inf = 1009000999;
const double eps = 1e-7;
const int maxn = 1e6 + 777;
const int baseint = 1000200013;
const long long basell = 1e18 + 3;
const long double PI = acos(-1.0);
const long long mod = 1e9 + 7;
unordered_set<long long> st, p;
vector<string> ss;
vector<vector<pair<long long, long long> > > h1, h2;
vector<pair<int, int> > nd;
void inline solve() {
  int n, m;
  cin >> m;
  string s;
  st.clear();
  p.clear();
  ss.clear();
  h1.clear();
  h2.clear();
  h1.resize(m);
  h2.resize(m);
  nd.clear();
  for (int jj = 0; jj < m; jj++) {
    cin >> s;
    ss.push_back(s);
    n = s.length();
    long long mod1 = 1e9 + 7, mod2 = 1000022809;
    h1[jj].push_back(make_pair(s[0] - 'a' + 1, s[0] - 'a' + 1));
    nd.push_back(make_pair(n, jj));
    if (n > 1) {
      h2[jj].push_back(make_pair(s[1] - 'a' + 1, s[1] - 'a' + 1));
    }
    for (int i = 1; i < n; i++) {
      h1[jj].push_back(
          make_pair((h1[jj].back().first * 29 + (s[i] - 'a' + 1)) % mod1,
                    (h1[jj].back().second * 31 + (s[i] - 'a' + 1)) % mod2));
    }
    for (int i = 2; i < n; i++) {
      h2[jj].push_back(
          make_pair((h2[jj].back().first * 29 + (s[i] - 'a' + 1)) % mod1,
                    (h2[jj].back().second * 31 + (s[i] - 'a' + 1)) % mod2));
    }
  }
  sort(nd.rbegin(), nd.rend());
  int l = nd[0].first;
  while (l > 0) {
    for (int i = 0; i < nd.size(); i++) {
      if (l > nd[i].first) break;
      if (!p.count((h1[nd[i].second][l - 1].first << 31) +
                   h1[nd[i].second][l - 1].second) &&
          (l - 2 < 0 || !st.count((h2[nd[i].second][l - 2].first << 31) +
                                  h2[nd[i].second][l - 2].second))) {
        st.insert((h1[nd[i].second][l - 1].first << 31) +
                  h1[nd[i].second][l - 1].second);
        if (l - 2 >= 0)
          p.insert((h2[nd[i].second][l - 2].first << 31) +
                   h2[nd[i].second][l - 2].second);
      }
    }
    l--;
  }
  cout << st.size();
}
int main() {
  srand(time(0));
  ios_base::sync_with_stdio(0);
  ;
  int t;
  cin >> t;
  while (t--) {
    solve();
    cout << "\n";
  }
  return 0;
}
