#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<string> s;
bool check(string temp) {
  for (int i = 1; i < n; i++) {
    int cnt = 0;
    for (int j = 0; j < m; j++) {
      if (s[i][j] != temp[j]) cnt++;
      if (cnt > 1) return 0;
    }
  }
  return 1;
}
void solve() {
  s.clear();
  string st;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> st;
    s.push_back(st);
  }
  string temp;
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < 26; j++) {
      temp = s[0];
      temp[i] = 'a' + j;
      if (check(temp)) {
        cout << temp << endl;
        return;
      }
    }
  }
  cout << "-1\n";
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
