#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 100;
int n, sl, res;
int c[maxn][27];
int d[maxn][2], trace[maxn];
vector<int> a[maxn];
vector<string> q;
void init() {
  q.clear();
  for (int i = 1; i <= sl; i++) {
    for (int j = 0; j < 26; j++) {
      c[i][j] = 0;
    }
  }
}
void nhap() {
  string s;
  cin >> n;
  getline(cin, s);
  init();
  res = 0;
  sl = 1;
  for (int i = 1; i <= n; i++) {
    getline(cin, s);
    q.push_back(s);
    int root = 1;
    for (int j = 0; j < s.size(); j++) {
      int x = s[j] - 'a';
      if (c[root][x] == 0) {
        sl++;
        c[root][x] = sl;
      }
      root = c[root][x];
    }
  }
}
void taodothi(string s) {
  int root = 1;
  int root1 = c[1][s[0] - 'a'];
  if (root1 == 0) return;
  for (int i = 1; i < s.size(); i++) {
    int x = s[i] - 'a';
    root = c[root][x];
    root1 = c[root1][x];
    if (root1 == 0 || root == 0) {
      return;
    }
    trace[root] = 1;
    trace[root1] = 1;
    a[root].push_back(root1);
    a[root1].push_back(root);
  }
}
void dfs(int u) {
  trace[u] = 0;
  d[u][0] = 0;
  d[u][1] = 1;
  for (int i = 0; i < a[u].size(); i++) {
    int v = a[u][i];
    if (trace[v] == 1) {
      dfs(v);
      d[u][0] += d[v][1];
      d[u][1] += min(d[v][0], d[v][1]);
    }
  }
}
void xuli() {
  for (int i = 1; i <= sl; i++) {
    a[i].clear();
  }
  for (int i = 0; i < q.size(); i++) {
    taodothi(q[i]);
  }
  res = sl - 1;
  for (int i = 1; i <= sl; i++) {
    if (trace[i] == 1) {
      dfs(i);
      res -= min(d[i][0], d[i][1]);
    }
  }
  cout << res << endl;
}
int main() {
  int test;
  cin >> test;
  while (test--) {
    nhap();
    xuli();
  }
}
