description: Polycarp has a string s. Polycarp performs the following actions until the string s is empty (t is initially an empty string):
  
    * he adds to the right to the string t the string s, i.e. he does t = t + s, where t + s is a concatenation of the strings t and s; 
    * he selects an arbitrary letter of s and removes from s all its occurrences (the selected letter must occur in the string s at the moment of performing this action). 
  
  
  
  Polycarp performs this sequence of actions strictly in this order.
  
  Note that after Polycarp finishes the actions, the string s will be empty and the string t will be equal to some value (that is undefined and depends on the order of removing).
  
  E.g. consider s="abacaba" so the actions may be performed as follows:
  
    * t="abacaba", the letter 'b' is selected, then s="aacaa"; 
    * t="abacabaaacaa", the letter 'a' is selected, then s="c"; 
    * t="abacabaaacaac", the letter 'c' is selected, then s="" (the empty string). 
  
  
  
  You need to restore the initial value of the string s using only the final value of t and find the order of removing letters from s.
  
  Input
  
  The first line contains one integer T (1 ≤ T ≤ 10^4) — the number of test cases. Then T test cases follow.
  
  Each test case contains one string t consisting of lowercase letters of the Latin alphabet. The length of t doesn't exceed 5 ⋅ 10^5. The sum of lengths of all strings t in the test cases doesn't exceed 5 ⋅ 10^5.
  
  Output
  
  For each test case output in a separate line:
  
    * -1, if the answer doesn't exist; 
    * two strings separated by spaces. The first one must contain a possible initial value of s. The second one must contain a sequence of letters — it's in what order one needs to remove letters from s to make the string t. E.g. if the string "bac" is outputted, then, first, all occurrences of the letter 'b' were deleted, then all occurrences of 'a', and then, finally, all occurrences of 'c'. If there are multiple solutions, print any one. 
  
  Example
  
  Input
  
  
  7
  abacabaaacaac
  nowyouknowthat
  polycarppoycarppoyarppyarppyrpprppp
  isi
  everywherevrywhrvryhrvrhrvhv
  haaha
  qweqeewew
  
  
  Output
  
  
  abacaba bac
  -1
  polycarp lcoayrp
  is si
  everywhere ewyrhv
  -1
  -1
  
  Note
  
  The first test case is considered in the statement.
solution: //package codeforce.div3.r739;
  
  import java.io.BufferedReader;
  import java.io.File;
  import java.io.FileNotFoundException;
  import java.io.FileReader;
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.InputStreamReader;
  import java.io.PrintWriter;
  import java.util.Collections;
  import java.util.LinkedList;
  import java.util.Scanner;
  import java.util.StringTokenizer;
  import java.util.stream.Collectors;
  import java.util.stream.IntStream;
  import java.util.ArrayList;
  import java.util.List;
  import java.util.HashMap;
  import java.util.Map;
  import java.util.Set;
  import java.util.HashSet;
  
  import static java.lang.System.out;
  import static java.util.stream.Collectors.joining;
  
  
  /**
   * @author pribic (Priyank Doshi)
   * @see <a href="https://codeforces.com/contest/1560/problem/E" target="_top">https://codeforces.com/contest/1560/problem/E</a>
   * @since 19/08/21 3:44 PM
   */
  public class E {
    static FastScanner sc = new FastScanner(System.in);
  
    public static void main(String[] args) {
      try (PrintWriter out = new PrintWriter(System.out)) {
        int T = sc.nextInt();
        for (int tt = 1; tt <= T; tt++) {
          String str = sc.next();
          String order = "";
          Set<Character> seen = new HashSet<>();
          int[] totalFreq = new int[26];
          for (int i = str.length() - 1; i >= 0; i--) {
            char ch = str.charAt(i);
            if (!seen.contains(ch)) {
              order = ch + order;
              seen.add(ch);
            }
            totalFreq[ch - 'a']++;
          }
          int[] freqInSlot = new int[26];
          boolean valid = true;
          for (int i = order.length() - 1; i >= 0; i--) {
            char ch = order.charAt(i);
            if (totalFreq[ch - 'a'] % (i + 1) != 0)
              valid = false;
            freqInSlot[ch - 'a'] = totalFreq[ch - 'a'] / (i + 1);
          }
          StringBuilder s = new StringBuilder();
          for (char c : str.toCharArray()) {
            if (freqInSlot[c - 'a'] > 0) {
              s.append(c);
              freqInSlot[c - 'a']--;
            } else {
              break;
            }
          }
          if (valid)
            valid = generate(s.toString(), order, str);
          //
          System.out.println(valid ? s + " " + order : -1);
        }
      }
    }
  
    private static boolean generate(String s, String order, String str) {
      StringBuilder t = new StringBuilder();
      for (int i = 0; i < order.length(); i++) {
        t.append(s);
        //out.println(t);
        s = s.replace(order.charAt(i) + "", "");
  
      }
      /*out.println("==");
      out.println(t + " " + str);
      out.println("==");*/
      return t.toString().equals(str);
    }
    
    /*
    polycarppoycarppoyarppyarppyrpprppp
    
    polycarppoycarppoyarppya | rppy | rppr | ppp
    
    we wont to find the split of given string t so that the first split will be original string
    
    obs: do we need to find all the splits or just the point where first split happens? ideally the first one is only needed but is it
    possible to find just first without not worrying about rest of the splits?
    
    last character would appear in all the slots - so freq of last char in each slot is total freq / slots. how many slots do we have but? it is same as 
    length of distinct characters
    
    what about second last char, it appears in slots - 1 , so we will do total freq / slots - 1
    this way we will find frequency of each letter in each slot
    as we know first slot will have all of them, we keep building first slot from left to right untill all the frequencies are exhausted
    
    
    --
    
    qweqeewew
    
    qweqe | ewe | w
     */
  
    static class FastScanner {
      BufferedReader br;
      StringTokenizer st;
  
      public FastScanner(File f) {
        try {
          br = new BufferedReader(new FileReader(f));
        } catch (FileNotFoundException e) {
          e.printStackTrace();
        }
      }
  
      public FastScanner(InputStream f) {
        br = new BufferedReader(new InputStreamReader(f), 32768);
      }
  
      String next() {
        while (st == null || !st.hasMoreTokens()) {
          String s = null;
          try {
            s = br.readLine();
          } catch (IOException e) {
            e.printStackTrace();
          }
          if (s == null)
            return null;
          st = new StringTokenizer(s);
        }
        return st.nextToken();
      }
  
      boolean hasMoreTokens() {
        while (st == null || !st.hasMoreTokens()) {
          String s = null;
          try {
            s = br.readLine();
          } catch (IOException e) {
            e.printStackTrace();
          }
          if (s == null)
            return false;
          st = new StringTokenizer(s);
        }
        return true;
      }
  
      int nextInt() {
        return Integer.parseInt(next());
      }
  
      long nextLong() {
        return Long.parseLong(next());
      }
  
      double nextDouble() {
        return Double.parseDouble(next());
      }
    }
  }