#include <bits/stdc++.h>
using namespace std;
vector<string> v;
int n, m;
string dfs(int p, string cur, vector<int> cnt) {
  if (p == m) return cur;
  for (int i = 0; i < 26; i++) {
    char ch = 'a' + i;
    auto next = cnt;
    int j = 0;
    for (; j < n; j++) {
      if (v[j][p] != ch) {
        if (next[j] == 1)
          break;
        else
          next[j]++;
      }
    }
    if (j == n) {
      cur.push_back(ch);
      auto res = dfs(p + 1, cur, next);
      if (res.size()) return res;
      cur.pop_back();
    }
  }
  return "";
}
void solve() {
  v.clear();
  cin >> n >> m;
  string t;
  for (int i = 0; i < n; i++) {
    cin >> t;
    v.push_back(t);
  }
  vector<int> v(n);
  auto ret = dfs(0, "", v);
  if (not ret.empty())
    cout << ret << endl;
  else
    cout << "-1" << endl;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) solve();
}
