#include <bits/stdc++.h>
using namespace std;
template <class T>
T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <class T>
void printc(T c) {
  for (auto const& v : c) std::cout << v << ' ';
  cout << endl;
}
const long long LL_MAX_INF = std::numeric_limits<long long>::max();
const long long LL_MIN_INF = std::numeric_limits<long long>::min();
void solution();
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    solution();
  }
  return 0;
}
void solution() {
  long long n, m;
  cin >> n >> m;
  vector<string> a(n);
  for (long long i = 0; i < n; ++i) {
    cin >> a[i];
  }
  for (long long i = 0; i < m; ++i) {
    for (long long j = 0; j < 26; ++j) {
      string cur = a[0];
      cur[i] = 'a' + j;
      bool ans = true;
      for (long long k = 0; k < n; ++k) {
        long long count = 0;
        for (long long x = 0; x < m; ++x) {
          if (cur[x] != a[k][x]) count++;
        }
        if (count > 1) {
          ans = false;
          break;
        }
      }
      if (ans) {
        cout << cur << endl;
        return;
      }
    }
  }
  cout << -1 << endl;
}
