#include <iostream>
#include <string.h>
#include <stdio.h>
using namespace std;
#define MAX 28
struct node{
    int flag;//标记是否为节点
    int num;;//表示一个字典树到此有多少相同前缀的数目
    struct node *next[MAX];
};
void Insert(node *root,char *str){
    if(root==NULL&&*str==‘\0‘)
        return ;
    node *p=root;
    int last;//记录上一次经过的节点的num
    while(*str!=‘\0‘){
        if(p->next[*str-‘a‘]==NULL){
            node *temp=new node;
            for(int i=0;i<MAX;i++)
                temp->next[i]=NULL;
            temp->flag=0;
            temp->num=0;
            p->next[*str-‘a‘]=temp;
        }
        p=p->next[*str-‘a‘];
        p->num+=1;
        str++;
    }
    p->flag=1;
}
void Delete(node *root){
    for(int i=0;i<MAX;i++)
        if(root->next[i]!=NULL)
            Delete(root->next[i]);
    delete (root);
}
int Query(node *root,int cnt){
    int sum=0;
    if(root->num==1)
        return cnt;
    for(int i=0;i<MAX;i++)
        if(root->next[i]!=NULL)
            sum+=Query(root->next[i],cnt+1);
    return sum;
}
int main(){
    char str[1000005];
    int T,n;
    cin>>T;
    while(T--){
        node *root=new node;
        for(int i=0;i<MAX;i++)
            root->next[i]=NULL;
        root->flag=0;
        cin>>n;
        for(int i=0;i<n;i++){
            cin>>str;
            Insert(root,str);
        }
        cout<<Query(root,0)<<endl;
        Delete(root);
    }
    return 0;
}