#include <bits/stdc++.h>
using namespace std;
long long ceile(long long &a, long long &b) { return (a / b) + ((a % b) != 0); }
class Graph {
 public:
  long long V;
  vector<vector<long long>> adj;
  Graph(long long V) {
    this->V = V;
    adj.resize(V, vector<long long>(0));
  }
  void addEdge(long long u, long long v) { adj[u].push_back(v); }
  bool DFS(long long s, long long V) {
    vector<bool> vis(V, 0);
    stack<long long> stack;
    stack.push(s);
    long long ans = 0;
    while (!stack.empty()) {
      s = stack.top();
      stack.pop();
      if (!vis[s]) {
        ans++;
        vis[s] = true;
      }
      for (auto i = adj[s].begin(); i != adj[s].end(); ++i)
        if (!vis[*i]) stack.push(*i);
    }
    return ans == V;
  }
};
class numpy {
 public:
  vector<long long> argsort(vector<long long> &vec) {
    vector<pair<long long, long long>> v;
    long long n = vec.size();
    for (long long(i) = (0); (i) < (n); ++(i)) v.push_back({vec[i], i});
    sort(v.begin(), v.end());
    vector<long long> ans;
    for (long long(i) = (0); (i) < (n); ++(i)) ans.push_back(v[i].second);
    return ans;
  }
  long long argmax(vector<long long> &vec) {
    return (max_element(vec.begin(), vec.end()) - vec.begin());
  }
};
int32_t main() {
  long long t;
  cin >> t;
  numpy np;
tester:
  while (t--) {
    string s;
    cin >> s;
    unordered_map<char, long long> ust;
    for (auto &c : s) ust[c]++;
    if (ust.size() == 1)
      cout << "-1\n";
    else {
      for (auto &c : ust) {
        string temp(c.second, c.first);
        cout << temp;
      }
      cout << "\n";
    }
  }
}
