#include <bits/stdc++.h>
using namespace std;
string to_string(string s) { return '"' + s + '"'; }
string to_string(char s) { return string(1, s); }
string to_string(const char *s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A>
string to_string(A);
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool f = 1;
  string r = "{";
  for (const auto &x : v) {
    if (!f) r += ", ";
    f = 0;
    r += to_string(x);
  }
  return r + "}";
}
void debug_out() { cout << endl; }
void show() { cout << endl; }
void pret() {
  cout << endl;
  exit(0);
}
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << " " << to_string(H);
  debug_out(T...);
}
template <typename Head, typename... Tail>
void show(Head H, Tail... T) {
  cout << H << " ";
  show(T...);
}
template <typename Head, typename... Tail>
void pret(Head H, Tail... T) {
  cout << H << " ";
  pret(T...);
}
const long long MOD = 1e9 + 7;
const long long maxn = 300000 + 10;
string s[11];
long long n, m;
bool check(string &t) {
  for (long long i = 0; i < n; ++i) {
    long long curr = 0;
    for (long long j = 0; j < m; ++j) {
      curr += (s[i][j] != t[j]);
    }
    if (curr > 1) return 0;
  }
  return 1;
}
string f() {
  cin >> n >> m;
  for (long long i = 0; i < n; ++i) {
    cin >> s[i];
  }
  for (long long i = 0; i < n; ++i) {
    string temp = s[i];
    for (long long j = 0; j < m; ++j) {
      for (long long k = 0; k < 26; ++k) {
        char curr = char('a' + k);
        temp[j] = curr;
        if (check(temp)) {
          return temp;
        }
      }
      temp[j] = s[i][j];
    }
  }
  return "-1";
}
int32_t main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  ;
  long long t;
  cin >> t;
  while (t--) {
    string ans = f();
    cout << ans << '\n';
  }
  return 0;
}
