#include <bits/stdc++.h>   using namespace std;   const long long N = 1e5 + 5;   bool match(string s1, string s2) {     long long cnt = 0;     for (long long i = 0; s1[i]; ++i) {       if (s1[i] != s2[i]) ++cnt;       if (cnt > 1) return 0;     }     return 1;   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t;     cin >> t;     while (t--) {       long long n, m;       cin >> n >> m;       vector<string> v(n);       for (long long i = 0; i < n; ++i) cin >> v[i];       bool ans = 0;       string str;       for (long long i = 0; i < m; ++i) {         string s = v[0];         for (long long j = 1; j < n; ++j) {           s[i] = v[j][i];           bool all_match = 1;           for (long long k = 1; k < n; ++k) {             if (!match(s, v[k])) {               all_match = 0;               break;             }           }           if (all_match) {             ans = 1;             str = s;             break;           }         }         if (ans) break;       }       if (ans)         cout << str <<   n ;       else {         bool all_match = 1;         for (long long i = 1; i < n; ++i) {           if (!match(v[0], v[i])) {             all_match = 0;             break;           }         }         if (all_match)           cout << v[0] <<   n ;         else           cout << -1 <<   n ;       }     }   }   