#include <bits/stdc++.h>
using namespace std;
template <typename A>
ostream &operator<<(ostream &cout, vector<A> const &v);
template <typename A, typename B>
ostream &operator<<(ostream &cout, pair<A, B> const &p) {
  return cout << '(' << p.f << ',' << ' ' << p.s << ')';
}
template <typename A>
ostream &operator<<(ostream &cout, vector<A> const &v) {
  cout << '[';
  for (int i = 0; i < v.size(); i++) {
    if (i) cout << ',';
    cout << v[i];
  }
  return cout << ']' << endl;
}
const long long mod = 1000000007;
string removed(string &s, char c) {
  string t = "";
  for (int i = 0; i < ((int)s.size()); i++) {
    if (s[i] != c) {
      t.push_back(s[i]);
    }
  }
  return t;
}
void solve() {
  string s;
  cin >> s;
  int n = ((int)s.size());
  set<int> st;
  vector<char> ord;
  for (int i = n - 1; i >= 0; i--) {
    if (!st.count(s[i] - 'a')) {
      st.insert(s[i] - 'a');
      ord.push_back(s[i]);
    }
  }
  reverse(ord.begin(), ord.end());
  map<int, int> mp;
  for (int i = 0; i < n; i++) {
    mp[s[i] - 'a']++;
  }
  map<int, int> mp2, mp3;
  for (int i = 0; i < ((int)ord.size()); i++) {
    mp2[ord[i] - 'a'] = mp[ord[i] - 'a'] / (i + 1);
    if (mp[ord[i] - 'a'] % (i + 1)) {
      cout << "-1\n";
      return;
    }
  }
  int len = n + 1;
  for (int i = 0; i < n; i++) {
    mp3[s[i] - 'a']++;
    if (mp3 == mp2) {
      len = i + 1;
      break;
    }
  }
  if (len == n + 1) {
    cout << "-1\n";
    return;
  }
  string t = s.substr(0, len);
  string ans = t;
  for (int i = 0; i < ((int)ord.size()); i++) {
    t = removed(t, ord[i]);
    ans += t;
  }
  if (ans == s) {
    cout << s.substr(0, len) << " ";
    for (int i = 0; i < ((int)ord.size()); i++) {
      cout << ord[i];
    }
    cout << "\n";
  } else {
    cout << "-1\n";
  }
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int tc = 1;
  cin >> tc;
  while (tc--) {
    solve();
  }
  return 0;
}
