#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
bool cmin(A &a, const B &b) {
  return a > b ? (a = b, true) : false;
}
template <typename A, typename B>
bool cmax(A &a, const B &b) {
  return a < b ? (a = b, true) : false;
}
const double PI = acos(-1);
const double EPS = 1e-9;
long long inf = sizeof(long long) == sizeof(long long) ? 2e18 : 1e9 + 10;
class RHash {
 public:
  long long n;
  vector<long long> base, mo;
  vector<vector<long long> > hash;
  vector<vector<long long> > po;
  RHash(string s) {
    base = {1009, 9973};
    mo = {1000000007, 1000000009};
    n = s.size();
    hash = vector<vector<long long> >(n + 1, vector<long long>(2));
    po = vector<vector<long long> >(n + 1, vector<long long>(2, 1));
    for (long long i = 0; i < n; i++)
      for (long long j = 0; j < 2; j++) {
        hash[i + 1][j] = (hash[i][j] + s[i]) * base[j] % mo[j];
        po[i + 1][j] = po[i][j] * base[j] % mo[j];
      }
  }
  pair<long long, long long> get(long long l, long long r) {
    long long t[2];
    for (long long i = 0; i < 2; i++)
      t[i] = ((hash[r][i] - hash[l][i] * po[r - l][i]) % mo[i] + mo[i]) % mo[i];
    return {t[0], t[1]};
  }
};
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long q;
  cin >> q;
  while (q--) {
    long long n;
    cin >> n;
    vector<string> in(n);
    for (long long i = 0; i < n; i++) cin >> in[i];
    sort(in.begin(), in.end(),
         [](string a, string b) { return a.size() > b.size(); });
    vector<RHash> data;
    for (long long i = 0; i < n; i++) data.push_back(RHash(in[i]));
    long long out = 0;
    set<pair<long long, long long> > mel, pre;
    for (long long i = in[0].size() - 1; i != -1; i--) {
      for (long long j = 0; j < n; j++) {
        if (in[j].size() <= i) break;
        pair<long long, long long> t1 = data[j].get(0, i + 1);
        if (pre.find(t1) == pre.end()) {
          pair<long long, long long> t2 = data[j].get(1, i + 1);
          pre.insert(t1);
          mel.insert(t2);
          out++;
        }
      }
      pre = mel;
      mel = set<pair<long long, long long> >();
    }
    cout << out << endl;
  }
}
