#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
bool Max(T1 &a, T2 b) {
  return a < b ? a = b, 1 : 0;
}
template <typename T1, typename T2>
bool Min(T1 &a, T2 b) {
  return a > b ? a = b, 1 : 0;
}
template <int MOD>
struct ModInt {
  unsigned x;
  ModInt() : x(0) {}
  ModInt(signed sig) : x(sig) {}
  ModInt(signed long long sig) : x(sig % MOD) {}
  int get() const { return (int)x; }
  ModInt pow(unsigned p) {
    ModInt res = 1, a = *this;
    while (p) {
      if (p & 1) res *= a;
      a *= a;
      p >>= 1;
    }
    return res;
  }
  ModInt &operator+=(ModInt that) {
    if ((x += that.x) >= MOD) x -= MOD;
    return *this;
  }
  ModInt &operator-=(ModInt that) {
    if ((x += MOD - that.x) >= MOD) x -= MOD;
    return *this;
  }
  ModInt &operator*=(ModInt that) {
    x = (unsigned long long)x * that.x % MOD;
    return *this;
  }
  ModInt &operator/=(ModInt that) { return (*this) *= that.pow(MOD - 2); }
  ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
  ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
  ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
  ModInt operator/(ModInt that) const { return ModInt(*this) /= that; }
  bool operator<(ModInt that) const { return x < that.x; }
};
const int N = 1000000;
int f[N][26];
vector<int> g[N];
int fa[N];
void dfs(int i, int j) {
  for (int k = 0; k < (26); ++k)
    if (f[i][k] && f[j][k]) {
      fa[f[i][k]] = f[j][k];
      g[f[j][k]].push_back(f[i][k]);
      dfs(f[i][k], f[j][k]);
    }
}
pair<int, int> dfs2(int i) {
  pair<int, int> res = {0, 1};
  for (auto &e : g[i]) {
    pair<int, int> t = dfs2(e);
    res.first += t.first;
    res.second &= !t.second;
  }
  res.first += res.second;
  return res;
}
void solve() {
  int n;
  cin >> n;
  int nf = 0;
  while (n--) {
    string str;
    cin >> str;
    int cur = 0;
    for (auto &ch : str) {
      ch -= 'a';
      if (f[cur][ch] == 0) {
        f[cur][ch] = ++nf;
      }
      cur = f[cur][ch];
    }
  }
  for (int i = 1; i <= (nf); ++i) {
    g[i].clear();
    fa[i] = 0;
  }
  for (int i = 0; i < (26); ++i)
    if (f[0][i]) dfs(f[0][i], 0);
  int ans = 0;
  for (int i = 1; i <= (nf); ++i)
    if (!fa[i]) ans += dfs2(i).first;
  cout << ans << '\n';
  for (int i = 0; i < (nf); ++i)
    for (int j = 0; j < (26); ++j) f[i][j] = 0;
}
void init() {}
int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.setf(ios::fixed);
  cout.precision(20);
  init();
  int TC = 1;
  cin >> TC;
  cin.get();
  for (int TI = 1; TI <= (TC); ++TI) {
    solve();
  }
  return 0;
}
