#include <bits/stdc++.h>
using namespace std;
const int MOD1 = 999989981;
const int MOD2 = 999999893;
const int INF = INT_MAX / 2;
struct edge {
  int i, v;
};
int pow_mod(long long x, long long n, int M) {
  long long ans = 1;
  for (; n; n >>= 1) {
    if (n & 1) ans = ans * x % M;
    x = x * x % M;
  }
  return ans;
}
int inv_mod(int x, int p) { return pow_mod(x, p - 2, p); }
struct rolling_hash {
  int M;
  vector<int> a, b;
  rolling_hash() {}
  rolling_hash(string s, int _M) {
    M = _M;
    int N = s.length();
    a.resize(N + 1);
    long long x = 1;
    for (int i = 0; i < N; i++) {
      a[i + 1] = (a[i] + x * s[i]) % M;
      x = x * 256 % M;
    }
    long long inv = inv_mod(256, M);
    b.resize(N + 1);
    b[0] = 1;
    for (int i = 0; i < N; i++) b[i + 1] = b[i] * inv % M;
  }
  int get(int l, int r) {
    return ((long long)(a[r] - a[l]) * b[l] % M + M) % M;
  }
};
int main() {
  int T;
  cin >> T;
  while (T--) {
    int N;
    cin >> N;
    vector<string> s(N);
    for (int i = 0; i < N; i++) cin >> s[i];
    vector<rolling_hash> a1(N), a2(N);
    for (int i = 0; i < N; i++) a1[i] = rolling_hash(s[i], MOD1);
    for (int i = 0; i < N; i++) a2[i] = rolling_hash(s[i], MOD2);
    vector<pair<int, int> > v;
    for (int i = 0; i < N; i++)
      for (int j = 1; j <= s[i].length(); j++)
        v.push_back(pair<int, int>(j, i));
    sort(v.rbegin(), v.rend());
    set<long long> ng;
    int ans = 0;
    for (pair<int, int> ji : v) {
      int i = ji.second, j = ji.first;
      long long x = (long long)a1[i].get(0, j) * MOD2 + a2[i].get(0, j);
      if (ng.count(x)) continue;
      ans++;
      ng.insert(x);
      long long y = (long long)a1[i].get(1, j) * MOD2 + a2[i].get(1, j);
      ng.insert(y);
    }
    printf("%d\n", ans);
  }
}
