#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2000005;
int trie[MAXN][27];
int similar[MAXN];
int len[MAXN];
int n;
string words[MAXN];
int sz = 1;
void insert(string s) {
  int cur = 0;
  for (int i = 0; i < s.size(); i++) {
    if (trie[cur][s[i] - 'a'] == -1) {
      trie[cur][s[i] - 'a'] = sz++;
    }
    cur = trie[cur][s[i] - 'a'];
    len[cur] = i + 1;
  }
}
void getSimilar(string s) {
  int cur = 0;
  int cur2 = trie[0][s[0] - 'a'];
  for (int i = 1; i < s.size(); i++) {
    if (cur != -1) cur = trie[cur][s[i] - 'a'];
    cur2 = trie[cur2][s[i] - 'a'];
    similar[cur2] = cur;
  }
}
int ord[MAXN];
bool bad[MAXN];
bool cmp(const int& a, const int& b) { return len[a] < len[b]; }
int solve() {
  sz = 1;
  for (int i = 0; i < n; i++) insert(words[i]);
  for (int i = 0; i < n; i++) getSimilar(words[i]);
  for (int i = 0; i < sz; i++) ord[i] = i;
  sort(ord, ord + sz, cmp);
  int cnt = 0;
  for (int i = sz - 1; i > 0; i--) {
    int x = ord[i];
    if (bad[x]) continue;
    cnt++;
    if (similar[x] != -1) bad[similar[x]] = true;
  }
  for (int i = 0; i < sz; i++) {
    for (int j = 0; j < 26; j++) trie[i][j] = -1;
    len[i] = 0;
    bad[i] = false;
    similar[i] = -1;
  }
  return cnt;
}
char s[MAXN];
int main() {
  memset(trie, -1, sizeof(trie));
  memset(similar, -1, sizeof(similar));
  int T;
  scanf("%d", &T);
  while (T--) {
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
      scanf("%s", s);
      words[i] = string(s);
    }
    printf("%d\n", solve());
  }
}
