#include <bits/stdc++.h> // All praise is due to Allah alone, and peace and blessings be
using namespace std; // upon him, after whom there is no other Prophet.
int32_t main() {
cin.tie(0)->sync_with_stdio(false);
function<void()> Test_Case = [&]() {
string s; cin >> s;
int n = s.size();
int ar[26] = {0};
for(const char c : s) {
ar[c - 'a']++;
}
if(*max_element(ar, ar + 26) > (n + 1) / 2) {
cout << "-1\n"; return;
}
s.clear();
for(int i = 0; i < n; i++) {
for(int j = 0; j < 26; j++) {
if(ar[j] == 0) continue;
char ok = char('a' + j);
if(s.size() and s.back() == ok) continue;
int it = max_element(ar, ar + 26) - ar;
if(it != j and ar[it] > (n - i) / 2) continue;
ar[j]--;
s.push_back(ok);
break;
}
}
cout << s << '\n';
};
int32_t Case = 1; cin >> Case;
for (int T = 1; T <= Case; T++) {
Test_Case();
}
return 0;
}