#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    string s[n], ans;
    for (int i = 0; i < n; i++) cin >> s[i];
    ans = s[0];
    int f = 1;
    for (int j = 0; j < m; j++) {
      char d = ans[j];
      for (char i = 'a'; i <= 'z'; i++) {
        ans[j] = i;
        f = 1;
        for (int k = 0; k < n; k++) {
          int cnt = 0;
          for (int l = 0; l < m; l++) {
            if (s[k][l] != ans[l]) cnt++;
          }
          if (cnt > 1) {
            f = 0;
            break;
          }
        }
        if (f) {
          cout << ans << endl;
          f = 2;
          break;
        }
      }
      if (f == 2) break;
      ans[j] = d;
    }
    if (f != 2) cout << -1 << endl;
  }
}
