#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
const int maxN = 1e6 + 1;
const int mod = 1e9 + 7;
const ll oo = 1e18;
string t;
inline void FastInput() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
}
void ReadInput() { cin >> t; }
void Solve() {
  string s, res;
  map<char, int> mp;
  map<char, vector<int>> vc;
  for (int i = 0; i < t.size(); i++) vc[t[i]].push_back(i + 1);
  for (int i = t.size() - 1; i >= 0; i--) {
    if (!mp[t[i]]) res.push_back(t[i]);
    mp[t[i]]++;
  }
  reverse(res.begin(), res.end());
  int l = 0, i = 1;
  for (char c : res) {
    if (mp[c] % i) {
      cout << -1 << '\n';
      return;
    }
    l = max(l, vc[c][mp[c] / i - 1]);
    i++;
  }
  s = t.substr(0, l);
  map<char, int> del;
  int pos = 0, j = 0;
  for (char c : t) {
    while (del[s[pos]]) pos++;
    if (pos == s.size()) {
      pos = 0;
      del[res[j]] = 1;
      j++;
    }
    while (del[s[pos]]) pos++;
    if (c != s[pos]) {
      cout << -1 << '\n';
      return;
    }
    pos++;
    if (pos == s.size()) {
      pos = 0;
      del[res[j]] = 1;
      j++;
    }
  }
  while (pos < s.size() && del[s[pos]]) pos++;
  if (pos < s.size()) {
    cout << -1 << '\n';
    return;
  }
  cout << s << " " << res << '\n';
}
int main() {
  FastInput();
  int test;
  cin >> test;
  while (test--) {
    ReadInput();
    Solve();
  }
}
