#include <bits/stdc++.h>
using namespace std;
const int N = 500050;
const int inf = 0x3f3f3f3f;
const long long llinf = 0x3f3f3f3f3f3f;
const long long mod = 998244353LL;
clock_t TIME_START, TIME_END;
void program_end() {}
int n, m;
string s[N];
string ans;
void solve() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) cin >> s[i];
  bool flag = 0;
  ans.clear();
  ans = s[1];
  for (int i = 0; i < m; ++i) {
    int ori = ans[i] - 'a';
    for (int c = 0; c < 26; ++c) {
      ans[i] = c + 'a';
      bool yes = 1;
      for (int id = 2; id <= n; ++id) {
        int diff = 0;
        for (int j = 0; j < m; ++j)
          if (ans[j] != s[id][j]) diff++;
        if (diff >= 2) {
          yes = 0;
          break;
        }
      }
      flag |= yes;
      if (flag) break;
    }
    if (flag) {
      cout << ans << '\n';
      return;
    }
    ans[i] = ori + 'a';
  }
  puts("-1");
}
int main() {
  TIME_START = clock();
  int Test = 1;
  cin >> Test;
  while (Test--) solve();
  TIME_END = clock();
  program_end();
  return 0;
}
