#include <bits/stdc++.h>
using namespace std;
string s[15];
long long int n, m;
bool check(string str) {
  for (long long int i = 0; i < n; i++) {
    long long int cnt = 0;
    for (long long int j = 0; j < m; j++) {
      if ((str[j] != s[i][j])) cnt++;
      if (cnt > 1) return 0;
    }
  }
  return 1;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t;
  cin >> t;
  while (t--) {
    cin >> n >> m;
    for (long long int i = 0; i < n; i++) cin >> s[i];
    if (check(s[0]))
      cout << s[0] << "\n";
    else {
      bool printed = 0;
      for (long long int i = 0; i < m; i++) {
        string str = s[0];
        for (char ch = 'a'; ch <= 'z'; ch++) {
          str[i] = ch;
          if (check(str)) {
            cout << str << "\n";
            printed = 1;
            break;
          }
        }
        if (printed) break;
      }
      if (!printed) cout << -1 << "\n";
    }
  }
  return 0;
}
