#include <bits/stdc++.h>
struct Node {
  int to[26];
  int fa, grand_fa;
  char ch;
} nodes[2000005];
int top;
int go(int root, char ch) {
  int &ans = nodes[root].to[ch - 'a'];
  if (ans == 0) {
    top += 1;
    memset(nodes + top, 0, sizeof(Node));
    nodes[top].fa = root;
    nodes[top].grand_fa = nodes[root].fa;
    nodes[top].ch = ch - 'a';
    ans = top;
  }
  return ans;
}
int bfs_order[2000005];
int bfs_order_top;
char str[2000005];
int f[2][2000005];
void work() {
  top = 0;
  memset(nodes, 0, sizeof(Node));
  {
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
      scanf("%s", str + 1);
      int root = 0;
      for (char *ch = str + 1; *ch; ch++) root = go(root, *ch);
    }
  }
  bfs_order[bfs_order_top = 0] = 0;
  for (int i = 0; i <= bfs_order_top; i++) {
    int k = bfs_order[i];
    for (int j = 0; j < 26; j++)
      if (nodes[k].to[j] != 0) {
        bfs_order_top += 1;
        bfs_order[bfs_order_top] = nodes[k].to[j];
      }
  }
  for (int i = 1; i <= bfs_order_top; i++) {
    int k = bfs_order[i];
    int original_father = nodes[k].fa;
    int original_grandfather = nodes[k].grand_fa;
    char ch = nodes[k].ch;
    int new_father;
    if (original_father == 0) {
      new_father = 0;
    } else if (original_grandfather == 0) {
      new_father = nodes[0].to[ch];
    } else {
      new_father = nodes[original_father].fa;
      if (new_father != 0) {
        new_father = nodes[new_father].to[ch];
      }
    }
    nodes[k].fa = new_father;
  }
  for (int i = 0; i <= bfs_order_top; i++) {
    f[0][i] = 0;
    f[1][i] = 1;
  }
  for (int i = bfs_order_top; i >= 1; i--) {
    int k = bfs_order[i];
    int fa = nodes[k].fa;
    f[0][fa] += std::max(f[1][k], f[0][k]);
    f[1][fa] += f[0][k];
  }
  printf("%d\n", f[0][0]);
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) work();
  return 0;
}
