#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
bool check(vector<ll> cnt, ll remaining) {
ll mx = *max_element(cnt.begin(), cnt.end());
return mx <= (remaining+1) / 2;
}
signed main() {
ios_base::sync_with_stdio(0); cin.tie(0);
ll tc; cin >> tc;
test:
while (tc--) {
string s; cin >> s;
ll n = s.size();
vector<ll> cnt(26);
for (char &u : s) cnt[u-'a']++;
if (!check(cnt, n)){
cout << "-1\n";
goto test;
}
string ans;
ll last = -1;
for (ll i = 0; i < n; i++) {
bool ok = false;
for (ll j = 0; j < 26; j++) {
if (cnt[j] == 0) continue;
if (j == last) continue;
cnt[j]--;
if (check(cnt, n-i-1)) {
ans.push_back(char('a'+j));
last = j;
ok = true;
break;
}
cnt[j]++;
}
if (!ok) break;
}
if (ans.size() != n) cout << "-1\n";
else cout << ans << "\n";
}
}