
#include<bits/stdc++.h>

#define all(A) A.begin(),A.end()
#define mset(A,X) memset(A,X,sizeof A)
#define bb(V,X) binary_search(V.begin(),V.end(),X);
#define upperb(V,X) (int)(upper_bound(V.begin(),V.end(),(X))-V.begin())
#define lowerb(V,X) (int)(lower_bound(V.begin(),V.end(),(X))-V.begin())
#define MAX(X,Y) ((X)>(Y)?(X):(Y)) //Nao usar pra chamada de funcao
#define MIN(X,Y) ((X)<(Y)?(X):(Y))

#define vi vector<int>
#define pii pair<int,int>
#define vii vector< pair<int,int> >
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fi first
#define se second

#define endl '\n'
#define ok cerr<<"OK"<<endl
#define inf 0x3f3f3f3f
#define llinf 0x3f3f3f3f3f3f3f3f
using namespace std;

int t,n,m;
int freq[100005][26];
string v[100005];

bool check(string &str) {
	for(int i=0; i<m; i++) {
		if(freq[i][str[i]-'a'] == 0) return false;
	}
	return true;
}

int32_t main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin>>t;
	while(t--) {
		string str;
		cin>>n>>m;
		for(int i=0; i<n; i++) {
			cin>>v[i];
			for(int j=0; j<m; j++) 
				freq[j][v[i][j]-'a']++; 
		}

		for(int i=1; i<n; i++) {
			cin>>str;
			for(int j=0; j<m; j++) 
				freq[j][str[j]-'a']--; 
		}

		for(string &i : v) {
			if(check(i)) {
				for(int j=0; j<m; j++) freq[j][i[j]-'a']--;
				cout<<i<<endl<<flush;
				break;
			}
		}
	}


	return 0;
}