#include <bits/stdc++.h>
using namespace std;
string str[15];
string ans;
int n, m;
int check() {
  for (int i = 0; i < n; i++) {
    int num = 0;
    for (int j = 0; j < m; j++) {
      if (str[i][j] != ans[j]) num++;
    }
    if (num > 1) return 0;
  }
  return 1;
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    scanf("%d%d", &n, &m);
    for (int i = 0; i < n; i++) cin >> str[i];
    int flag = 0;
    for (int i = 0; i < m && flag == 0; i++) {
      for (int j = 0; j < 26; j++) {
        ans = str[0];
        ans[i] = 'a' + j;
        if (check()) {
          flag = 1;
          cout << ans << endl;
          break;
        }
      }
    }
    if (flag == 0) printf("-1\n");
  }
  return 0;
}
