#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<string> v(10);
bool check(string s) {
  for (int i = 0; i < n; i++) {
    int ct = 0;
    for (int j = 0; j < m; j++) ct += (v[i][j] != s[j]);
    if (ct > 1) return false;
  }
  return true;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t;
  cin >> t;
  while (t--) {
    cin >> n >> m;
    v.clear();
    v.resize(n + 1);
    for (int i = 0; i < n; i++) cin >> v[i];
    int flag = 0;
    for (int i = 0; i < m; i++) {
      string ans = v[0];
      for (int j = 0; j < 26; j++) {
        ans[i] = char(j + 'a');
        if (check(ans)) {
          cout << ans << "\n";
          flag = 1;
          break;
        }
      }
      if (flag == 1) break;
    }
    if (!flag)
      cout << "-1"
           << "\n";
  }
}
