#include <bits/stdc++.h>
using namespace std;
string s[11];
int dif(string a, string b, int l) {
  int nr = 0;
  for (int i = 0; i < l; i++) {
    if (a[i] != b[i]) nr++;
  }
  return nr > 1;
}
int main() {
  int n, m, t;
  cin >> t;
  while (t--) {
    int i, nr = 0;
    char j;
    cin >> n >> m;
    for (i = 1; i <= n; i++) {
      cin >> s[i];
    }
    for (i = 0; i < m; i++) {
      string c = s[1];
      for (j = 'a'; j <= 'z'; j++) {
        bool ok = true;
        s[1][i] = j;
        for (int k = 2; k <= n; k++)
          if (dif(s[1], s[k], m)) ok = false;
        if (ok == true) {
          nr++;
          if (nr == 1) cout << s[1] << endl;
        }
      }
      s[1] = c;
    }
    if (nr == 0) cout << -1 << endl;
  }
}
