#include <bits/stdc++.h> // All praise is due to Allah alone, and peace and blessings be
using namespace std; // upon him, after whom there is no other Prophet.
int32_t main() {
cin.tie(0)->sync_with_stdio(false);
function<void()> Test_Case = [&]() {
string s; cin >> s;
int n = s.size();
map<char, int> m;
for(const char c : s) {
m[c]++;
}
vector<pair<int, char>> ar;
for(auto [a, b] : m) {
ar.emplace_back(b, a);
}
sort(ar.begin(), ar.end());
if(ar.back().first > (n + 1) / 2) {
cout << "-1\n"; return;
}
for(int i = 0; i < n; i++) {
s[i] = '*';
}
for(int i = 0, k = ar.size() - 1; i < n and k >= 0; i++) {
if(s[i] == '*') {
int j = i;
while(ar[k].first > 0 and j < n) {
if(s[j] == '*') {
s[j] = ar[k].second;
ar[k].first--;
j += 2;
}
}
if(ar[k].first == 0) k--;
}
}
cout << s << '\n';
};
int32_t Case = 1; cin >> Case;
for (int T = 1; T <= Case; T++) {
Test_Case();
}
return 0;
}