#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    vector<string> v(n);
    for (int i = 0; i < n; i++) cin >> v[i];
    int c = 0;
    string ans = "-1", temp;
    for (int i = 0; i < m; i++) {
      temp = v[0];
      for (char j = 'a'; j <= 'z'; j++) {
        temp[i] = j;
        for (int k = 0; k < n; k++) {
          c = 0;
          for (int l = 0; l < m; l++)
            if (v[k][l] != temp[l]) c++;
          if (c > 1) break;
        }
        if (c <= 1) {
          ans = temp;
          break;
        }
      }
      if (ans != "-1") break;
    }
    cout << ans << '\n';
  }
  return 0;
}
