#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f2f1f0f;
const long long LINF = 1ll * INF * INF;
const int MAX_N = 1e6 + 10, MAX_L = 1e6 + 10;
struct NODE {
  int go[26], bf;
  NODE() {
    for (int i = 0; i < 26; i++) go[i] = -1;
    bf = -1;
  }
};
NODE nd[MAX_L];
int allN, root = 1;
int N;
char temp[MAX_L];
vector<int> Ed[MAX_L];
int Dy[MAX_L][2];
bool Vis[MAX_L][2];
int getAns(int v, int use) {
  int &ans = Dy[v][use];
  if (Vis[v][use]) return ans;
  Vis[v][use] = true;
  int other = (use ? getAns(v, 0) : 0);
  int now = use;
  for (int w : Ed[v]) now += getAns(w, 1 - use);
  ans = max(other, now);
  return ans;
}
int main() {
  int TC;
  cin >> TC;
  while (TC--) {
    scanf("%d", &N);
    allN = 1;
    for (int o = 0; o < N; o++) {
      scanf("%s", temp);
      int n = strlen(temp);
      int now = root;
      for (int i = 0; i < n; i++) {
        int v = temp[i] - 'a';
        if (nd[now].go[v] == -1) nd[now].go[v] = ++allN;
        now = nd[now].go[v];
      }
    }
    queue<int> Q;
    vector<int> roots;
    for (int s = 0; s < 26; s++)
      if (nd[root].go[s] != -1) {
        Q.push(nd[root].go[s]), nd[nd[root].go[s]].bf = 1;
      }
    while (!Q.empty()) {
      int v = Q.front();
      Q.pop();
      if (nd[v].bf > 1)
        Ed[nd[v].bf].push_back(v);
      else {
        roots.push_back(v);
      }
      for (int s = 0; s < 26; s++) {
        int ix = nd[v].go[s];
        if (ix == -1) continue;
        Q.push(ix);
        if (nd[v].bf == -1)
          nd[ix].bf = -1;
        else
          nd[ix].bf = nd[nd[v].bf].go[s];
      }
    }
    int ans = 0;
    for (int rs : roots) ans += getAns(rs, 1);
    printf("%d\n", ans);
    for (int i = 1; i <= allN; i++) {
      vector<int> tp;
      Ed[i].swap(tp);
    }
    for (int i = 1; i <= allN; i++) {
      for (int j = 0; j < 2; j++) Vis[i][j] = 0;
      for (int j = 0; j < 26; j++) nd[i].go[j] = -1;
      nd[i].bf = -1;
    }
  }
  return 0;
}
