#include <bits/stdc++.h>
using namespace std;
void yes(bool fl = true) {
  if (fl)
    cout << "YES\n";
  else
    cout << "Yes\n";
}
void no(bool fl = true) {
  if (fl)
    cout << "NO\n";
  else
    cout << "No\n";
}
long long a, b, c, d, e, f, g, n, m, k, t, x, h, w, p, q, y;
string str = "";
long long mod = 1e9 + 7;
long long pow(long long begin, long long p) {
  long long answer = 1;
  while (p != 0) {
    if (p % 2 == 0) {
      begin = (begin * begin) % mod;
      p = p / 2;
    } else {
      p--;
      answer = ((answer % mod) * (begin % mod)) % mod;
    }
  }
  return answer;
}
string check(vector<string> &v) {
  str = v[0];
  for (int j = 0; j < m; j++) {
    for (char ch = 'a'; ch <= 'z'; ch++) {
      string tmp = str;
      tmp[j] = ch;
      bool flag = true;
      for (int i = 1; i < v.size(); i++) {
        int changes = 0;
        for (int zz = 0; zz < m; zz++) {
          if (tmp[zz] != v[i][zz]) changes++;
        }
        if (changes > 1) {
          flag = false;
          break;
        }
      }
      if (flag) return tmp;
    }
  }
  return "-1";
}
void solve() {
  cin >> n >> m;
  vector<string> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  if (m == 1) {
    cout << "a\n";
    return;
  }
  cout << check(v) << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  int cases = 1;
  cin >> cases;
  while (cases--) solve();
  return 0;
}
