#include <iostream>
#include <unordered_set>
#include <string>
#include <vector>
using namespace std;
bool isValidAlienABC(const string& S, unordered_set<string>& seen) {
int n = S.size();
for (int i = 0; i < n; ++i) {
for (int len = 1; len <= 2 && i + len <= n; ++len) {
string letter = S.substr(i, len);
if (seen.find(letter) != seen.end()) return false;
seen.insert(letter);
}
}
return true;
}
void reconstructAlienABC(const string& S) {
unordered_set<string> seen;
string result;
int n = S.size();
for (int i = 0; i < n; ) {
if (i + 1 < n && S[i] == S[i + 1]) { // Double letter case
string doubleLetter = S.substr(i, 2);
if (seen.find(doubleLetter) != seen.end()) {
cout << -1 << endl;
return;
}
result += doubleLetter + " ";
seen.insert(doubleLetter);
i += 2;
} else { // Single letter case
string singleLetter = S.substr(i, 1);
if (seen.find(singleLetter) != seen.end()) {
cout << -1 << endl;
return;
}
result += singleLetter + " ";
seen.insert(singleLetter);
i++;
}
}
cout << result << endl;
}
int main() {
int T;
cin >> T;
while (T--) {
string S;
cin >> S;
reconstructAlienABC(S);
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dW5vcmRlcmVkX3NldD4KI2luY2x1ZGUgPHN0cmluZz4KI2luY2x1ZGUgPHZlY3Rvcj4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmJvb2wgaXNWYWxpZEFsaWVuQUJDKGNvbnN0IHN0cmluZyYgUywgdW5vcmRlcmVkX3NldDxzdHJpbmc+JiBzZWVuKSB7CiAgICBpbnQgbiA9IFMuc2l6ZSgpOwogICAgZm9yIChpbnQgaSA9IDA7IGkgPCBuOyArK2kpIHsKICAgICAgICBmb3IgKGludCBsZW4gPSAxOyBsZW4gPD0gMiAmJiBpICsgbGVuIDw9IG47ICsrbGVuKSB7CiAgICAgICAgICAgIHN0cmluZyBsZXR0ZXIgPSBTLnN1YnN0cihpLCBsZW4pOwogICAgICAgICAgICBpZiAoc2Vlbi5maW5kKGxldHRlcikgIT0gc2Vlbi5lbmQoKSkgcmV0dXJuIGZhbHNlOwogICAgICAgICAgICBzZWVuLmluc2VydChsZXR0ZXIpOwogICAgICAgIH0KICAgIH0KICAgIHJldHVybiB0cnVlOwp9Cgp2b2lkIHJlY29uc3RydWN0QWxpZW5BQkMoY29uc3Qgc3RyaW5nJiBTKSB7CiAgICB1bm9yZGVyZWRfc2V0PHN0cmluZz4gc2VlbjsKICAgIHN0cmluZyByZXN1bHQ7CiAgICBpbnQgbiA9IFMuc2l6ZSgpOwoKICAgIGZvciAoaW50IGkgPSAwOyBpIDwgbjsgKSB7CiAgICAgICAgaWYgKGkgKyAxIDwgbiAmJiBTW2ldID09IFNbaSArIDFdKSB7IC8vIERvdWJsZSBsZXR0ZXIgY2FzZQogICAgICAgICAgICBzdHJpbmcgZG91YmxlTGV0dGVyID0gUy5zdWJzdHIoaSwgMik7CiAgICAgICAgICAgIGlmIChzZWVuLmZpbmQoZG91YmxlTGV0dGVyKSAhPSBzZWVuLmVuZCgpKSB7CiAgICAgICAgICAgICAgICBjb3V0IDw8IC0xIDw8IGVuZGw7CiAgICAgICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgIH0KICAgICAgICAgICAgcmVzdWx0ICs9IGRvdWJsZUxldHRlciArICIgIjsKICAgICAgICAgICAgc2Vlbi5pbnNlcnQoZG91YmxlTGV0dGVyKTsKICAgICAgICAgICAgaSArPSAyOwogICAgICAgIH0gZWxzZSB7IC8vIFNpbmdsZSBsZXR0ZXIgY2FzZQogICAgICAgICAgICBzdHJpbmcgc2luZ2xlTGV0dGVyID0gUy5zdWJzdHIoaSwgMSk7CiAgICAgICAgICAgIGlmIChzZWVuLmZpbmQoc2luZ2xlTGV0dGVyKSAhPSBzZWVuLmVuZCgpKSB7CiAgICAgICAgICAgICAgICBjb3V0IDw8IC0xIDw8IGVuZGw7CiAgICAgICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgIH0KICAgICAgICAgICAgcmVzdWx0ICs9IHNpbmdsZUxldHRlciArICIgIjsKICAgICAgICAgICAgc2Vlbi5pbnNlcnQoc2luZ2xlTGV0dGVyKTsKICAgICAgICAgICAgaSsrOwogICAgICAgIH0KICAgIH0KICAgIGNvdXQgPDwgcmVzdWx0IDw8IGVuZGw7Cn0KCmludCBtYWluKCkgewogICAgaW50IFQ7CiAgICBjaW4gPj4gVDsKICAgIHdoaWxlIChULS0pIHsKICAgICAgICBzdHJpbmcgUzsKICAgICAgICBjaW4gPj4gUzsKICAgICAgICByZWNvbnN0cnVjdEFsaWVuQUJDKFMpOwogICAgfQogICAgcmV0dXJuIDA7Cn0=