#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const long long INF = 1e19;
const long long mod = 1e9 + 7;
const double pi = 3.1415926536;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n, m, cnt = 0;
    bool yes = true, f = false;
    cin >> n >> m;
    vector<string> v(n);
    for (int i = 0; i < n; i++) cin >> v[i];
    string st = v[0];
    for (int c = 0; c < m && !f; c++) {
      for (char i = 'a'; i <= 'z' && !f; i++) {
        char x = st[c];
        st[c] = i;
        yes = true;
        for (int j = 0; j < n && !f; j++) {
          cnt = 0;
          for (int k = 0; k < m && !f; k++) {
            if (v[j][k] != st[k]) cnt++;
          }
          if (cnt > 1) {
            yes = false;
            break;
          }
        }
        if (yes) {
          f = true;
          break;
        }
        st[c] = x;
      }
    }
    if (f)
      cout << st << endl;
    else
      cout << -1 << endl;
  }
  return 0;
}
