#pragma GCC optimize("O3", "inline")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define ub upper_bound
#define INF 1e18 + 100
const int asz = 26;
string solve()
{
string s;
cin >> s;
int n = s.size();
vector<int> fa(26, 0);
for (int i = 0; i < n; i++)
fa[s[i] - 'a']++;
char last = '\0';
for (int i = 0; i < n; i++)
{
int fc = 0, mc = 0;
int fg = 0;
for (int i = 25; i >= 0; i--)
{
if((char)(i + 'a') == last) continue;
if (fa[i])
{
fg = 1;
if (fa[i] > fa[mc])
mc = i;
fc = i;
}
}
if(!fg) return "-1";
if (mc != fc)
{
if ((n - i) / 2 >= fa[mc])
{
s[i] = (char)('a' + fc);
fa[fc]--;
}
else if ((n - i) / 2 >= fa[mc] - 1)
{
s[i] = (char)('a' + mc);
fa[mc]--;
}
else
return "-1";
}
else
{
if ((n - i) / 2 >= fa[mc] - 1)
{
s[i] = (char)('a' + mc);
fa[mc]--;
}
else
return "-1";
}
last = s[i];
}
return s;
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t = 1;
cin >> t;
while (t--)
{
string x = solve();
cout << x << "\n";
}
return 0;
}