#include <bits/stdc++.h>
using namespace std;
long long spf[100001];
bool isPrime(long long n) {
  if (n <= 1) return false;
  if (n <= 3) return true;
  if (n % 2 == 0 || n % 3 == 0) return false;
  for (long long i = 5; i * i <= n; i = i + 6)
    if (n % i == 0 || n % (i + 2) == 0) return false;
  return true;
}
long long power(long long a, long long b) {
  long long res = 1;
  while (b > 0) {
    if (b & 1) res = (res * a);
    a = (a * a);
    b >>= 1;
  }
  return res;
}
long long modpow(long long a, long long b, long long x) {
  long long res = 1;
  while (b > 0) {
    if (b & 1) res = (res * a) % x;
    a = (a * a) % x;
    b >>= 1;
  }
  return res;
}
void sieve() {
  spf[1] = 1;
  for (long long i = 2; i < 100001; i++) spf[i] = i;
  for (long long i = 4; i < 100001; i += 2) spf[i] = 2;
  for (long long i = 3; i * i < 100001; i++)
    if (spf[i] == i)
      for (long long j = i * i; j < 100001; j += i)
        if (spf[j] == j) spf[j] = i;
}
vector<long long> getFactorization(long long x) {
  vector<long long> ret;
  while (x != 1) {
    ret.push_back(spf[x]);
    x = x / spf[x];
  }
  return ret;
}
void solve() {
  long long n, m;
  cin >> n >> m;
  string s[n];
  for (int i = 0; i < n; i++) cin >> s[i];
  string ans = s[0];
  vector<long long> a(26, 0);
  for (int i = 0; i < m; i++) {
    char save = ans[i];
    for (char d = 'a'; d <= 'z'; d++) {
      ans[i] = d;
      bool flag = true;
      for (int j = 0; j < n; j++) {
        long long cnterrors = 0;
        for (int k = 0; k < m; k++) {
          if (s[j][k] != ans[k]) {
            cnterrors++;
          }
        }
        if (cnterrors > 1) {
          flag = false;
          break;
        }
      }
      if (flag == true) {
        cout << ans << "\n";
        return;
      }
    }
    ans[i] = save;
  }
  cout << -1 << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t = 1;
  cin >> t;
  while (t--) solve();
  return 0;
}
