/*
Submitted With (^^) by -> Hossam ^_^
_____________________
| ___ ___ |
| (^_^) (^_^) |
| /( | )\_/( | )\ |
|_____|_|_____|_|_____|
*/
#include <bits/stdc++.h>
using namespace std;
inline void prep()
{
cin.tie(0);
cin.sync_with_stdio(0);
}
#define X first
#define Y second
#define ll long long
#define inf (0x7fffffffffffffff)
#define all(x) x.begin(), x.end()
#define ZXC cerr << clock() * 1.0 / CLOCKS_PER_SEC << endl;
const int mod = (int)1e9 + 7;
const int MX = (int)1e6 + 5;
int main()
{
prep();
int tc;
cin >> tc;
int T = tc;
while (tc--)
{
int n, l;
cin >> n >> l;
vector<string> s(n);
bool ch[30][30][30];
bool mask[30][30];
memset(ch, 0, sizeof ch);
memset(mask, 0, sizeof mask);
for (int i = 0; i < n; ++i)
{
cin >> s[i];
for (int idx = 0; idx < l; ++idx)
{
if (idx + 1 < l)
ch[s[i][idx] - 'A'][idx][(s[i][idx + 1] - 'A')] = 1;
mask[idx][s[i][idx] - 'A'] = 1;
}
}
string res = s[rand() % n];
bool found = false;
for (int c = 0; c < 26; ++c)
{
for (int idx = 0; idx + 1 < l; ++idx)
{
for (int i = 0; i < 26; ++i)
{
if (mask[idx][c] && ch[c][idx][i] ^ mask[idx + 1][i])
{
found = true;
res[idx] = 'A' + c;
res[idx + 1] = 'A' + i;
break;
}
}
if (found)
break;
}
if (found)
break;
}
cout << "Case #" << T - tc << ": " << (found ? res : "-") << "\n";
}
// ZXC
return 0;
}
LyoKU3VibWl0dGVkIFdpdGggKF5eKSBieSAtPiBIb3NzYW0gXl9eCiBfX19fX19fX19fX19fX19fX19fX18KfCAgICAgX19fICAgICBfX18gICAgIHwKfCAgICAoXl9eKSAgICheX14pICAgIHwKfCAgIC8oIHwgKVxfLyggfCApXCAgIHwKfF9fX19ffF98X19fX198X3xfX19fX3wKKi8KCiNpbmNsdWRlIDxiaXRzL3N0ZGMrKy5oPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmlubGluZSB2b2lkIHByZXAoKQp7CiAgICBjaW4udGllKDApOwogICAgY2luLnN5bmNfd2l0aF9zdGRpbygwKTsKfQoKI2RlZmluZSBYIGZpcnN0CiNkZWZpbmUgWSBzZWNvbmQKI2RlZmluZSBsbCBsb25nIGxvbmcKI2RlZmluZSBpbmYgKDB4N2ZmZmZmZmZmZmZmZmZmZikKI2RlZmluZSBhbGwoeCkgeC5iZWdpbigpLCB4LmVuZCgpCiNkZWZpbmUgWlhDIGNlcnIgPDwgY2xvY2soKSAqIDEuMCAvIENMT0NLU19QRVJfU0VDIDw8IGVuZGw7Cgpjb25zdCBpbnQgbW9kID0gKGludCkxZTkgKyA3Owpjb25zdCBpbnQgTVggPSAoaW50KTFlNiArIDU7CgppbnQgbWFpbigpCnsKICAgIHByZXAoKTsKCiAgICBpbnQgdGM7CiAgICBjaW4gPj4gdGM7CiAgICBpbnQgVCA9IHRjOwoKICAgIHdoaWxlICh0Yy0tKQogICAgewoKICAgICAgICBpbnQgbiwgbDsKICAgICAgICBjaW4gPj4gbiA+PiBsOwoKICAgICAgICB2ZWN0b3I8c3RyaW5nPiBzKG4pOwogICAgICAgIGJvb2wgY2hbMzBdWzMwXVszMF07CiAgICAgICAgYm9vbCBtYXNrWzMwXVszMF07CiAgICAgICAgbWVtc2V0KGNoLCAwLCBzaXplb2YgY2gpOwogICAgICAgIG1lbXNldChtYXNrLCAwLCBzaXplb2YgbWFzayk7CgogICAgICAgIGZvciAoaW50IGkgPSAwOyBpIDwgbjsgKytpKQogICAgICAgIHsKICAgICAgICAgICAgY2luID4+IHNbaV07CiAgICAgICAgICAgIGZvciAoaW50IGlkeCA9IDA7IGlkeCA8IGw7ICsraWR4KQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBpZiAoaWR4ICsgMSA8IGwpCiAgICAgICAgICAgICAgICAgICAgY2hbc1tpXVtpZHhdIC0gJ0EnXVtpZHhdWyhzW2ldW2lkeCArIDFdIC0gJ0EnKV0gPSAxOwogICAgICAgICAgICAgICAgbWFza1tpZHhdW3NbaV1baWR4XSAtICdBJ10gPSAxOwogICAgICAgICAgICB9CiAgICAgICAgfQoKICAgICAgICBzdHJpbmcgcmVzID0gc1tyYW5kKCkgJSBuXTsKICAgICAgICBib29sIGZvdW5kID0gZmFsc2U7CiAgICAgICAgZm9yIChpbnQgYyA9IDA7IGMgPCAyNjsgKytjKQogICAgICAgIHsKICAgICAgICAgICAgZm9yIChpbnQgaWR4ID0gMDsgaWR4ICsgMSA8IGw7ICsraWR4KQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBmb3IgKGludCBpID0gMDsgaSA8IDI2OyArK2kpCiAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgaWYgKG1hc2tbaWR4XVtjXSAmJiBjaFtjXVtpZHhdW2ldIF4gbWFza1tpZHggKyAxXVtpXSkKICAgICAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgICAgIGZvdW5kID0gdHJ1ZTsKICAgICAgICAgICAgICAgICAgICAgICAgcmVzW2lkeF0gPSAnQScgKyBjOwogICAgICAgICAgICAgICAgICAgICAgICByZXNbaWR4ICsgMV0gPSAnQScgKyBpOwogICAgICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoZm91bmQpCiAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKGZvdW5kKQogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgfQoKICAgICAgICBjb3V0IDw8ICJDYXNlICMiIDw8IFQgLSB0YyA8PCAiOiAiIDw8IChmb3VuZCA/IHJlcyA6ICItIikgPDwgIlxuIjsKICAgIH0KCiAgICAvLyBaWEMKICAgIHJldHVybiAwOwp9Cg==