/**/
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <stack>
#include <queue>

typedef long long LL;
using namespace std;

int t;
int n;
string s[105];

int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);

	scanf("%d", &t);
	while(t--){
		scanf("%d", &n);
		map<string, int>mp;
		int ans = 0;
		int lenmin = 105, num = 1;
		for (int i = 1; i <= n; i++){
			cin >> s[i];
			int len = s[i].size();
			if(lenmin > len){
				lenmin = len;
				num = i;
			}
		}
		int len = s[num].size();
		for (int j = 0; j < len; j++){
			for (int k = 1; k + j <= len; k++){
				string str = s[num].substr(j, k);
				string rstr = str;
				reverse(rstr.begin(), rstr.end());
				int flag = 0;
				for (int i = 1; i <= n; i++){
					if(s[i].find(str) == string::npos && s[i].find(rstr) == string::npos){
						flag = 1;
					}
				}
				if(!flag){
					ans = max(ans, (int)str.size());
				}
			}
		}
		printf("%d\n", ans);
	}

	return 0;
}
/**/