#include <bits/stdc++.h>
using namespace std;
bool check(string &a, vector<string> &v) {
  for (string s : v) {
    int cont = 0;
    for (int i = 0; i < s.size(); i++) {
      if (a[i] != s[i]) cont++;
    }
    if (cont >= 2) return false;
  }
  return true;
}
void solve() {
  int n, m;
  cin >> n >> m;
  vector<string> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < m; i++) {
    string aux = a[0];
    for (char c = 'a'; c <= 'z'; c++) {
      aux[i] = c;
      if (check(aux, a)) {
        cout << aux << '\n';
        return;
      }
    }
  }
  cout << -1 << '\n';
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
