#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 7;
int n, m;
char mp[15][15];
void solve() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%s", mp[i] + 1);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      for (int k = 1; k <= n; k++) {
        char s[15];
        for (int z = 1; z <= m; z++) s[z] = mp[i][z];
        s[j] = mp[k][j];
        s[m + 1] = '\0';
        bool ff = true;
        for (int z = 1; z <= n; z++) {
          if (z == i) continue;
          int num = 0;
          for (int x = 1; x <= m; x++) {
            if (mp[z][x] != s[x]) num++;
          }
          if (num > 1) {
            ff = false;
            break;
          }
        }
        if (ff) {
          printf("%s\n", s + 1);
          return;
        }
      }
    }
  }
  printf("-1\n");
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    solve();
  }
}
