#include<bits/stdc++.h>
using namespace std;
#define int long long int
int find_max_freq(vector<int> cnt) {
int max_f = 0;
for (int count : cnt) {
if (count > max_f) {
max_f = count;
}
}
return max_f;
}
int solve(){
string s;
cin>>s;
if(s.size() == 1){
cout<<s<<endl;
return 0;
}
int mxcnt = 0;
vector<int> cnt(26, 0);
for(int i = 0; i < s.size(); i++){
cnt[s[i] - 'a']++;
mxcnt = max(mxcnt, cnt[s[i] - 'a']);
}
if(mxcnt > (s.size() + 1) / 2){
cout<<-1<<endl;
return 0;
}
string ans = "";
vector<pair<int, char>> compress;
for(int i = 0; i < 26; i++){
if(cnt[i] > 0){
compress.push_back({cnt[i], i + 'a'});
}
}
string result = "";
int last_char_idx = -1;
int n = s.size();
for (int i = 0; i < n; ++i) {
for (int j = 0; j < 26; ++j) {
if (cnt[j] > 0 && j != last_char_idx) {
cnt[j]--;
int rem_len = n - 1 - i;
if (rem_len == 0 || find_max_freq(cnt) <= (rem_len + 1) / 2) {
result += (char)('a' + j);
last_char_idx = j;
break;
} else {
cnt[j]++;
}
}
}
}
cout << result << endl;
return 0;
}
int32_t main(){
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// #endif
int t;
t = 1;
cin>>t;
while(t--){
solve();
}
return 0;
}