#include <bits/stdc++.h>
using namespace std;
void __print(unsigned x) { cerr << x; }
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
void __print(char x) { cerr << '\'' << x << '\''; }
template <typename T, typename V>
void __print(const pair<T, V> &x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename T>
void __print(const T &x) {
  int f = 0;
  cerr << '{';
  for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v)) cerr << ", ";
  _print(v...);
}
int DP[12][1500], pr[12][1500][2];
vector<string> v;
int n, m;
int dfs(int pos, int mask) {
  if (pos == m) {
    return 1;
  }
  int &ret = DP[pos][mask];
  if (~ret) return ret;
  ret = 0;
  for (int i = 0; i < 26; i += 1) {
    int yes = 1, msk = 0;
    char x = i + 'a';
    for (int j = 0; j < n; j += 1) {
      if ((v[j][pos] != x) && (mask & (1 << j))) {
        yes = 0;
        break;
      }
      if (v[j][pos] != x) msk |= (1 << j);
    }
    if (yes) {
      int p = dfs(pos + 1, mask | msk);
      ret |= p;
      if (p) {
        pr[pos][mask][0] = i;
        pr[pos][mask][1] = msk;
        return 1;
      }
    }
  }
  return ret;
}
void print() {
  string s;
  int pos = 0, mask = 0;
  while (pos < m) {
    s += (pr[pos][mask][0] + 'a');
    mask |= pr[pos][mask][1];
    pos += 1;
  }
  cout << s << '\n';
}
void solve() {
  cin >> n >> m;
  v.clear();
  v.resize(n);
  for (int i = 0; i < n; i += 1) cin >> v[i];
  memset(DP, -1, sizeof DP);
  int ans = dfs(0, 0);
  ;
  if (ans == 0)
    cout << "-1\n";
  else {
    print();
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int tc;
  cin >> tc;
  while (tc--) solve();
  return 0;
}
