#include <bits/stdc++.h>
using namespace std;
const int N = 1000010;
int tot;
struct node {
  node *ch[26], *fail;
  int len, id;
  node* init(int tlen) {
    memset(ch, 0, sizeof(ch));
    fail = NULL;
    len = tlen;
    return this;
  }
} * root, spT[N];
vector<int> g[N];
void addin(char* c) {
  node* tmp = root;
  while (*c != '\0') {
    int t = *c - 'a';
    if (tmp->ch[t] == NULL) tmp->ch[t] = spT[++tot].init(tmp->len + 1);
    tmp = tmp->ch[t];
    c++;
  }
}
queue<node*> q;
int en, st;
void getfail() {
  q.push(root);
  while (!q.empty()) {
    node* tmp = q.front();
    q.pop();
    for (int t = 0; t < 26; t++)
      if (tmp->ch[t] != NULL) {
        if (tmp == root)
          tmp->ch[t]->fail = root;
        else {
          node* p = tmp->fail;
          while (p != root && p->ch[t] == NULL) p = p->fail;
          if (p->ch[t] != NULL)
            tmp->ch[t]->fail = p->ch[t];
          else
            tmp->ch[t]->fail = root;
        }
        q.push(tmp->ch[t]);
      }
  }
}
char S[N];
int f[N][2];
int dfs(int x) {
  f[x][0] = 0;
  f[x][1] = 1;
  for (auto p : g[x]) {
    dfs(p);
    f[x][1] += f[p][0];
    f[x][0] += max(f[p][0], f[p][1]);
  }
  return max(f[x][0], f[x][1]);
}
bool v[N];
int main() {
  int T, n;
  for (int i = (1); i <= (N - 1); i++) spT[i].id = i;
  cin >> T;
  while (T--) {
    root = spT[tot = 1].init(0);
    cin >> n;
    for (int i = (1); i <= (n); i++) {
      scanf("%s", S);
      addin(S);
    }
    getfail();
    for (int i = (1); i <= (tot); i++) g[i].clear(), v[i] = 0;
    for (int i = (1); i <= (tot); i++) {
      node* tmp = &spT[i];
      if (tmp->fail && tmp->fail != root && tmp->fail->len + 1 == tmp->len) {
        g[tmp->fail->id].push_back(tmp->id);
        v[tmp->id] = 1;
      }
    }
    int ans = 0;
    for (int i = (2); i <= (tot); i++)
      if (!v[i]) ans += dfs(i);
    cout << ans << endl;
  }
  return 0;
}
