#include <bits/stdc++.h>
using namespace std;
long long int MOD = 1000000007;
long long int MOD1 = 998244353;
mt19937 tw(chrono::high_resolution_clock::now().time_since_epoch().count());
void solve() {
  int n, m;
  cin >> n >> m;
  string a[n], res;
  for (int i = 0; i < n; i++) cin >> a[i];
  res = a[0];
  for (int i = 0; i < m; i++) {
    for (int j = 'a'; j <= 'z'; j++) {
      string t = res;
      t[i] = j;
      int f = 1;
      for (int k = 0; k < n; k++) {
        int c = 0;
        for (int l = 0; l < m; l++) {
          if (t[l] != a[k][l]) c++;
        }
        if (c > 1) {
          f = 0;
          break;
        }
      }
      if (f == 1) {
        cout << t << "\n";
        return;
      }
    }
  }
  cout << -1 << "\n";
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int q;
  cin >> q;
  while (q--) solve();
}
