#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
const int N = 2e6 + 13, M = N;
int i, j, k, n, m;
long long gcd(long long a, long long b) {
  if (a == 0) return b;
  if (b == 0) return a;
  if (a == b) return a;
  if (a > b) return gcd(a % b, b);
  return gcd(a, b % a);
}
void print(vector<int>& A) {
  for (k = 0; k < A.size(); k++) {
    cout << A[k] << " ";
  }
  cout << endl;
}
long long C(long long n, long long r) {
  long long p = 1, k = 1;
  if (n - r < r) r = n - r;
  if (r != 0) {
    while (r) {
      p *= n;
      k *= r;
      long long m = gcd(p, k);
      p /= m;
      k /= m;
      n--;
      r--;
    }
  } else
    p = 1;
  return p;
}
bool check(string a, string b) {
  int count = 0;
  for (int i = 0; i < a.size(); i++) {
    if (a[i] != b[i]) count++;
  }
  return count < 2;
}
void solve() {
  cin >> n >> m;
  vector<string> v(n);
  for (i = 0; i < n; i++) cin >> v[i];
  string compare = v[0];
  for (i = 0; i < m; i++) {
    for (char c = 'a'; c <= 'z'; c++) {
      int f = 1;
      compare = v[0];
      compare[i] = c;
      for (string s : v) {
        if (!check(compare, s)) f = 0;
      }
      if (f) {
        cout << compare << endl;
        return;
      }
    }
  }
  cout << -1 << endl;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
