#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 2e9;
vector<string> v;
int n, m;
int diff(string a, string b) {
  int i, cc = 0;
  for (i = 0; i < m; ++i) cc += (a[i] != b[i]);
  return cc;
}
string solve() {
  string s = v[0], t;
  int i, j, cc;
  char c;
  bool f;
  for (i = 0; i < m; ++i) {
    t = s;
    for (c = 'a'; c <= 'z'; ++c) {
      t[i] = c;
      cc = 0;
      f = 1;
      for (j = 0; j < n; ++j) {
        cc = diff(t, v[j]);
        if (cc > 1) f = 0;
      }
      if (f) return t;
    }
  }
  return "-1";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int tc, ti = 1;
  cin >> tc;
  while (tc--) {
    int i, j;
    cin >> n >> m;
    v.resize(n);
    for (i = 0; i < n; ++i) cin >> v[i];
    cout << solve() << "\n";
  }
  return 0;
}
