#include <bits/stdc++.h>
using namespace std;
void solve() {
  vector<int> used(26, 0);
  vector<char> ltr;
  string s;
  cin >> s;
  int n = s.size();
  for (long long i = (n)-1; i >= (0); --i) {
    if (!used[s[i] - 'a']) {
      ltr.push_back(s[i]);
    }
    used[s[i] - 'a']++;
  }
  int cnt = ltr.size();
  reverse((ltr).begin(), (ltr).end());
  for (long long i = (0); i < (cnt); ++i) {
    if (used[ltr[i] - 'a'] % (i + 1) != 0) {
      cout << -1 << endl;
      return;
    }
    used[ltr[i] - 'a'] /= (i + 1);
  }
  string resStr = "";
  for (auto& c : s) {
    if (used[c - 'a']) {
      used[c - 'a']--;
      resStr += c;
    }
  }
  vector<int> emitUsed(26, 0);
  string emitStr = resStr;
  for (auto& c : ltr) {
    emitUsed[c - 'a']++;
    for (auto& c2 : resStr) {
      if (!emitUsed[c2 - 'a']) emitStr += c2;
    }
  }
  if (emitStr == s) {
    cout << resStr << ' ';
    for (auto& c : ltr) cout << c;
    cout << endl;
  } else {
    cout << -1 << endl;
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int t;
  cin >> t;
  for (long long _ = (0); _ < (t); ++_) {
    solve();
  }
}
