#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5, C = 26;
struct node {
  node *ch[C], *fail;
  int len;
  vector<node *> adj;
  node(int len = 0) : len(len) {
    memset(ch, NULL, sizeof(ch));
    fail = NULL;
    adj.clear();
  }
} pol[N], *tot = pol, *root;
node *newnode(int len = 0) {
  *tot = node(len);
  return tot++;
}
void insert(char *t) {
  int n = strlen(t);
  node *p = root;
  for (int i = 0; i < n; ++i) {
    int v = t[i] - 'a';
    if (!p->ch[v]) p->ch[v] = newnode(p->len + 1);
    p = p->ch[v];
  }
}
void BFS() {
  root->fail = root;
  queue<node *> q;
  q.push(root->fail = root);
  while (!q.empty()) {
    node *x = q.front();
    q.pop();
    for (int i = 0; i < C; ++i)
      if (x->ch[i]) {
        node *&y = x->ch[i];
        y->fail = x == root ? root : x->fail->ch[i];
        q.push(y);
        y->fail->adj.push_back(y);
      } else {
        x->ch[i] = x == root ? root : x->fail->ch[i];
      }
  }
}
char s[N];
pair<bool, int> dfs(node *x, int &res) {
  bool use = 0;
  int cnt = 0;
  res++;
  for (node *u : x->adj) {
    auto tmp = dfs(u, res);
    cnt += tmp.second;
    if (x->len + 1 == u->len && !use && !tmp.first) {
      use = 1;
      cnt++;
    }
  }
  return {use, cnt};
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    tot = pol;
    root = newnode();
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
      scanf("%s", s);
      insert(s);
    }
    BFS();
    int ans = 0;
    for (node *x : root->adj) {
      int res, tot = 0;
      res = dfs(x, tot).second;
      ans += tot - res;
    }
    printf("%d\n", ans);
  }
}
