#include <bits/stdc++.h>
#pragma GCC optimize "-O3"
using namespace std;
int n, m;
vector<string> s;
string ans;
bool ndiff(string a, string b, int d) {
  bool diff = true;
  int count = 0, m = a.size();
  for (int k = 0; k < (int)m; k++) {
    if (a[k] != b[k]) count++;
    if (count > d) {
      diff = false;
      break;
    }
  }
  return diff;
}
bool allcomp(string a) {
  bool works = true;
  for (int i = 0; i < (int)n; i++) {
    if (!ndiff(a, s[i], 1)) {
      works = false;
      break;
    }
  }
  return works;
}
bool change_char(string s) {
  bool ans_exists = false;
  for (int j = 0; j < (int)m; j++) {
    string a = s;
    for (int k = 0; k < (int)26; k++) {
      a[j] = 'a' + k;
      ans_exists = allcomp(a);
      if (ans_exists) {
        ans = a;
        break;
      }
    }
    if (ans_exists) break;
  }
  return ans_exists;
}
void solve() {
  cin >> n >> m;
  s.resize(n);
  for (int i = 0; i < (int)n; i++) cin >> s[i];
  bool ans_exists = false;
  for (int i = 0; i < (int)n; i++) {
    ans_exists = change_char(s[i]);
    if (ans_exists) break;
  }
  if (ans_exists)
    cout << ans << "\n";
  else
    cout << -1 << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
