#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 3;
const long long INF = 1e18 + 123;
int sz, dp[N][4];
bool used[N];
vector<int> g[N];
struct vertex {
  int next[30];
} t[N];
void add_string(string s) {
  int v = 0;
  for (int i = 0; i < s.size(); i++) {
    int c = int(s[i] - 'a');
    if (t[v].next[c] == 0) {
      sz++;
      memset(t[sz].next, 0, sizeof t[sz].next);
      t[v].next[c] = sz;
    }
    v = t[v].next[c];
  }
}
void dfs(int v, int u) {
  if (v != 0) {
    g[v].push_back(u);
    g[u].push_back(v);
  }
  for (int i = 0; i < 26; i++) {
    if (t[v].next[i] != 0 && t[u].next[i] != 0) {
      dfs(t[v].next[i], t[u].next[i]);
    }
  }
}
int calc(int v) {
  used[v] = 1;
  dp[v][0] = 0;
  dp[v][1] = 1;
  for (int i = 0; i < g[v].size(); i++) {
    int to = g[v][i];
    if (!used[to]) {
      calc(to);
      dp[v][1] += dp[to][0];
      dp[v][0] += max(dp[to][1], dp[to][0]);
    }
  }
  return max(dp[v][0], dp[v][1]);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int q;
  cin >> q;
  while (q--) {
    sz = 0;
    int n;
    cin >> n;
    memset(t[0].next, 0, sizeof t[0].next);
    memset(used, 0, sizeof used);
    for (int i = 0; i < n; i++) {
      string s;
      cin >> s;
      add_string(s);
    }
    for (int i = 1; i <= sz; i++) {
      g[i].clear();
    }
    for (int i = 0; i < 26; i++) {
      if (t[0].next[i] != 0) {
        dfs(0, t[0].next[i]);
      }
    }
    int ans = 0;
    for (int i = 1; i <= sz; i++) {
      if (!used[i]) {
        ans += calc(i);
      }
    }
    cout << ans << "\n";
  }
  return 0;
}
