#include<bits/stdc++.h>
using namespace std;
//* ATCODER
#include<atcoder/all>
using namespace atcoder;
typedef modint998244353 mint;
//*/
/* BOOST MULTIPRECISION
#include<boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
//*/
typedef long long ll;
#define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--)
template <typename T> bool chmin(T &a, const T &b) {
if (a <= b) return false;
a = b;
return true;
}
template <typename T> bool chmax(T &a, const T &b) {
if (a >= b) return false;
a = b;
return true;
}
template <typename T> T max(vector<T> &a){
assert(!a.empty());
T ret = a[0];
for (int i=0; i<(int)a.size(); i++) chmax(ret, a[i]);
return ret;
}
template <typename T> T min(vector<T> &a){
assert(!a.empty());
T ret = a[0];
for (int i=0; i<(int)a.size(); i++) chmin(ret, a[i]);
return ret;
}
template <typename T> T sum(vector<T> &a){
T ret = 0;
for (int i=0; i<(int)a.size(); i++) ret += a[i];
return ret;
}
void jikken(int n, bool show){
vector<map<int,int>> mp(n);
rep(i,0,n){
rep(j,0,n){
mp[i * j / n][i * j % n]++;
}
}
set<vector<int>> st;
rep(i,1,n){
vector<int> a;
for (auto [x, c]: mp[i]){
a.push_back(c);
}
sort(a.begin(), a.end());
st.insert(a);
}
cout << n << ' ' << (int)st.size() << '\n';
if (n-1 != (int)st.size()) cout << "WARNING " << n << endl;
if (show){
rep(i,0,n){
cout << n << " ABOUT " << i << endl;
for (auto [x, c]: mp[i]){
cout << x << " * " << c << endl;
}
cout << endl;
}
}
}
string solve(int n, vector<string> s){
string shudai = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
assert(shudai.size() == 52);
map<char,int> fuku;
rep(i,0,52){
fuku[shudai[i]] = i;
}
map<char,int> len_1;
rep(i,0,n * n){
if ((int)s[i].size() == 1){
len_1[s[i][0]]++;
}
}
map<char,int> taio;
vector<char> modoso(n, '$');
for (auto [i,x]: len_1){
if (x == 2 * n - 1){
taio[i] = 0;
modoso[0] = i;
}
if (x == 1){
taio[i] = 1;
modoso[1] = i;
}
}
vector<map<int,int>> mp_orig(n);
rep(i,0,n){
rep(j,0,n){
mp_orig[i * j / n][i * j % n]++;
}
}
vector<map<char,int>> mp_chiper(n);
rep(i,0,n*n){
if ((int)s[i].size() == 2){
mp_chiper[fuku[s[i][0]]][s[i][1]]++;
}
}
map<vector<int>,int> gogo;
set<vector<int>> kinshi;
rep(i,1,n){
vector<int> tmp;
for(auto [j,d]: mp_orig[i]){
tmp.push_back(d);
}
sort(tmp.begin(), tmp.end());
if (gogo.find(tmp) != gogo.end()){
kinshi.insert(tmp);
}else{
gogo[tmp] = i;
}
}
vector<char> blacklist;
rep(i,0,n){
char x = shudai[i];
if (taio.find(x) != taio.end()) continue;
vector<int> tmp;
for (auto [j,d]: mp_chiper[fuku[x]]){
tmp.push_back(d);
}
sort(tmp.begin(), tmp.end());
if (kinshi.find(tmp) != kinshi.end()){
blacklist.push_back(x);
}else{
taio[x] = gogo[tmp];
modoso[gogo[tmp]] = x;
}
}
if ((int)blacklist.size() > 0){
vector<int> no_place;
rep(i,0,n){
if (modoso[i] == '$') no_place.push_back(i);
}
vector<int> moto;
rep(i,0,n){
rep(j,0,n){
moto.push_back(i * j);
}
}
sort(moto.begin(), moto.end());
int k = blacklist.size();
vector<int> p(k);
iota(p.begin(), p.end(), 0);
do{
rep(i,0,k){
taio[blacklist[i]] = no_place[p[i]];
modoso[no_place[p[i]]] = blacklist[i];
}
vector<int> tar;
rep(i,0,n*n){
if (s[i].size() == 1){
tar.push_back(taio[s[i][0]]);
}else{
tar.push_back(taio[s[i][0]] * n + taio[s[i][1]]);
}
}
sort(tar.begin(), tar.end());
if (tar == moto){
break;
}
rep(i,0,k){
taio.erase(blacklist[i]);
modoso[no_place[p[i]]] = '$';
}
}while(next_permutation(p.begin(), p.end()));
}
string ans;
rep(i,0,n){
ans += modoso[i];
}
return ans;
}
void assertion(){
random_device seed_gen;
mt19937 engine(seed_gen());
uniform_int_distribution<int> dist(2, 52);
string shudai = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
rep(num,0,10000){
int n = dist(engine);
string s2 = shudai.substr(0, n);
shuffle(s2.begin(), s2.end(), engine);
vector<string> s;
rep(i,0,n){
rep(j,0,n){
if (i*j/n == 0){
string x = "";
x += s2[i*j%n];
s.push_back(x);
}else{
string x = "";
x += s2[i*j/n];
x += s2[i*j%n];
s.push_back(x);
}
}
}
shuffle(s.begin(), s.end(), engine);
string ans = solve(n, s);
if (ans != s2){
cout << "ASSERTION FAILED. " << num << endl;
cout << n << endl;
}
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t; cin >> t;
while(t--){
int n; cin >> n;
vector<string> s(n * n);
rep(i,0,n * n){
cin >> s[i];
}
cout << solve(n, s) << '\n';
}
}