#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000010;
struct Trie {
  int next[maxn][26], fail[maxn];
  int depth[maxn];
  vector<int> sons[maxn];
  int _dp[maxn][2];
  int root, L;
  int newnode() {
    for (int i = 0; i < 26; i++) next[L][i] = -1;
    return L++;
  }
  void init() {
    L = 0;
    root = newnode();
    depth[root] = 0;
  }
  void insert(char buf[]) {
    int len = strlen(buf);
    int now = root;
    for (int i = 0; i < len; i++) {
      if (next[now][buf[i] - 'a'] == -1) next[now][buf[i] - 'a'] = newnode();
      now = next[now][buf[i] - 'a'];
      depth[now] = i + 1;
    }
  }
  void build() {
    queue<int> Q;
    fail[root] = root;
    for (int i = 0; i < 26; i++)
      if (next[root][i] == -1)
        next[root][i] = root;
      else {
        fail[next[root][i]] = root;
        Q.push(next[root][i]);
      }
    while (!Q.empty()) {
      int now = Q.front();
      Q.pop();
      for (int i = 0; i < 26; i++)
        if (next[now][i] == -1)
          next[now][i] = next[fail[now]][i];
        else {
          fail[next[now][i]] = next[fail[now]][i];
          Q.push(next[now][i]);
        }
    }
  }
  void build_edge() {
    for (int i = 0; i < L; i++) sons[i].clear();
    for (int i = 1; i < L; i++) {
      int j = fail[i];
      sons[j].push_back(i);
    }
  }
  int dp(int u) {
    _dp[u][0] = 0, _dp[u][1] = 1;
    for (int i = 0; i < sons[u].size(); i++) {
      int v = sons[u][i];
      dp(v);
      _dp[u][0] += max(_dp[v][0], _dp[v][1]);
      _dp[u][1] +=
          (depth[v] - depth[u] == 1) ? _dp[v][0] : max(_dp[v][0], _dp[v][1]);
    }
    return _dp[u][0];
  }
};
char buf[maxn];
Trie ac;
int main() {
  int T;
  int n;
  scanf("%d", &T);
  while (T--) {
    scanf("%d", &n);
    ac.init();
    for (int i = 0; i < n; i++) {
      scanf("%s", buf);
      ac.insert(buf);
    }
    ac.build();
    ac.build_edge();
    printf("%d\n", ac.dp(0));
  }
  return 0;
}
