#include <bits/stdc++.h>
using namespace std;
bool rev(long long x, long long y) { return x > y; }
void input_arr(long long a[], long long n) {
  for (long long i = 0; i < n; i += 1) cin >> a[i];
}
bool sortbysec(const pair<long long, long long> &a,
               const pair<long long, long long> &b) {
  return a.second < b.second;
}
bool sortinrev(const pair<long long, long long> &a,
               const pair<long long, long long> &b) {
  return (a.first > b.first);
}
void print_vec(vector<long long> &v) {
  for (auto i : v) cout << i << " ";
  cout << endl;
}
bool sortinrevbysec(const pair<long long, long long> &a,
                    const pair<long long, long long> &b) {
  return (a.second > b.second);
}
void print_arr(long long a[], long long n) {
  for (long long i = 0; i < n; i += 1) cout << a[i] << " ";
  cout << endl;
}
template <typename... T>
void input(T &...args) {
  ((cin >> args), ...);
}
template <typename... T>
void print(T &&...args) {
  ((cout << args << endl), ...);
}
template <typename... T>
void deb(T &&...args) {
  cerr << "~~ ";
  ((cerr << args << " "), ...);
  cerr << endl;
}
bool play(string s, vector<string> v) {
  for (long long i = 0; i < (long long)(v.size()); i += 1) {
    string t = v[i];
    long long val = 0;
    for (long long j = 0; j < (long long)(s.size()); j += 1) {
      if (t[j] != s[j]) val++;
    }
    if (val > 1) return false;
  }
  return true;
}
void stand8th() {
  long long n, m;
  input(n, m);
  vector<string> v;
  string s;
  for (long long i = 0; i < n; i += 1) {
    input(s);
    v.push_back(s);
  }
  vector<string> check;
  s = v[0];
  for (long long i = 0; i < m; i += 1) {
    string t = s;
    for (long long j = 0; j < 26; j += 1) {
      t[i] = 'a' + j;
      check.push_back(t);
    }
  }
  for (auto vbn : check) {
    if (play(vbn, v)) {
      print(vbn);
      return;
    }
  }
  print(-1);
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long tin = 1;
  input(tin);
  while (tin--) {
    stand8th();
  }
  return 0;
}
