# include<iostream>
# include<string>
# include<string.h>
# include<queue>
# include<stdio.h>
# include<math.h>
#include <algorithm>
using namespace std;
#define MAX 2005
int first[MAX],next[MAX],u[MAX],v[MAX],used[MAX],h=,ct=,in[MAX],ans[MAX];
int out[MAX],x=;
string s[MAX];
char ch;
void AddEdge(int a,int b)
{
u[h] = a;
v[h] = b;
out[a]++;
in[b]++;
next[h] = first[u[h]];
first[u[h]] = h;
h++;
} int judge(int p)
{
int count1 = ;
int count2 = ;
int vertex[];
for(int i=;i<=p;i++)
{
if(out[i]-in[i] == )
{
if(count1>=)
return -;
vertex[] = i;
count1++;
}
else if(out[i]-in[i] == - )
{
if(count2>=)
return -;
vertex[] = i;
count2++;
}
else if(out[i]-in[i] == )
{
continue;
}
else //WA原因
{
return -;
}
}
if(count1== && count2==)
{
return vertex[];
}
else if(count1== && count2==)
{
for(int i=;i<=;i++)
{
if(in[i]!= && out[i]!=)
return i;
}
}
else
return -;
}
void dfs(int k) //k是出发顶点
{
for(int i = ; i < h; i++)
{
if(u[i] == k)
{
//printf("%d %d\n------------\n",u[i],k);
if(used[i]!=)
{
used[i] = ;
dfs(v[i]);
ans[ct++] = i;
//printf("%d %d\n------------\n",ct,i);
///求出后答案是倒着的
}
}
} }
int main()
{
int m,n,i,j;
cin>>n;
while(n--)
{
cin>>m;
h = ;
x = ;
ct = ;
for(i=;i<MAX;i++)
{
first[i] = -;
next[i] = -;
used[i] = ;
in[i] = ;
out[i] = ;
} for(i=;i<=m;i++)
{
cin>>s[i];
}
sort(s+,s+m+);
for(i=;i<=m;i++)
{
int a,b;
a = s[i][] - 'a' + ;
b = s[i][ s[i].length()- ] - 'a' + ;
//printf("%d %d",a,b);
AddEdge(a,b);
}
int k,flag = ;
k = judge();
/*
printf("%d\n------------------\n",k); for(i=1;i<h;i++)
{
printf("%d %d %d\n",u[i],v[i],used[i]);
}
printf("\n------------------\n");
*/
dfs(k); if(k==-)
{
flag = ;
}
else
{
for(i=;i<h;i++)
{
if(used[i]!=)
{
flag = ;
break;
}
}
} if(flag==)
{
for(i=ct-;i>=;i--)
{
if(i!=)
cout<<s[ans[i]]<<"." ;
else
cout<<s[ans[i]];
}
cout<<endl;
}
else printf("***\n"); }
return ;
}
05-11 13:58