#include<bits/stdc++.h>
using namespace std;

#define endl        '\n'
#define w(t)        int t;cin>>t;while(t--)
#define int         long long
#define fr(i,a,b)   for(int i=a;i<=b;i++)
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define pb          push_back
#define ppb         pop_back
#define mp          make_pair
#define all(x)      x.begin(),x.end()
#define ff          first
#define ss          second
#define pii         pair<int,int>
#define vi          vector<int>
#define vvi         vector<vi>
#define pqi         priority_queue<int>
#define pqd         priority_queue<int,vi,greater<int>>
#define inf         1e18
#define mod         1000000007
#define PI          3.14159265358979323846264338327950288419716939937510



int32_t main() {

    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

    w(t){

        int n,m;
        cin>>n>>m;
        vector<string> a(n),b(n-1);
        
        for(auto &i:a)
            cin>>i;
        for(auto &i:b)
            cin>>i;

        vector<vector<char>> fre1(m),fre2(m);

        rep(i,0,m){
            rep(j,0,n){
                fre1[i].pb(a[j][i]);
            }
        }

        rep(i,0,m){
            rep(j,0,n-1){
                fre2[i].pb(b[j][i]);
            }
        }

        string ans;

        rep(i,0,m){
            sort(all(fre1[i]));
            sort(all(fre2[i]));
            int j=0;

            for(;j<n-1;j++){
                if(fre1[i][j]!=fre2[i][j]){
                    ans+=fre1[i][j];
                    break;
                }
            }
            if(j==n-1)
                ans+=fre1[i][n-1];
        }

        cout<<ans<<endl;




    }
    
    return 0;
    
}