#include <bits/stdc++.h>
using namespace std;
long long power(long long b, long long e, long long m) {
  if (e == 0) return 1;
  if (e & 1) return b * power(b * b % m, e / 2, m) % m;
  return power(b * b % m, e / 2, m);
}
long long power(long long b, long long e) {
  if (e == 0) return 1;
  if (e & 1) return b * power(b * b, e / 2);
  return power(b * b, e / 2);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    string s[n];
    set<string> se;
    for (int i = 0; i < n; i++) {
      cin >> s[i];
      se.insert(s[i]);
    }
    if (n == 1 || se.size() == 1)
      cout << s[0] << "\n";
    else {
      string ans = *se.begin();
      char prev;
      bool found = true;
      string ansfin;
      for (int i = 0; i < m; i++) {
        prev = ans[i];
        for (char j = 'a'; j <= 'z'; j++) {
          ans[i] = j;
          found = true;
          for (int k = 0; k < n; k++) {
            int c = 0;
            for (int l = 0; l < m; l++) {
              if (s[k][l] != ans[l]) c++;
            }
            if (c > 1) {
              found = false;
              break;
            }
          }
          if (found == true) {
            ansfin = ans;
            break;
          }
        }
        if (found) break;
        ans[i] = prev;
      }
      if (found)
        cout << ansfin << "\n";
      else
        cout << "-1"
             << "\n";
    }
  }
  return 0;
}
