#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int t, n, m, flag, flag1, index, count;
  char ch, prev;
  cin >> t;
  while (t--) {
    cin >> n >> m;
    vector<string> arr;
    arr.resize(n);
    for (long long int i = 0; i < n; i++) cin >> arr[i];
    flag = 0;
    for (long long int i = 0; i < m; i++) {
      prev = arr[0][i];
      for (long long int j = 0; j < 26; j++) {
        ch = (char)('a' + j);
        arr[0][i] = ch;
        flag1 = 0;
        for (long long int i1 = 0; i1 < n; i1++) {
          count = 0;
          for (long long int i2 = 0; i2 < m; i2++) {
            if (arr[0][i2] != arr[i1][i2]) count++;
          }
          if (count > 1) {
            flag1 = 1;
            break;
          }
        }
        if (flag1 == 0) {
          flag = 1;
          for (long long int i3 = 0; i3 < m; i3++) cout << arr[0][i3];
          cout << endl;
          break;
        }
      }
      arr[0][i] = prev;
      if (flag == 1) break;
    }
    if (flag == 0) cout << "-1\n";
  }
  return 0;
}
