#include <bits/stdc++.h>
using namespace std;
long long n, m;
char a[100][100];
char final_string[100];
bool isok() {
  for (long long i = 2; i <= n; i++) {
    long long c = 0;
    for (long long j = 1; j <= m; j++) {
      if (final_string[j] != a[i][j]) c++;
    }
    if (c > 1) return false;
  }
  return true;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    cin >> n >> m;
    for (long long i = 1; i <= n; i++) {
      for (long long j = 1; j <= m; j++) {
        cin >> a[i][j];
      }
    }
    for (long long j = 1; j <= m; j++) {
      final_string[j] = a[1][j];
    }
    long long flag = 0;
    for (long long i = 1; i <= m; i++) {
      for (char c = 'a'; c <= 'z'; c++) {
        final_string[i] = c;
        if (isok()) {
          for (long long i = 1; i <= m; i++) {
            cout << final_string[i];
          }
          cout << "\n";
          flag = 1;
          break;
        }
      }
      final_string[i] = a[1][i];
      if (flag == 1) break;
    }
    if (flag == 0)
      cout << "-1"
           << "\n";
  }
  return 0;
}
