#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, n, m;
  string x[10];
  cin >> t;
  while (t--) {
    string s, ans;
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
      cin >> x[i];
    }
    s = x[0];
    bool ok = false;
    for (int i = 0; i < s.length() && !ok; i++) {
      for (char j = 'a'; j <= 'z' && !ok; j++) {
        if (j == x[0][i] && i > 0) continue;
        s[i] = j;
        int z, d;
        for (z = 1; z < n; z++) {
          d = 0;
          for (int y = 0; y < m; y++) {
            if (s[y] != x[z][y]) d++;
          }
          if (d > 1) break;
        }
        if (z == n) {
          ok = true;
          ans = s;
        }
      }
      s = x[0];
    }
    if (ok)
      cout << ans << endl;
    else
      cout << -1 << endl;
  }
  return 0;
}
