/*
██████╗ ██████╗ ███████╗████████╗████████╗██╗   ██╗
██╔══██╗██╔══██╗██╔════╝╚══██╔══╝╚══██╔══╝╚██╗ ██╔╝
██████╔╝██████╔╝█████╗     ██║      ██║    ╚████╔╝ 
██╔═══╝ ██╔══██╗██╔══╝     ██║      ██║     ╚██╔╝  
██║     ██║  ██║███████╗   ██║      ██║      ██║   
╚═╝     ╚═╝  ╚═╝╚══════╝   ╚═╝      ╚═╝      ╚═╝   
                                                   
███████╗ █████╗ ██╗   ██╗ █████╗  ██████╗ ███████╗ 
██╔════╝██╔══██╗██║   ██║██╔══██╗██╔════╝ ██╔════╝ 
███████╗███████║██║   ██║███████║██║  ███╗█████╗   
╚════██║██╔══██║╚██╗ ██╔╝██╔══██║██║   ██║██╔══╝   
███████║██║  ██║ ╚████╔╝ ██║  ██║╚██████╔╝███████╗ 
╚══════╝╚═╝  ╚═╝  ╚═══╝  ╚═╝  ╚═╝ ╚═════╝ ╚══════╝ 
                                                   
https://www.youtube.com/watch?v=gU2HqP4NxUs
*/
#include <bits/stdc++.h>

using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
#define ll                long long
#define pb                push_back
#define mp                make_pair
#define sz(a)             int((a).size())
#define all(c)            (c).begin(),(c).end()
#define EPS               1.0e-8
#define dot(a,b)          ((conj(a)*(b)).real())
#define cross(a,b)        ((conj(a)*(b)).imag())
#define vec(a,b)          ((b)-(a))
#define P(x)              cout<<#x<<" = { "<<x<<" }\n"
ll fastpow(ll base, ll power, ll M){
    if (power == 1) return base;
    ll val = fastpow(base, power / 2, M);
    return (power % 2 == 0) ? (val * val) % M : (((val * val) % M) * base) % M;
}
inline void debugMode() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}
const int N = 1e5+1;
const int MOD = 1e9+7;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};
int main(){
    debugMode();
    int t;cin>>t;
    while(t--){
        int n,m;cin>>n>>m;
        string s[n];
        map<int,int> mm[m];
        for(int i=0;i<n;i++){
            cin>>s[i];
            for(int j=0;j<m;j++)
                mm[j][s[i][j] - 'a']++;
        }
        for(int i=0;i<n-1;i++){
            string ss;cin>>ss;
            for(int j=0;j<m;j++)
                mm[j][ss[j] - 'a']--;
        }
        string ans = "";
        for(int i=0;i<m;i++){
            for(auto it = mm[i].begin();it!=mm[i].end();it++)
                ans += string(it->second,char(it->first + 'a'));
        }
        for(int i=0;i<n;i++){
            string x = s[i];
            if(ans == x){
                cout<<s[i]<<endl;
                break;
            }
        }
    }
    return 0;
}