#include <bits/stdc++.h>
using namespace std;
template <class P, class Q>
inline void smin(P &a, Q b) {
  if (b < a) a = b;
}
template <class P, class Q>
inline void smax(P &a, Q b) {
  if (a < b) a = b;
}
const int maxn = 1000000 + 100;
const int base = 747;
const long long mod = 115797848077099;
int n;
string str[maxn];
vector<long long> h0[maxn], h1[maxn];
set<pair<int, int> > p;
set<long long> h;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    h.clear();
    cin >> n;
    for (int i = 0, i__n = (int)(n); i < i__n; ++i) {
      cin >> str[i];
      h0[i].resize((int((str[i]).size())));
      h1[i].resize((int((str[i]).size())));
      h0[i][0] = str[i][0];
      h1[i][0] = 0;
      for (int j = (int)(1), j__b = (int)((int((str[i]).size()))); j < j__b;
           ++j)
        h0[i][j] = (h0[i][j - 1] * base + str[i][j]) % mod,
        h1[i][j] = (h1[i][j - 1] * base + str[i][j]) % mod;
    }
    for (int i = 0, i__n = (int)(n); i < i__n; ++i)
      p.insert(pair<int, int>((int((str[i]).size())), i));
    int ans = 0;
    while (!p.empty()) {
      pair<int, int> q = *--p.end();
      p.erase(--p.end());
      q.first--;
      long long hash = h0[q.second][q.first];
      if (h.find(hash) == h.end()) {
        h.insert(hash);
        h.insert(h1[q.second][q.first]);
        ans++;
      }
      if (q.first != 0) p.insert(q);
    }
    cout << ans << endl;
  }
  return 0;
}
