#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long ll;
const int N = 1e6 + 5;
const int INF = 0x3f3f3f3f;
string a[N], b[N];
typedef pair<char, ll> PAIR;
bool cmp(const PAIR& l, const PAIR& r) {
	return l.second > r.second;
}
int main() {
	ios::sync_with_stdio(false);
//	freopen("out.txt","w",stdout);
	ll t;
	cin >> t;
	while (t --) {
		ll n, m;
		cin >> n >> m;
		map<ll, map<char, ll> > mp;
		for (ll i = 0; i < n; i ++) {
			string s;
			cin >> s; 
			for (ll j = 0; j < m; j ++)  mp[j][s[j]] ++;
		}
		for (ll i = 0; i < n - 1; i ++) {
			string s;
			cin >> s;
			for (ll j = 0; j < m; j ++)  mp[j][s[j]] --;
		}
		for (ll i = 0; i < m; i ++) {
			vector<PAIR> vt(mp[i].begin(), mp[i].end());
			sort(vt.begin(), vt.end(), cmp);
			cout << vt[0].first;
		}
		cout << '\n';
	}
	return 0;
}
