#include <bits/stdc++.h>
using namespace std;
map<int, int> c;
int main() {
  int t;
  cin >> t;
  for (int i = 0; i < t; i++) {
    long long n, m;
    cin >> n >> m;
    vector<string> v;
    string s;
    for (int j = 0; j < n; j++) {
      cin >> s;
      v.push_back(s);
    }
    string a;
    int j, k, l, cnt;
    for (j = 0; j < m; j++) {
      a.clear();
      a += v[0];
      for (int x = 0; x < 26; x++) {
        a[j] = x + 97;
        for (k = 0; k < n; k++) {
          cnt = 0;
          for (l = 0; l < m; l++) {
            if (v[k][l] != a[l]) cnt++;
            if (cnt > 1) break;
          }
          if (l != m) break;
        }
        if (k == n) break;
      }
      if (k == n) break;
    }
    if (k == n)
      cout << a << "\n";
    else
      cout << "-1"
           << "\n";
  }
  return 0;
}
