#include <bits/stdc++.h>
using namespace std;
vector<string> a;
int n, m;
bool check(string in) {
  for (int i = 0; i < n; ++i) {
    int c = 0;
    for (int j = 0; j < m; ++j) {
      if (in[j] != a[i][j]) {
        c++;
      }
    }
    if (c > 1) {
      return false;
    }
  }
  return true;
}
void solve() {
  cin >> n >> m;
  string res;
  a = vector<string>(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  for (int i = 0; i < m; ++i) {
    for (int j = 0; j < 26; ++j) {
      string s = a[0];
      s[i] = 'a' + j;
      if (check(s)) {
        cout << s << endl;
        return;
      }
    }
  }
  cout << -1 << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  for (int i = 1; i <= t; ++i) {
    solve();
  }
  return 0;
}
