#include <bits/stdc++.h>
using namespace std;
int n;
string str[1000006];
vector<long long> h0[1000006], h1[1000006];
set<pair<int, int> > p;
set<long long> h;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    h.clear();
    cin >> n;
    for (int i = (0); i <= (n - 1); ++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 = (1); j <= (((int)str[i].size()) - 1); ++j)
        h0[i][j] = (h0[i][j - 1] * 107 + str[i][j]) % 115797848077099,
        h1[i][j] = (h1[i][j - 1] * 107 + str[i][j]) % 115797848077099;
    }
    for (int i = (0); i <= (n - 1); ++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 has = h0[q.second][q.first];
      if (h.find(has) == h.end()) {
        h.insert(has);
        h.insert(h1[q.second][q.first]);
        ans++;
      }
      if (q.first != 0) p.insert(q);
    }
    cout << ans << endl;
  }
  return 0;
}
