#include <bits/stdc++.h>
using namespace std;
long long bigmod(long long b, long long p, long long m) {
  if (p == 0) return 1;
  long long my = bigmod(b, p / 2, m);
  my *= my;
  my %= m;
  if (p & 1) my *= b, my %= m;
  return my;
}
long long setb(long long n, long long pos) { return n = n | (1 << pos); }
long long resb(long long n, long long pos) { return n = n & ~(1 << pos); }
bool checkb(long long n, long long pos) { return (bool)(n & (1 << pos)); }
string str;
int n;
long long base[2] = {29, 31};
long long mod[2] = {1000000007, 1000000009};
long long p[2][1000005], inv[2][1000005];
long long h[2][1000005];
void prework(int N) {
  p[0][0] = p[1][0] = 1;
  inv[0][0] = inv[1][0] = 1;
  for (int k = 0; k < 2; k++) {
    long long d = bigmod(base[k], mod[k] - 2, mod[k]);
    for (int i = 1; i <= N; i++) {
      p[k][i] = (p[k][i - 1] * base[k]) % mod[k];
      inv[k][i] = (inv[k][i - 1] * d) % mod[k];
    }
  }
}
void init() {
  for (int k = 0; k < 2; k++) {
    long long ret = 0;
    for (int i = 0; i < n; i++) {
      ret = (ret + p[k][i] * (str[i] - 'a' + 1)) % mod[k];
      h[k][i] = ret;
    }
  }
}
long long get_hash(int l, int r) {
  long long ret[2];
  for (int k = 0; k < 2; k++) {
    ret[k] = h[k][r];
    if (l) ret[k] -= h[k][l - 1];
    if (ret[k] < 0) ret[k] += mod[k];
    ret[k] = (ret[k] * inv[k][l]) % mod[k];
  }
  return ret[0] + ret[1] * 2000000000;
  return ret[0];
}
string ara[1000005];
int s[1000005];
int id[1000005][2];
int q;
map<long long, long long> mp;
int ind;
int marker[1000005];
vector<int> g[1000005];
int deg[1000005];
int visit[1000005][2], dp[1000005][2], cs;
int F(int u, int f) {
  if (visit[u][f] == cs) return dp[u][f];
  int len = g[u].size(), i;
  int ret = f;
  for (i = 0; i < len; i++) {
    int v = g[u][i];
    if (f)
      ret += F(v, 0);
    else
      ret += max(F(v, 0), F(v, 1));
  }
  visit[u][f] = cs;
  return dp[u][f] = ret;
}
void build() {
  int len = 0;
  for (int i = 1; i <= q; i++) {
    int l = id[i][0];
    int r = id[i][1];
    for (int j = l; j <= r; j++) {
      len++;
      long long my = get_hash(l, j);
      if (mp.find(my) == mp.end()) mp[my] = ++ind;
      marker[len] = mp[my];
    }
  }
  len = 0;
  for (int i = 1; i <= q; i++) {
    int l = id[i][0] + 1;
    int r = id[i][1];
    len++;
    for (int j = l; j <= r; j++) {
      len++;
      long long my = get_hash(l, j);
      if (mp.find(my) != mp.end()) {
        int v = marker[len];
        int u = mp[my];
        g[u].push_back(v);
        deg[v]++;
      }
    }
  }
}
int F() {
  cs++;
  int ret = 0;
  for (int i = 1; i <= ind; i++)
    sort(g[i].begin(), g[i].end()),
        g[i].erase(unique(g[i].begin(), g[i].end()), g[i].end());
  for (int i = 1; i <= ind; i++) {
    if (deg[i] == 0) ret += max(F(i, 0), F(i, 1));
  }
  return ret;
}
void Clear() {
  mp.clear();
  for (int i = 1; i <= ind; i++) g[i].clear(), deg[i] = 0;
  ind = 0;
}
int main() {
  long long t, T, i;
  prework(1000000);
  scanf("%lld", &T);
  for (t = 1; t <= T; t++) {
    scanf("%lld", &q);
    str = "";
    long long last = -1;
    for (i = 1; i <= q; i++) {
      cin >> ara[i];
      s[i] = ara[i].size();
      str += ara[i];
      id[i][0] = last + 1;
      id[i][1] = last + s[i];
      last = last + s[i];
    }
    n = last + 1;
    init();
    build();
    int ret = F();
    printf("%d", ret);
    printf("\n");
    Clear();
  }
  return 0;
}
