#include <bits/stdc++.h>
using namespace std;
#define TR(i,v)         for(__typeof((v).begin())i=(v).begin();i!=(v).end();++i)
#define DEBUG(x)        cout << #x << " = " << x << endl;
#define SIZE(p)         (int)(p).size()
#define MP(a, b)        make_pair((a), (b))
#define ALL(p)          (p).begin(), (p).end()
#define rep(i, n)       for(int (i)=0; (i)<(int)(n); ++(i))
#define REP(i, a, n)    for(int (i)=(a); (i)<(int)(n); ++(i))
#define FOR(i, a, b)    for(int (i)=(int)(a); (i)<=(int)(b); ++(i))
#define FORD(i, b, a)   for(int (i)=(int)(b); (i)>=(int)(a); --(i))
#define CLR(x, y)       memset((x), (y), sizeof((x)))
typedef long long LL;
typedef pair<int, int> pii;
inline int idx(char c) {
	return c-'A';
}
typedef double NUM;
const double eps = 1e-10;
const double PI = acos(-1);
const double TWO_PI = 2*PI;
inline int dcmp(NUM x)   {
    return abs(x)<eps ? 0 : x<0 ? -1 : 1;
}
inline double zero(double x) {
    return dcmp(x)==0 ? 0 : x;
}
struct Point {
    NUM x, y;
    Point(NUM xx=0, NUM yy=0):    x(xx), y(yy)    {}
    void read() {cin>>x>>y;}
    void print() {cout<<fixed<<setprecision(12)<<x<<" "<<y<<endl;}
};
typedef Point Vector;
typedef vector<Point> Polygon;
Vector operator+(Vector A, Vector B)        {return Vector(A.x+B.x, A.y+B.y);}
Vector operator-(Point A, Point B)          {return Vector(A.x-B.x, A.y-B.y);}
Vector operator*(Vector A, NUM p)           {return Vector(A.x*p, A.y*p);}
Vector operator/(Vector A, NUM p)           {return Vector(A.x/p, A.y/p);}
bool operator<(const Point &a, const Point &b) {
    return dcmp(a.x-b.x)<0 || (dcmp(a.x-b.x)==0 && dcmp(a.y-b.y)<0);
}
bool operator == (const Point a, const Point b) {
    return dcmp(a.x-b.x)==0 && dcmp(a.y-b.y)==0;
}
NUM Cross(Vector A, Vector B)               {return A.x*B.y - A.y*B.x;}                  
bool segmentProperIntersection(Point a1, Point a2, Point b1, Point b2) {		
    NUM c1=Cross(a2-a1, b1-a1), c2=Cross(a2-a1, b2-a1);
    NUM c3=Cross(b2-b1, a1-b1), c4=Cross(b2-b1, a2-b1);
    return dcmp(c1)*dcmp(c2) <= 0 && dcmp(c3)*dcmp(c4) <= 0;
}
double getit(Point P, Vector v, Point Q, Vector w) {
    Vector u=P-Q;
    double t=Cross(w,u)/Cross(v,w);
    assert(dcmp(t)>0);
    return t;
}
bool tpcmp(const pair<double,int> &a, const pair<double,int> &b) {	
	return dcmp(a.first-b.first)<0;
}
const char MAP[][10] = {
	"",
	" TUVWXYZ",
	" MNOPQRS",
	" FGHIJKL",
	"  ABCDE "
};
Point letterP[26];
string G[26][26];
string gao(int sti,int edi) {
	Point st=letterP[sti], ed=letterP[edi];
	static int use[26];	CLR(use,0);
	vector<pair<double,int> > tp;		
	rep(k,26) if(k!=sti && k!=edi) {		
		Point c=letterP[k];		
		vector<Point> p;
		p.push_back(Point(c.x-0.5+eps,c.y+0.5-eps));
		p.push_back(Point(c.x+0.5-eps,c.y+0.5-eps));
		p.push_back(Point(c.x+0.5-eps,c.y-0.5+eps));
		p.push_back(Point(c.x-0.5+eps,c.y-0.5+eps));
		p.push_back(Point(c.x-0.5+eps,c.y+0.5-eps));
		rep(i,4) {
			if(segmentProperIntersection(st,ed,p[i],p[i+1])) {	
				tp.push_back(MP(getit(st,ed-st,p[i],p[i+1]-p[i]), k));
			}
		}				
	}		
	sort(ALL(tp),tpcmp);
	string res;
	rep(i,SIZE(tp)) if(!use[tp[i].second])
		res+=(char)('A'+tp[i].second), use[tp[i].second]=1;
	return res;
}
void preWork() {
	FOR(y,1,4)
	FOR(x,1,7) if(isupper(MAP[y][x]))
		letterP[idx(MAP[y][x])]=Point(x,y);		
	rep(i,26)
	rep(j,26) {
		G[i][j]=gao(i,j);
	}
}
int main(int argc, char const *argv[]) {
#ifndef ONLINE_JUDGE
    freopen("B.in", "r", stdin);
    freopen("B.out", "w", stdout);
#endif
    // ios::sync_with_stdio(false);		cin.tie(0);
    preWork();    
    int T;	scanf("%d",&T);
    FOR(cs,1,T) {
    	int n;	char W[110];	scanf("%d%s",&n,W);    	
    	string w="#";	
    	int len=strlen(W);
    	rep(i,len-1) {
    		w+=W[i],w+=G[idx(W[i])][idx(W[i+1])];    		
    	}	w+=W[len-1];    	
    	char t[110];
    	string res;
    	rep(ss,n) {
    		scanf("%s",t+1);
    		if(!res.empty())	continue;
    		static int dp[110*27][110];
    		int n1=SIZE(w)-1, n2=strlen(t+1);    		
    		FOR(i,1,n1)
    		FOR(j,1,n2) {
    			if(w[i]==t[j])
    				dp[i][j]=max(dp[i-1][j-1]+1,max(dp[i][j-1],dp[i-1][j]));
    			else
    				dp[i][j]=max(dp[i][j-1],dp[i-1][j]);
    		}    		
    		if(dp[n1][n2]==n2)
    			res=t+1;
    	}
    	puts(res.empty()?"NO SOLUTION":res.c_str());
    }
    return 0;
}