/**
* 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() {
deque<char> a;
string s; cin >> s;
for (int i = 0; i < sz(s); ++i)a.push_back(s[i]);
int n = sz(s);
string res;
sort(all(a));
for (int i = 0; i < n; ++i) {
if (sz(res) == 0) {
res += a.front();
a.pop_front();
continue;
}
for (auto j: a) {
if (j != res.back()){
deque<int>::iterator itr;
//char ch = 'a';
a.erase(find(a.begin(), a.end(), j));
res += j;
break;
}
}
}
//cout << res << nl;
for (auto i: a) {
bool can = false;
for (int j = sz(res)-1; j >= 0; --j) {
bool ok = false;
string s1, t1;
if (j > 0) {
s1 = res.substr(0, j+1);
if (i == res[j])ok = true;
}
if (j < sz(res)) {
t1 = res.substr(j+1, sz(res)-j-i);
if (i == res[j+1])ok = true;
}
if (ok)continue;
can = true;
res = s1+i+t1;
break;
}
if (!can && res.front()!=i) {
res = i+res;
}
}
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;
}