using System.Collections.Generic;
public static void Main()
int t = int.Parse(Console.ReadLine());
for(int i = 0; i < t; i++) {
int n = int.Parse(Console.ReadLine());
string[] values = new string[n];
for(int j = 0; j < n; j++) {
values[j] = Console.ReadLine();
Dictionary<string, int> ds = new Dictionary<string, int>();
for(int x = 0; x < values[0].Length; x++) {
for(int y = 1; y <= (values[0].Length - x); y++) {
string sstr = values[0].Substring(x, y);
if(!ds.ContainsKey(sstr)) {
List<string> dictkeys = new List<string>(ds.Keys);
foreach(var item in dictkeys) {
for(int x = 1; x < values.Length; x++) {
if(values[x].Contains(item)) {
var items = ds.OrderByDescending(x => x.Value).ThenByDescending(x => x.Key.Length).ToDictionary(x => x.Key, x => x.Value);
int result1 = items.First().Value;
string prefix = items.First().Key;
int prelen = prefix.Length;
for(int x = 1; x < values.Length; x++) {
if(values[x].Substring(0, prelen) == prefix)
Console.WriteLine(result1 + result2);