#include <bits/stdc++.h>
using namespace std;
long long int n, m, t;
long long int power(long long int a, long long int n) {
  if (n == 0) {
    return 1;
  }
  long long int p = power(a, n / 2) % 1000000000;
  p = (p * p) % 1000000000;
  if (n % 2 == 1) {
    p = (p * a) % 1000000000;
  }
  return p;
}
long long int gcd(long long int a, long long int b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
long long int comp(string s, vector<string> &a) {
  long long int flag = 1;
  for (int i = 0; i < n; i++) {
    long long int count = 0;
    for (int j = 0; j < m; j++) {
      if (s[j] != a[i][j]) {
        count++;
      }
    }
    if (count > 1) {
      flag = -1;
      break;
    }
  }
  return flag;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> t;
  while (t--) {
    cin >> n >> m;
    vector<string> a(n);
    ;
    for (long long int i = 0; i < n; i++) cin >> a[i];
    ;
    long long int flag = 0;
    for (int i = 0; i < m; i++) {
      string s = a[0];
      for (int j = 0; j < 26; j++) {
        s[i] = (char)(j + 97);
        if (comp(s, a) == 1) {
          flag = 1;
          cout << s << "\n";
          break;
        }
      }
      if (flag == 1) {
        break;
      }
    }
    if (flag == 0) {
      cout << -1 << "\n";
    }
  }
  return 0;
}
