#include <bits/stdc++.h>
using namespace std;
bool check(string s, vector<string> g) {
  long long n = g.size(), m = s.size();
  map<string, long long> make_pair;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      if (s[j] != g[i][j]) {
        make_pair[g[i]]++;
        if (make_pair[g[i]] > 1) return false;
      }
    }
  }
  return true;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    long long n, m;
    cin >> n >> m;
    vector<string> g;
    set<string> s;
    string tt, st, ans;
    bool done = 0;
    for (long long i = 0; i < n; i++) {
      cin >> tt;
      s.insert(tt);
    }
    for (auto tt : s) {
      g.push_back(tt);
    }
    n = g.size();
    for (long long i = 0; i < m && !done; i++) {
      for (long long c = 'a'; c <= 'z'; c++) {
        string temp = g[0];
        temp[i] = c;
        if (check(temp, g)) {
          ans = temp;
          done = 1;
          break;
        }
      }
    }
    if (!done)
      cout << -1 << endl;
    else
      cout << ans << endl;
  }
}
