#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cstdlib>
#include <iomanip>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  long long t;
  cin >> t;
  while (t--) {
    long long n, m;
    cin >> n >> m;
    vector<string> arr1(n), arr2(n - 1);
    for (int i = 0; i < n; i++) cin >> arr1[i];
    for (int i = 0; i < n - 1; i++) cin >> arr2[i];
    string res = "";
    vector<bool> odw(n);
    for (int i = 0; i < m && res == ""; i++) {
      map<char, int> tmp, counter;
      for (int j = 0; j < n - 1; j++) tmp[arr2[j][i]]++;
      for (int j = 0; j < n; j++) counter[arr1[j][i]]++;
      for (int j = 0; j < n; j++) {
          if (tmp[arr1[j][i]] == counter[arr1[j][i]]) odw[j] = true;
          else if (tmp[arr1[j][i]] == 0) {
            res = arr1[j];
            break;
          }
      }
    }
    for (int i = 0; i < n && res == ""; i++) {
      if (!odw[i]) res = arr1[i];
    }
    cout << res << "\n" << flush;
  }


  return 0;
}
