#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define all(x) (x).begin(), (x).end()
#define f(i, n) for (int i = 0; i < n; i++)
#define trace(x) cerr << #x << ": " << x << '\n'
bool check(vector<int> &cnt, int rem)
{
int mx = 0;
for (int v : cnt)
mx = max(mx, v);
return mx <= (rem + 1) / 2;
}
void solve(string s)
{
int n = s.size();
vector<int> cnt(26, 0);
for (char ch : s)
cnt[ch - 'a']++;
if (!check(cnt, n))
{
cout << "-1\n";
return;
}
string res;
res.reserve(n);
int prev = -1;
for (int pos = 0; pos < n; pos++)
{
bool ok = false;
for (int c = 0; c < 26; c++)
{
if (cnt[c] == 0 or c == prev)
continue;
cnt[c]--;
if (check(cnt, n - pos - 1))
{
res.push_back(char('a' + c));
prev = c;
ok = true;
break;
}
cnt[c]++;
}
if (!ok)
break;
}
if (res.size() < n)
cout << "-1\n";
else
cout << res << '\n';
}
int32_t main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--)
{
string s;
cin >> s;
solve(s);
}
return 0;
}