#include <bits/stdc++.h>
using namespace std;
unsigned long long power(unsigned long long a, unsigned long long p,
                         unsigned long long mod = 1e9 + 7) {
  unsigned long long res = 1, run = p % mod;
  while (p > 0) {
    if (p & 1) {
      res = (res * run) % mod;
    }
    p = (p >> 1);
    run = (run * run) % mod;
  }
  return res;
}
unsigned long long inverse(unsigned long long a,
                           unsigned long long mod = 1e9 + 7) {
  return power(a, mod - 2, mod);
}
unsigned long long gcd(unsigned long long a, unsigned long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
void pre() {}
void solve() {
  string t;
  cin >> t;
  long long m = t.length();
  vector<int> cnt(26, 0);
  string order;
  for (long long i = m - 1; i >= 0; i--) {
    cnt[t[i] - 'a']++;
    if (cnt[t[i] - 'a'] == 1) {
      order += t[i];
    }
  }
  long long nc = order.length();
  long long n = 0;
  for (long long i = 0; i < nc; i++) {
    long long sc = nc - i;
    long long chr = order[i] - 'a';
    if (cnt[chr] % sc != 0 || cnt[chr] < sc) {
      cout << -1 << endl;
      return;
    } else {
      n += cnt[chr] / sc;
    }
  }
  string seg, s = t.substr(0, n);
  seg = s;
  long long l = 0;
  for (long long i = nc - 1; i >= 0; i--) {
    if (t.substr(l, seg.size()) != seg) {
      cout << -1 << endl;
      return;
    }
    l += seg.size();
    string nseg;
    for (auto c : seg) {
      if (c != order[i]) nseg += c;
    }
    seg = nseg;
  }
  order = string(order.rbegin(), order.rend());
  cout << t.substr(0, n) << " " << order << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t = 1;
  cin >> t;
  pre();
  while (t--) {
    solve();
  }
}
