#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0, fl = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') fl = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * fl;
}
const int N = 500010, M = 30, mod = 1e9 + 7;
int n, m, k, top, tt;
int st[M], cnt[M], la[M], id[M];
string s, t, str;
bool f[M];
bool solve() {
  cin >> t;
  k = t.length();
  memset(st, 0, sizeof st);
  memset(cnt, 0, sizeof cnt);
  memset(la, 0, sizeof la);
  for (int i = 0; i < k; i++) {
    int c = t[i] - 'a';
    st[c] = 1;
    cnt[c]++;
    la[c] = i;
  }
  vector<pair<long long, long long> > res;
  for (int i = 0; i < 26; i++) {
    if (st[i]) {
      res.push_back({la[i], i});
    }
  }
  sort(res.begin(), res.end());
  int idx = 1;
  for (auto p : res) {
    id[p.second] = idx++;
  }
  for (int i = 0; i < 26; i++) {
    if (st[i]) {
      if (cnt[i] % id[i] != 0) return 1;
      cnt[i] /= id[i];
    }
  }
  int cot = res.size();
  s = "";
  for (int i = 0; i < k; i++) {
    int c = t[i] - 'a';
    if (cnt[c] == 0) return 1;
    cnt[c]--;
    s += t[i];
    if (cnt[c] == 0) cot--;
    if (cot == 0) break;
  }
  str = "" + s;
  memset(f, 0, sizeof f);
  for (auto p : res) {
    int c = p.second;
    f[c] = 1;
    for (auto ch : s) {
      if (!f[ch - 'a']) str += ch;
    }
  }
  if (str != t) return 1;
  cout << s << " ";
  for (auto p : res) {
    printf("%c", p.second + 'a');
  }
  cout << endl;
  return 0;
}
int main() {
  tt = read();
  while (tt--) {
    if (solve()) puts("-1");
  }
  return 0;
}
