#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n, m;
  cin >> n >> m;
  vector<string> vs;
  for (long long i = 0; i < n; i++) {
    string s;
    cin >> s;
    vs.push_back(s);
  }
  string first = vs[0];
  bool f1 = 1;
  long long cnt = 0;
  for (long long i = 0; i < m; i++) {
    char old = first[i];
    for (char c = 'a'; c <= 'z'; c++) {
      f1 = 1;
      first[i] = c;
      for (long long j = 0; j < n; j++) {
        cnt = 0;
        for (long long k = 0; k < m; k++) {
          if (first[k] != vs[j][k]) {
            cnt++;
          }
          if (cnt > 1) {
            f1 = 0;
            break;
          }
        }
      }
      if (f1) {
        cout << first << endl;
        return;
      }
      first[i] = old;
    }
  }
  cout << "-1" << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  long long trials;
  cin >> trials;
  while (trials--) {
    solve();
  }
}
