#include <bits/stdc++.h>
using namespace std;
const int nax = 55;
string a[nax];
bool ok(string s, string y) {
  int w = 0;
  for (int i = 0; i < s.length(); i++) {
    if (s[i] != y[i]) w++;
  }
  if (w > 1) return false;
  return true;
}
void solve() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> a[i];
  string res = a[1];
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < 26; j++) {
      res = a[1];
      res[i] = (char)'a' + j;
      bool q = true;
      for (int k = 1; k <= n; k++) {
        if (ok(a[k], res) == false) q = false;
      }
      if (q) {
        cout << res << endl;
        return;
      }
    }
  }
  cout << -1 << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
