#include <bits/stdc++.h>
using namespace std;
int main(int argc, const char* argv[]) {
  int t;
  scanf("%d", &t);
  while (t--) {
    bool found = false;
    string str;
    cin >> str;
    if (str.size() == 1) {
      cout << -1 << endl;
      continue;
    } else if (str.size() == 2) {
      if (str[0] == str[1]) {
        cout << -1 << endl;
        continue;
      } else {
        cout << str << endl;
        continue;
      }
    } else {
      if (str[0] != str[str.length() - 1]) {
        cout << str << endl;
        continue;
      } else {
        for (int i = 1; i < str.length(); i++) {
          if (str[i] != str[0]) {
            str[str.length() - 1] = str[i];
            str[i] = str[0];
            found = true;
          }
          if (found) {
            cout << str << endl;
            break;
          }
        }
      }
    }
    if (!found) cout << -1 << endl;
  }
  return 0;
}
