#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int MAXN = 1e5;
int r[MAXN]; // r 数组保存了字符串中的每个元素值,除最后一个元素外,每个元素的值在 1..m 之间,最后一个元素的值为 0
int wa[MAXN], wb[MAXN], wv[MAXN], ws[MAXN]; // 这 4 个数组是后缀数组计算时的临时变量,无实际意义
int sa[MAXN]; // sa[i] 保存第 i 小的后缀在字符串中的开始下标,i 取值范围为 0..n-1
int cmp(int *r, int a, int b, int l) {
return r[a] == r[b] && r[a + l] == r[b + l];
}
void da(int *r, int *sa, int n, int m) { // n 为字符串的长度,注意是长度,m 为字符最大值
int i, j, p, *x = wa, *y = wb;
for (i = 0; i < m; ++i) ws[i] = 0;
for (i = 0; i < n; ++i) ws[x[i] = r[i]]++;
for (i = 1; i < m; ++i) ws[i] += ws[i - 1];
for (i = n - 1; i >= 0; --i) sa[--ws[x[i]]] = i;
for (j = 1, p = 1; p < n; j *= 2, m = p) {
for (p = 0, i = n - j; i < n; ++i) y[p++] = i;
for (i = 0; i < n; ++i) if (sa[i] >= j) y[p++] = sa[i] - j;
for (i = 0; i < n; ++i) wv[i] = x[y[i]];
for (i = 0; i < m; ++i) ws[i] = 0;
for (i = 0; i < n; ++i) ws[wv[i]]++;
for (i = 1; i < m; ++i) ws[i] += ws[i - 1];
for (i = n - 1; i >= 0; --i) sa[--ws[wv[i]]] = y[i];
for (swap(x, y), p = 1, x[sa[0]] = 0, i = 1; i < n; ++i)
x[sa[i]] = cmp(y, sa[i - 1], sa[i], j) ? p - 1 : p++;
}
return;
}
int rnk[MAXN]; // rank[i] 表示从下标 i 开始的后缀的排名,值为 1..n
int height[MAXN]; // 下标范围为 1..n,height[1] = 0
void calHeight(int *r, int *sa, int n) { //n为字符串长度减一
int i, j, k = 0;
for (i = 1; i <= n; ++i)
rnk[sa[i]] = i;
for (i = 0; i < n; height[rnk[i++]] = k)
for (k ? k-- : 0, j = sa[rnk[i] - 1]; r[i + k] == r[j + k]; ++k);
return;
}
char s[MAXN];
int id[MAXN];
int vis[105];
bool check(int mid,int n,int k){
memset(vis,0,sizeof(vis));
int cnt=0;
for(int i=1;i<n;i++){
if(height[i]>=mid){
//枚举每一条字符串。
for(int j=0;j<k;j++){
if(id[sa[i]]==j){
cnt+=(vis[j]?0:1);
vis[j]=1;
}
if(id[sa[i-1]]==j){
cnt+=(vis[j]?0:1);
vis[j]=1;
}
}
}else{
if(cnt>=k) return true;
cnt=0;
memset(vis,0,sizeof(vis));
}
}
if(cnt>=k) return true;
return false;
}
int main(){
int t;
scanf("%d",&t);
while(t--){
int k,n=0;
int f=1;
scanf("%d",&k);
for(int i=0;i<k;i++){
scanf("%s",s);
int len=strlen(s);
for(int j=0;j<len;j++){
r[n]=s[j];
id[n]=i;
n++;
}
r[n++]=128+f++;
reverse(s,s+len);
for(int j=0;j<len;j++){
r[n]=s[j];
id[n]=i;
n++;
}
r[n++]=128+f++;
}
r[n-1]=0;
da(r,sa,n,128+f);
calHeight(r,sa,n-1);
int l=1,r=n-1,ans=0;
while(l<=r){
int mid=l+r>>1;
if(check(mid,n,k)){
ans=mid;
l=mid+1;
}else r=mid-1;
}
printf("%d\n",ans);
}
return 0;
}