#include <bits/stdc++.h>
using namespace std;
bool isPowerOfTwo(long long x) { return x && (!(x & (x - 1))); }
long long power(long long x, unsigned long long y) {
  long long res = 1;
  while (y > 0) {
    if (y & 1) res = res * x;
    y = y >> 1;
    x = x * x;
  }
  return res;
}
const long long Nmax = 1e5 + 2;
vector<long long> adj[Nmax];
bool v[Nmax];
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long n, m;
    cin >> n >> m;
    string a[n];
    for (long long i = 0; i < n; ++i) cin >> a[i];
    bool f = false;
    for (long long i = 0; i < m; ++i) {
      if (f) break;
      for (long long j = 0; j < 26; ++j) {
        string str = "";
        char fll = 'a' + j;
        for (long long k = 0; k < m; ++k) {
          if (k == i)
            str += fll;
          else
            str += a[0][k];
        }
        bool ok = true;
        for (long long k = 1; k < n; ++k) {
          long long cnt = 0;
          for (long long r = 0; r < m; ++r) {
            if (a[k][r] != str[r]) cnt++;
          }
          if (cnt > 1) ok = false;
        }
        if (ok && !f) {
          cout << str << "\n";
          f = true;
          break;
        }
      }
    }
    if (f) continue;
    cout << "-1\n";
  }
  return 0;
}
