#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  long long tt;
  cin >> tt;
  while (tt--) {
    long long n, m, flag1 = 0, flag2 = 0;
    cin >> n >> m;
    string second[n], s1, s2;
    for (long long i = 0; i < n; i++) cin >> second[i];
    for (long long j = 0; j < m; j++) {
      for (char c = 'a'; c <= 'z'; c++) {
        string t = second[0];
        t[j] = c;
        long long cou, flag = 0;
        for (long long k = 1; k < n; k++) {
          cou = 0;
          for (long long l = 0; l < m; l++) {
            if (second[k][l] != t[l]) cou++;
          }
          if (cou > 1) flag = 1;
        }
        if (flag == 0 && flag2 == 0) {
          cout << t << "\n";
          flag2 = 1;
        }
      }
    }
    if (flag2 == 0)
      cout << "-1"
           << "\n";
  }
}
