#include <bits/stdc++.h>
using namespace std;
const long long INF = LLONG_MAX;
const long long NINF = LLONG_MIN;
long long mod = 1e8;
string to_binary(long long x) {
  string s;
  while (x > 0) {
    s += (x % 2 ? '1' : '0');
    x /= 2;
  }
  reverse(s.begin(), s.end());
  return s;
}
vector<bool> SieveOfEratosthenes(long long n) {
  vector<bool> prime(n + 1, true);
  for (long long p = 2; p * p <= n; p++) {
    if (prime[p] == true) {
      for (long long i = p * p; i <= n; i += p) prime[i] = false;
    }
  }
  return prime;
}
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 digitsum(long long x) {
  long long ans = 0;
  while (x) {
    ans += x % 10;
    x /= 10;
  }
  return ans;
}
long long nCr(long long n, long long r) {
  if (n == r)
    return 1;
  else if (r == 0)
    return 1;
  else
    return ((nCr(n - 1, r - 1) + nCr(n - 1, r)) % mod);
}
long long sqroot(long long number) {
  long long x = sqrt(number);
  while (x * x < number) x++;
  while (x * x > number) x--;
  return x;
}
long long cbroot(long long number) {
  long long x = cbrt(number);
  while (x * x * x < number) x++;
  while (x * x * x > number) x--;
  return x;
}
long long gcd(long long a, long long b) {
  if (a == 0) return b;
  if (b == 0) return a;
  return gcd(b % a, a);
}
long long power(long long a, long long b) {
  if (b == 0) return 1;
  if (b & 1) return (a * power(a, b - 1));
  long long temp = power(a, b / 2);
  return (temp * temp);
}
long long powermod(long long a, long long b) {
  if (b == 0) return 1;
  if (b & 1) return (a * powermod(a, b - 1)) % mod;
  long long temp = powermod(a, b / 2) % mod;
  return (temp * temp) % mod;
}
vector<long long> factor(long long x) {
  vector<long long> fact;
  for (long long i = 1; i * i <= x; i++) {
    if (x % i == 0) {
      fact.push_back(i);
      if (i * i != x) {
        fact.push_back(x / i);
      }
    }
  }
  return fact;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  long long test;
  cin >> test;
  while (test--) {
    long long n;
    cin >> n;
    long long si;
    cin >> si;
    vector<string> v(n);
    for (long long i = 0; i < n; i++) {
      string s;
      cin >> s;
      v[i] = s;
    }
    vector<string> ans;
    for (long long i = 0; i < si; i++) {
      for (long long j = 0; j < 26; j++) {
        string st = "";
        for (long long k = 0; k < i; k++) {
          st += v[0][k];
        }
        st += (char)('a' + j);
        for (long long f = i + 1; f < si; f++) {
          st += v[0][f];
        }
        ans.push_back(st);
      }
    }
    long long flag = 0;
    for (long long i = 0; i < ans.size(); i++) {
      long long j = 0;
      for (j = 0; j < n; j++) {
        long long cnt = 0;
        for (long long k = 0; k < si; k++) {
          if (ans[i][k] != v[j][k]) {
            cnt++;
          }
          if (cnt > 1) {
            break;
          }
        }
        if (cnt > 1) {
          break;
        }
      }
      if (j == n) {
        cout << ans[i] << '\n';
        flag = 1;
        break;
      }
    }
    if (flag == 0) {
      cout << -1 << '\n';
    }
  }
  cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << '\n';
  return 0;
}
