#include <bits/stdc++.h>
using namespace std;
char a[20][20], ans[20];
int n, m;
bool isValid() {
  for (int i = 2; i <= n; i++) {
    int c = 0;
    for (int j = 1; j <= m; j++) c += (ans[j] != a[i][j]);
    if (c > 1) return false;
  }
  return true;
}
void fun() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> (a[i] + 1);
  for (int i = 1; i <= m; i++) ans[i] = a[1][i];
  ans[m + 1] = '\0';
  if (isValid())
    cout << (ans + 1) << "\n";
  else {
    bool isGood = false;
    for (int i = 1; i <= m && !isGood; i++) {
      for (char c = 'a'; c <= 'z' && !isGood; c++) {
        if (c != a[1][i]) {
          ans[i] = c;
          if (isValid()) {
            cout << (ans + 1) << "\n";
            isGood = true;
          }
        }
      }
      ans[i] = a[1][i];
    }
    if (!isGood) cout << "-1\n";
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    fun();
  }
  return 0;
}
