#include<bits/stdc++.h>
using namespace std;
const int N = 1e5;
const int Prime = 1e9+7;
const int Base = 251;
//...................................................................//
#define endl '\n'
#define Int long long int
#define gcd(x, y) (__gcd(x, y))
#define lcm(x, y) ((x/gcd(x, y))*y)
#define rand(x, y) rand()%(y-x+1)+x
#define pow2(x) (1<<x)
#define pi 3.141592653589793
#define decimal(x, y) fixed<<setprecision(x)<<y
#define unsync ios_base::sync_with_stdio(0); cin.tie(0);
#define TxtI freopen("input.txt","r",stdin);
#define TxtO freopen("output.txt","w",stdout);
//...................................................................//
int main()
{
//srand(time(0));
//TxtI TxtO
unsync
int t;
cin >> t;
while(t--)
{
Int mx=0;
char mxC;
string s, ans="";
map<char, int> mp;
priority_queue<pair<int, char>> pq;
cin >> s;
for(int i=0; i<s.size(); i++)
{
mp[s[i]]++;
if(mp[s[i]]>mx)
{
mx = mp[s[i]];
mxC = s[i];
}
}
if(s.size()-mp[mxC]<mp[mxC]-1) cout << -1 << endl;
else
{
for(pair<char, int> i : mp) pq.push({i.second, i.first});
while(pq.size())
{
pair<int, char> a = pq.top();
pair<int, char> b;
pq.pop();
ans += a.second;
if(pq.size()>0)
{
b = pq.top();
ans += b.second;
pq.pop();
if(b.first-1>0) pq.push({b.first-1, b.second});
}
if(a.first-1>0) pq.push({a.first-1, a.second});
}
for(int i=ans.size()-1; i>=0; i--) cout << ans[i];
cout << endl;
}
}
}