#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, m;
  vector<string> v;
  cin >> n >> m;
  int i, j;
  string s;
  for (i = 0; i < n; i++) {
    cin >> s;
    v.push_back(s);
  }
  string a = v[0];
  for (i = 0; i < m; i++) {
    char save = a[i];
    for (char d = 'a'; d <= 'z'; d++) {
      a[i] = d;
      bool flag = true;
      for (j = 1; j < n; j++) {
        int diff = 0;
        for (int t = 0; t < m; t++) {
          if (v[j][t] != a[t]) diff++;
        }
        if (diff > 1) {
          flag = false;
          break;
        }
      }
      if (flag) {
        cout << a << endl;
        return;
      }
    }
    a[i] = save;
  }
  cout << -1 << endl;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
