#include <bits/stdc++.h>
using namespace std;
bool chec(string aa, string arr[], long long int n, long long int m) {
  for (long long int i = 0; i < n; i++) {
    long long int cnt = 0;
    for (long long int j = 0; j < m; j++) {
      if (aa[j] != arr[i][j]) cnt++;
    }
    if (cnt > 1) return false;
  }
  return true;
}
void solve() {
  long long int n, m;
  cin >> n >> m;
  string arr[n];
  for (long long int i = 0; i < n; i++) cin >> arr[i];
  string ans;
  long long int ch = 0;
  string aa = arr[0];
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j < m; j++) {
      for (long long int k = 0; k < 26; k++) {
        char p = 'a' + k;
        char temp = aa[j];
        aa[j] = p;
        if (chec(aa, arr, n, m)) {
          ans = aa;
          ch = 1;
          break;
        }
        aa[j] = temp;
      }
      if (ch) break;
    }
    if (ch) break;
  }
  if (ch)
    cout << ans << "\n";
  else
    cout << -1 << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t = 1;
  cin >> t;
  while (t--) solve();
}
