#include <bits/stdc++.h>
using namespace std;
char c[10][10];
int check(int m, int n) {
  for (int i = 0; i < n; i++) {
    int ct = 0;
    for (int j = 0; j < m; j++) {
      if ((c[i][j] != c[0][j])) ct++;
    }
    if (ct > 1) {
      return 0;
    }
  }
  return 1;
}
string findstring(int m, int n) {
  for (int i = 0; i < m; i++) {
    char rev = c[0][i];
    for (int j = 0; j < 26; j++) {
      c[0][i] = char('a' + j);
      int rt = check(m, n);
      if (rt) {
        string result = "";
        for (int k = 0; k < m; k++) {
          result += c[0][k];
        }
        return result;
      }
    }
    c[0][i] = rev;
  }
  return "-1";
}
int main() {
  int T;
  cin >> T;
  while (T--) {
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
      string t;
      cin >> t;
      for (int j = 0; j < m; j++) {
        c[i][j] = t[j];
      }
    }
    cout << findstring(m, n) << "\n";
  }
  return 0;
}
