#include <bits/stdc++.h>
using namespace std;
int T;
string hxt[16];
int main() {
  cin >> T;
  while (T--) {
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= n; i++) cin >> hxt[i];
    bool iif = false;
    for (int i = 0; i < m; i++) {
      char x = hxt[1][i];
      for (char j = 'a'; j <= 'z'; j++) {
        hxt[1][i] = j;
        bool flag = true;
        for (int k = 2; k <= n; k++) {
          int js = 0;
          for (int l = 0; l < m; l++) {
            if (hxt[k][l] != hxt[1][l]) js++;
            if (js > 1) break;
          }
          if (js > 1) {
            flag = false;
            break;
          }
        }
        if (flag) {
          cout << hxt[1] << endl;
          iif = true;
          break;
        }
        hxt[1][i] = x;
      }
      if (iif) break;
    }
    if (!iif) cout << -1 << endl;
  }
  return 0;
}
