#include <bits/stdc++.h>
using namespace std;
bool valid(vector<string> &arr, string &ans, int n, int m) {
  for (int i = 0; i < n; i++) {
    int errors = 0;
    for (int j = 0; j < m; j++) {
      if (arr[i][j] != ans[j]) errors++;
    }
    if (errors > 1) {
      return false;
    }
  }
  return true;
}
string solve(vector<string> &arr, int n, int m) {
  string ans = arr[0];
  for (int i = 0; i < m; i++) {
    char save = ans[i];
    for (char j = 'a'; j <= 'z'; j++) {
      ans[i] = j;
      if (valid(arr, ans, n, m)) {
        return ans;
      } else {
        ans[i] = save;
      }
    }
  }
  return "-1";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t, n, m;
  cin >> t;
  while (t--) {
    cin >> n >> m;
    vector<string> arr(n);
    for (int i = 0; i < n; i++) cin >> arr[i];
    cout << solve(arr, n, m) << "\n";
  }
  return 0;
}
