#include <bits/stdc++.h>
using namespace std;
const long long N = 1e6 + 10;
const long long M = 3e8 + 1;
const long long big = 1e18;
const long long hsh2 = 1964325029;
const long long mod = 1e9 + 7;
const long double EPS = 1e-14;
const long long block = 700;
const long long shift = 2e4 + 1e3;
long long n, m;
long long second[N][26];
long long k[N], p[N], b[N], gl[N];
long long rt = 1, cur = 2;
vector<long long> g[N];
void add(string x) {
  long long v = rt;
  string sub;
  for (auto u : x) {
    long long c = u - 'a';
    if (!second[v][c]) {
      second[v][c] = cur++;
      p[second[v][c]] = v, b[second[v][c]] = c, k[second[v][c]] = 0;
      for (int i = 0; i < 26; i++) second[second[v][c]][i] = 0;
    }
    sub += u;
    gl[second[v][c]] = gl[v] + 1;
    v = second[v][c];
  }
}
void crtsuf(long long v) {
  if (p[v] != 1)
    k[v] = second[k[p[v]]][b[v]];
  else
    k[v] = 1;
  if (k[v] != 1 && gl[v] - gl[k[v]] == 1)
    g[k[v]].push_back(v), g[v].push_back(k[v]);
  for (int i = 0; i < 26; i++)
    if (!second[v][i]) second[v][i] = second[k[v]][i];
}
void bldsuf() {
  queue<int> q;
  q.push(1);
  while (q.size()) {
    long long v = q.front();
    q.pop();
    for (int i = 0; i < 26; i++)
      if (second[v][i] && v != second[v][i]) q.push(second[v][i]);
    crtsuf(v);
  }
}
long long t;
bool was[N];
pair<long long, long long> dfs(long long v, long long p) {
  pair<long long, long long> ans = make_pair(1, 0);
  was[v] = 1;
  for (auto u : g[v]) {
    if (p == u) continue;
    pair<long long, long long> z = dfs(u, v);
    ans.second += max(z.first, z.second), ans.first += z.first;
  }
  swap(ans.first, ans.second);
  return ans;
}
void solve() {
  for (int i = 0; i < 26; i++) second[1][i] = 0;
  cur = 2;
  k[1] = 1, p[1] = 1;
  long long z = 0;
  cin >> n;
  string b;
  while (n--) {
    cin >> b;
    add(b);
    z += b.size();
  }
  for (int i = 0; i < 26; i++)
    if (!second[1][i]) second[1][i] = 1;
  for (int i = 1; i < cur; i++) g[i].clear(), was[i] = 0;
  bldsuf();
  long long ans = 0;
  for (int i = 2; i < cur; i++) {
    if (was[i]) continue;
    pair<long long, long long> z = dfs(i, 0);
    ans += max(z.first, z.second);
  }
  cout << ans << '\n';
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> t;
  while (t--) solve();
}
