#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const unsigned gen_seed =
    std::chrono::system_clock::now().time_since_epoch().count();
std::mt19937_64 gen(gen_seed);
struct vertex {
  int next[26];
  int pick = 1;
  void clear() {
    for (int i = 0; i < 26; i++) next[i] = -1;
    pick = 1;
  };
};
const int NMAX = 2000000;
vertex t[NMAX];
int par[NMAX];
int sz;
const int K = 26;
void add_string(const string& s) {
  int v = 0;
  for (size_t i = 0; i < s.length(); ++i) {
    char c = s[i] - 'a';
    if (t[v].next[c] == -1) {
      t[v].next[c] = sz;
      par[sz] = v;
      t[sz++].clear();
    }
    v = t[v].next[c];
  }
}
int ans = 0;
void dfs(int v) {
  if (v > 0) ans += t[v].pick;
  for (int i = 0; i < 26; i++)
    if (t[v].next[i] != -1) dfs(t[v].next[i]);
}
int main() {
  int tn;
  scanf("%d", &tn);
  char c[1000100];
  for (int it = 0; it < tn; it++) {
    sz = 1;
    t[0].clear();
    int n;
    scanf("%d", &n);
    std::vector<string> s;
    std::vector<std::pair<int, int> > ord;
    for (int i = 0; i < n; i++) {
      scanf("%s", c);
      s.push_back(string(c));
      add_string(s.back());
    }
    std::vector<int> pn(n, 1);
    std::vector<int> pt(n, 0);
    std::vector<int> ptsuf(n, 0);
    for (int i = 0; i < n; i++) {
      pt[i] = t[0].next[s[i][0] - 'a'];
      while (pn[i] < s[i].size() && t[ptsuf[i]].next[s[i][pn[i]] - 'a'] != -1) {
        char c = s[i][pn[i]] - 'a';
        pt[i] = t[pt[i]].next[c];
        ptsuf[i] = t[ptsuf[i]].next[c];
        pn[i]++;
      }
      ord.push_back(make_pair(pn[i], i));
    }
    sort((ord).begin(), (ord).end());
    reverse((ord).begin(), (ord).end());
    int l = ord[0].first;
    ans = 0;
    for (int i = l; i >= 1; i--) {
      int j = 0;
      while (j < n && ord[j].first == i) {
        int ind = ord[j].second;
        if (t[pt[ind]].pick) {
          t[pt[ind]].pick = 0;
          ans++;
          t[ptsuf[ind]].pick = 0;
        }
        pt[ind] = par[pt[ind]];
        ptsuf[ind] = par[ptsuf[ind]];
        ord[j].first--;
        j++;
      }
    }
    dfs(0);
    printf("%d\n", ans);
  }
}
