#include <bits/stdc++.h>
using namespace std;
string s[11];
long long n, m;
string ans = "";
bool dfs(long long i, string second) {
  for (long long j = 0; j < n; j++) {
    long long cnt = 0;
    for (long long k = 0; k < i; k++) {
      if (s[j][k] != second[k]) cnt++;
    }
    if (cnt > 1) return false;
  }
  if (i == m) {
    ans = second;
    return true;
  }
  for (long long j = 0; j < n; j++) {
    if (dfs(i + 1, second + s[j][i])) return true;
  }
  return false;
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  long long t;
  cin >> t;
  while (t--) {
    cin >> n >> m;
    for (long long i = 0; i < n; i++) cin >> s[i];
    ans = "";
    if (!dfs(0, ""))
      cout << -1 << '\n';
    else
      cout << ans << '\n';
  }
}
