#include <bits/stdc++.h>
using namespace std;
long long powermodm(long long x, long long n, long long M) {
  long long result = 1;
  while (n > 0) {
    if (n % 2 == 1) result = (result * x) % M;
    x = (x * x) % M;
    n = n / 2;
  }
  return result;
}
long long power(long long _a, long long _b) {
  long long _r = 1;
  while (_b) {
    if (_b % 2 == 1) _r = (_r * _a);
    _b /= 2;
    _a = (_a * _a);
  }
  return _r;
}
int n, m;
void solve() {
  cin >> n >> m;
  vector<string> v(n);
  for (auto i = 0; i < n; i++) cin >> v[i];
  string ans = v[0];
  for (auto i = 0; i < m; i++) {
    char s = ans[i];
    for (auto j = 'a'; j <= 'z'; j++) {
      ans[i] = j;
      bool flag = true;
      for (auto k = 0; k < n; k++) {
        int cnt = 0;
        for (auto l = 0; l < m; l++) {
          if (ans[l] != v[k][l]) cnt++;
        }
        if (cnt > 1) {
          flag = false;
          break;
        }
      }
      if (flag) {
        cout << ans << endl;
        return;
      }
    }
    ans[i] = s;
  }
  cout << -1 << endl;
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) solve();
  return 0;
}
