#include<bits/stdc++.h>
#define deb(x) cout<<#x<<" "<<x<<endl;
#define print(arr,n) for(int i=0;i<n;++i) { cout<<arr[i]<<" "; } cout<<endl;
#define ub(x,el) upper_bound(x.begin(),x.end(),el) - x.begin()
#define lb(x,el) lower_bound(x.begin(),x.end(),el) - x.begin();
#define bs(x,el) binary_search(x.begin(),x.end(),el)
#define MOD 1000000007
#define finish return 0
using namespace std;
typedef long long int ll;
ll mod(ll x) { return x%MOD; }
ll power(ll x,ll y, ll p) { ll res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res*x) % p; y = y>>1; x = (x*x) % p; } return res; }
ll mod(ll num, ll den){ return mod(mod(num) * power(den,MOD-2,MOD)); }
bool compare(string &a, string &b)
{
return a.size()<b.size();
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll t;
cin>>t;
ll co = 1;
while(t--)
{
ll n;
cin>>n;
vector<string> arr(n);
for(ll i=0;i<n;++i) cin>>arr[i];
vector< vector<string> > A(2, vector<string>(n));
for(ll i=0;i<n;++i)
{
ll left = 0;
while(left < arr[i].size())
{
if(arr[i][left] == '*') break;
A[0][i] += arr[i][left];
++left;
}
ll right = arr[i].size()-1;
while(right >= 0)
{
if(arr[i][right] == '*') break;
A[1][i] += arr[i][right];
--right;
}
reverse(A[1][i].begin(),A[1][i].end());
}
string head,tail;
string ans = "*";
sort(A[0].begin(),A[0].end(),compare);
string ref = A[0][n-1];
bool ok = true;
for(ll i=0;i<n-1;++i)
{
string &temp = A[0][i];
string temp2 = ref.substr(0,temp.size());
if(temp != temp2)
{
ok = false;
break;
}
}
cout<<"Case #"<<co<<": ";
++co;
if(ok)
{
head = ref;
sort(A[1].begin(),A[1].end(),compare);
ref = A[1][n-1];
for(ll i=0;i<n-1;++i)
{
string &temp = A[1][i];
string temp2 = ref.substr(ref.size()-temp.size());
if(temp != temp2)
{
ok = false;
break;
}
}
tail = ref;
}
if(ok)
{
ans = head;
for(ll i=0;i<n;++i)
{
ll left = 0;
while(left < arr[i].size())
{
if(arr[i][left] == '*') break;
++left;
}
ll right = arr[i].size()-1;
while(right >= 0)
{
if(arr[i][right] == '*') break;
--right;
}
for(ll j=left+1;j<=right-1;++j) if(arr[i][j] != '*') ans+=arr[i][j];
}
ans+=tail;
}
cout<<ans<<endl;
}
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KI2RlZmluZSBkZWIoeCkgY291dDw8I3g8PCIgIjw8eDw8ZW5kbDsKI2RlZmluZSBwcmludChhcnIsbikgZm9yKGludCBpPTA7aTxuOysraSkgeyBjb3V0PDxhcnJbaV08PCIgIjsgfSBjb3V0PDxlbmRsOwojZGVmaW5lIHViKHgsZWwpIHVwcGVyX2JvdW5kKHguYmVnaW4oKSx4LmVuZCgpLGVsKSAtIHguYmVnaW4oKQojZGVmaW5lIGxiKHgsZWwpIGxvd2VyX2JvdW5kKHguYmVnaW4oKSx4LmVuZCgpLGVsKSAtIHguYmVnaW4oKTsKI2RlZmluZSBicyh4LGVsKSBiaW5hcnlfc2VhcmNoKHguYmVnaW4oKSx4LmVuZCgpLGVsKQojZGVmaW5lIE1PRCAxMDAwMDAwMDA3CiNkZWZpbmUgZmluaXNoIHJldHVybiAwCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CnR5cGVkZWYgbG9uZyBsb25nIGludCBsbDsKbGwgbW9kKGxsIHgpIHsgcmV0dXJuIHglTU9EOyB9CmxsIHBvd2VyKGxsIHgsbGwgeSwgbGwgcCkgeyBsbCByZXMgPSAxOyB4ID0geCAlIHA7IHdoaWxlICh5ID4gMCkgeyBpZiAoeSAmIDEpIHJlcyA9IChyZXMqeCkgJSBwOyB5ID0geT4+MTsgeCA9ICh4KngpICUgcDsgICB9IHJldHVybiByZXM7IH0gCmxsIG1vZChsbCBudW0sIGxsIGRlbil7IHJldHVybiBtb2QobW9kKG51bSkgKiBwb3dlcihkZW4sTU9ELTIsTU9EKSk7IH0KYm9vbCBjb21wYXJlKHN0cmluZyAmYSwgc3RyaW5nICZiKQp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