/*
JAI JAGANNATH!
*/
//@Author : zanj0
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <class T>
using ordered_set = __gnu_pbds::tree<T, __gnu_pbds::null_type, less<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;
#define ff first
#define ss second
#define pb push_back
#define MOD 1000000007
#define inf 1e18
#define ps(x, y) fixed << setprecision(y) << x
#define w(x) \
int x; \
cin >> x; \
while (x--)
#define endl "\n"
#define timetaken cerr << "Time : " << 1000 * (long double)clock() / (long double)CLOCKS_PER_SEC << "ms\n"
typedef long long int lli;
void zanj0()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
#endif
}
void Solve()
{
string s;
cin >> s;
int n = s.size();
vector<int> cnt(26);
for (auto &it : s)
{
cnt[it - 'a']++;
if (cnt[it - 'a'] > (n + 1) / 2)
{
cout << -1 << endl;
return;
}
}
string ret = "";
char last = '*';
for (int i = 0; i < n; i++)
{
int left = n - i;
int max_val = (left + 1) / 2;
char add = (char)('z' + 1);
for (int j = 0; j < 26; j++)
{
if (!cnt[j])
continue;
char now = (char)('a' + j);
int next_max_val = ((left - 1) + 1) / 2;
if (cnt[j] == max_val && max_val > next_max_val)
{
if (last != now)
{
add = now;
break;
}
else
{
cout << -1 << endl;
return;
}
}
else if (last != now && now < add)
add = now;
}
ret += add;
cnt[add - 'a']--;
last = add;
}
cout << ret << endl;
}
int32_t main()
{
zanj0();
w(t) Solve();
timetaken;
return 0;
}