#include <bits/stdc++.h>
using namespace std;
using namespace std;
using ll = long long;
using ld = long double;
const int MOD = 1e9 + 7, inf = 1e9, N = 2e5 + 1;
const ll INF = 1e18;
ld tic, tac;
int solve(string s, string str[], int n, int m) {
  int flag = 1;
  for (int i = 0; i < (n); ++i) {
    int count = 0;
    for (int j = 0; j < m; j++) {
      if (str[i][j] != s[j]) count++;
    }
    if (count > 1) {
      flag = 0;
      break;
    }
  }
  return flag;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  cin >> t;
  while (t--) {
    ll n, m;
    cin >> n >> m;
    int arr[m];
    string str[n];
    for (int i = 0; i < (n); ++i) cin >> str[i];
    int err = 0;
    int flag = 0;
    string s = str[n - 1];
    for (int i = 0; i < m; i++) {
      s = str[n - 1];
      for (char c = 'a'; c <= 'z'; c++) {
        s[i] = c;
        if (solve(s, str, n - 1, m)) {
          flag = 1;
          cout << s << '\n';
          break;
        }
      }
      if (flag) break;
    }
    if (!flag) cout << -1 << '\n';
  }
  return 0;
}
