#include <bits/stdc++.h>
using namespace std;
int n, m;
string arr[15];
bool solve(string s) {
  for (int i = 0; i < n; ++i) {
    int c = 0;
    for (int j = 0; j < m; ++j) {
      if (arr[i][j] != s[j]) {
        ++c;
      }
    }
    if (c > 1) {
      return 0;
    }
  }
  return 1;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    cin >> n >> m;
    for (int i = 0; i < n; ++i) {
      cin >> arr[i];
    }
    bool f = 0;
    for (int i = 0; i < m; ++i) {
      string ans = arr[0];
      for (int j = 0; j < 26; ++j) {
        char ch = ('a' + j);
        ans[i] = ch;
        if (solve(ans)) {
          cout << ans << "\n";
          f = 1;
          break;
        }
      }
      if (f) {
        break;
      }
    }
    if (!f) {
      cout << "-1\n";
    }
  }
  return 0;
}
