#include <bits/stdc++.h>
using namespace std;
vector<long long> graph[200005];
bool visited[200005];
long long mod = 1000000007;
long long dfs(long long i) {
  visited[i] = true;
  for (long long j = 0; j < graph[i].size(); j++) {
    if (!visited[graph[i][j]]) {
      dfs(graph[i][j]);
    }
  }
}
vector<string> s;
long long n, m;
bool check(string t) {
  for (long long i = 0; i < n; i++) {
    long long cnt = 0;
    for (long long j = 0; j < m; j++) {
      if (t[j] != s[i][j]) cnt++;
    }
    if (cnt > 1) return false;
  }
  return true;
}
void solve() {
  cin >> n >> m;
  s.clear();
  for (long long i = 0; i < n; i++) {
    string temp;
    cin >> temp;
    s.push_back(temp);
  }
  string ans = s[0];
  if (check(ans)) {
    cout << ans << endl;
    return;
  } else {
    bool flag = false;
    for (long long i = 0; i < m; i++) {
      string str = s[0];
      for (char c = 'a'; c <= 'z'; c++) {
        str[i] = c;
        if (check(str)) {
          cout << str << endl;
          flag = true;
        }
      }
      if (flag) break;
    }
    if (flag == false) cout << -1 << endl;
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
