#ifndef LOCAL
#include <bits/stdc++.h>
#define debug(...)
#endif
using namespace std;
#define int long long
#define cinv(v) for (auto &it:v) cin>>it;
#define coutv(v) for (auto &it:v) cout<< it<<' '; cout<<'\n';
void shelby() {
string s;
cin >> s;
int n = s.size();
map<char,int> freq;
map<int, set<char>, greater<> > mp;
for (auto &it: s) freq[it]++;
for (auto &[u,v]: freq) mp[v].insert(u);
debug(mp, n);
if (mp.begin()->first * 2 - (n % 2) > n) return void(cout << "-1\n");
string t;
while (!mp.empty()) {
int rem = n - t.size() - 1;
int slot = (rem + 1) / 2;
if (slot < mp.begin()->first) {
char c = *mp.begin()->second.begin();
t += c;
freq[c]--;
mp.begin()->second.erase(c);
if (mp.begin()->second.empty()) mp.erase(mp.begin());
if (freq[c]) mp[freq[c]].insert(c);
else freq.erase(c);
}
else {
auto it = freq.begin();
if (!t.empty() && t.back() == it->first) ++it;
t += it->first;
// if (it == freq.end()) {
// debug(t);
// return;
// }
assert(it!=freq.end());
int cnt = it->second;
mp[cnt].erase(it->first);
if (mp[cnt].empty()) mp.erase(cnt);
if (cnt - 1) mp[cnt - 1].insert(it->first);
it->second--;
if (it->second == 0) freq.erase(it);
}
}
cout << t << '\n';
}
signed main() {
cin.tie(0)->sync_with_stdio(0);
int t = 1;
cin >> t;
for (int _ = 1; _ <= t; ++_) {
// cout << "Case " << _ << ": ";
shelby();
}
}