#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int m;
    cin >> m;
    vector<string> v;
    for (int i = 0; i < n; i++) {
      string c;
      cin >> c;
      v.push_back(c);
    }
    string ans = v[0];
    string ans1 = ans;
    int is = 0;
    int is1 = 0;
    for (int j = 0; j < m; j++) {
      char save = ans[j];
      for (char c = 'a'; c <= 'z'; c++) {
        ans[j] = c;
        is = 0;
        for (int k = 0; k < n; k++) {
          int counterror = 0;
          string curr = v[k];
          for (int l = 0; l < m; l++) {
            if (curr[l] != ans[l]) {
              counterror++;
            }
          }
          if (counterror > 1) {
            is = 1;
            break;
          }
        }
        if (is == 1) {
          ans[j] = save;
        } else {
          cout << ans << endl;
          break;
        }
      }
      if (is == 0) {
        is1 = 1;
        break;
      }
    }
    if (is1 == 0) {
      cout << -1 << endl;
    }
  }
}
