/**
* In the name of Allah
* We are nothing and you're everything
* Ya Muhammad!
**/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = uint64_t;
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
//#define int long long
const char nl = '\n';
const int N = 1e5+5;
const ll inf = 0x3f3f3f3f3f3f3f3fll;
void solve() {
string s; cin >> s;
int n = sz(s);
vector<int> a(30);
for (auto i: s) {
a[i-'a'] += 1;
}
string res;
int m = n;
//cout << a[1] << nl;
for (int i = 0; i < n; ++i) {
bool did = false;
for (int j = 0; j < 27; ++j) {
//if (i == 0 && j == 1)cout << (a[j]+1)/2 << " " << m-a[j] << nl;
if (a[j]-1 == m-a[j] && (res.empty()||res.back()-'a' != j)) {
res += char(j+(int)('a'));
//cout << j << " " << i<< nl;
a[j]--;
m--;
did = true;
break;
}
}
//cout << did << nl;
if (!did) {
for (int j = 0; j < 27; ++j)
if ((res.empty()||res.back()-'a' != j) && a[j]>0) {
did = true;
res += char(j+(int)('a'));
m--;a[j]--;
break;
}
}
}
if (sz(res) < n)cout << -1 << nl;
else cout << res << nl;
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int t; cin >> t;
while(t--)solve();
return 0;
}