#include <bits/stdc++.h>
using namespace std;
int cansel_sync = (ios::sync_with_stdio(0), cin.tie(0), 0);
const int N = 110;
int T, n, m;
string s[N];
string ans;
bool ok() {
  for (int i = (0), _ = (n); i < _; i++) {
    int cnt = 0;
    for (int j = (0), _ = (m); j < _; j++) cnt += (ans[j] != s[i][j]);
    if (cnt > 1) return 0;
  }
  return 1;
}
void solve() {
  cin >> n >> m;
  for (int i = (0), _ = (n); i < _; i++) cin >> s[i];
  ans = s[0];
  for (int i = (0), _ = (n); i < _; i++)
    for (int j = (0), _ = (m); j < _; j++) {
      int t = ans[j];
      ans[j] = s[i][j];
      if (ok()) {
        cout << ans << endl;
        return;
      }
      ans[j] = t;
    }
  cout << -1 << endl;
}
signed main() {
  cin >> T;
  while (T--) {
    solve();
  }
  return 0;
}
