#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    long long n, m;
    cin >> n >> m;
    vector<string> ar(11);
    for (int i = 0; i < n; i++) {
      cin >> ar[i];
    }
    string ans;
    bool res = false;
    for (int i = 0; i < m && !res; i++) {
      for (int j = 0; j < 26 && !res; j++) {
        string s = ar[0];
        s[i] = 'a' + j;
        bool te = true;
        for (int k = 0; k < n; k++) {
          long long co = 0;
          for (int l = 0; l < m; l++) {
            if (ar[k][l] != s[l]) {
              co++;
            }
          }
          if (co > 1) {
            te = false;
            break;
          }
        }
        if (te) {
          cout << s << endl;
          res = true;
          break;
        }
      }
    }
    if (!res) {
      cout << -1 << endl;
    }
  }
}
