#include <bits/stdc++.h>
long long fpow(long long x, long long y, long long p = 1000000007) {
  x = x % p;
  long long sum = 1;
  while (y) {
    if (y & 1) sum = sum * x;
    sum %= p;
    y = y >> 1;
    x = x * x;
    x %= p;
  }
  return sum;
}
long long fact[1000007] = {0};
void facto() {
  fact[0] = 1;
  fact[1] = 1;
  for (long long i = 2; i < 100007; i++)
    fact[i] = (fact[i - 1] * i) % 1000000007;
}
long long ncr(long long n, long long r) {
  long long res = 1;
  res = fact[n];
  res = (res * (fpow(fact[r], 1000000007 - 2))) % 1000000007;
  res = (res * (fpow(fact[n - r], 1000000007 - 2))) % 1000000007;
  return res;
}
long long npr(long long n, long long r) {
  long long res = 1;
  res = fact[n];
  res = (res * (fpow(fact[n - r], 1000000007 - 2))) % 1000000007;
  return res;
}
long long modmul(long long x, long long y) { return (x * y) % 1000000007; }
long long modadd(long long x, long long y) { return (x + y) % 1000000007; }
long long modsub(long long x, long long y) {
  return (x - y + 1000000007) % 1000000007;
}
long long xx[4] = {1, 0, -1, 0};
long long yy[4] = {0, 1, 0, -1};
using namespace std;
signed main() {
  long long t;
  cin >> t;
  while (t--) {
    long long n, m;
    cin >> n >> m;
    string s[n];
    for (long long i = 0; i < n; i++) {
      cin >> s[i];
    }
    for (long long i = 0; i < m; i++) {
      char curr = s[0][i];
      for (long long j = 0; j < 26; j++) {
        s[0][i] = j + 'a';
        long long f = 0;
        for (long long k = 1; k < n; k++) {
          long long cha = 0;
          for (long long l = 0; l < m; l++) {
            if (s[0][l] != s[k][l]) {
              cha++;
            }
          }
          if (cha > 1) {
            f = 1;
          }
        }
        if (f == 0) {
          cout << s[0] << endl;
          goto en;
        }
      }
      s[0][i] = curr;
    }
    cout << "-1" << endl;
  en:;
  }
}
