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: import java.util.*;
  import java.io.*;
  
  public class E
  {
      static InputReader in=new InputReader(System.in);
      static OutputWriter out=new OutputWriter(System.out);
      static StringBuilder sb=new StringBuilder();
      static long MOD = (long)(998244353);
  
      // Main Class Starts Here
      public static void main(String args[])throws IOException
      {
          int t = in();
          while(t-->0) {
              String str = sn();
              char a[] = str.toCharArray();
              Set<Character> set = new HashSet<>();
              for(char x: a) set.add(x);
  
              int d = set.size(); // distinct chars.
              int n = a.length;
  
              // occurrence mapping.
              HashMap<Character, Integer> occr = new HashMap<>();
              for(int i = 0 ;i < n; i++){
                  int occurrence = occr.getOrDefault(a[i], 0);
                  occr.put(a[i], ++occurrence);
              }
  
              // prln("Occr in t : "+occr+" distinct chars : "+d);
  
              boolean isNotPossible = false;
              HashMap<Character, Integer> map = new HashMap<>();
              Stack<Character> stack = new Stack<>();
              int  i = n-1;
              while(i >= 0){
                  if(!map.containsKey(a[i])){
                      // first entry.
                      stack.push(a[i]);
                      // find the freq
                      int freq = occr.get(a[i]);
                      if(freq % (d - map.size()) != 0){
                          isNotPossible = true;
                          break;
                      }
                      int actualFreq = freq / (d - map.size());
                      // prln("Char : "+a[i]+" , freq : "+freq+" , actual freq : "+actualFreq);
                      map.put(a[i], actualFreq);
                      int temp = actualFreq - 1; // cutting this occurrence.
                      char cur = a[i];
                      i--;
                      while(i >= 0 && temp > 0){
                          if(a[i] == cur){
                              temp--;
                          }
                          i--;
                      }
                  }
                  else{
                      i--;
                  }
              }
  
              // prln("Occr in s : "+map+"\nStack : "+stack);
              if(isNotPossible){
                  app(-1+"\n");
              }
              else{
                  if(stack.size() != d){
                      app(-1+"\n");
                  }
                  else{
                      // check final possibility.
                      int sum = 0;
                      for(int x: map.values()){
                          sum += x;
                      }
                      if(!isFinallyPossible(str, str.substring(0, sum), (Stack<Character>) stack.clone(), map)){
                          app(-1+"\n");
                          continue;
                      }
                      app(str.substring(0, sum)+" ");
                      while(!stack.isEmpty()){
                          app(stack.pop());
                      }
                      app("\n");
                  }
  
              }
          }
          out.printLine(sb);
          out.close();
      }
  
      public static boolean isFinallyPossible(String str, String actual, Stack<Character> stack, HashMap<Character, Integer> map){
          String temp = actual;
          StringBuilder stringBuilder = new StringBuilder(actual);
          while(!stack.isEmpty()){
              char cur = stack.pop();
              temp = temp.replace(""+cur, "");
              stringBuilder.append(temp);
          }
          return stringBuilder.toString().equals(str);
      }
  
      static class DisjointSet{
          int par[];
          int rank[];
          int n;
          public DisjointSet(int n){
              this.n = n;
              par = new int[n];
              rank = new int[n];
              for(int i = 0; i < n; i++){
                  par[i] = i;
              }
          }
  
          public int findPar(int i){
              // path compression.
              if(par[i] != i){
                  par[i] = findPar(par[i]);
              }
              return par[i];
          }
  
          public int merge(int x, int y){
              int parX = findPar(x);
              int parY = findPar(y);
              if(parX == parY) return 0; // no decrease in connected components
              if(rank[parX] > rank[parY]){
                  // merge y to x.
                  par[parY] = parX;
              }
              else if(rank[parY] > rank[parX]){
                  par[parX] = parY;
              }
              else{
                  par[parY] = parX;
                  rank[parX]++;
              }
              return 1; // after merging the decrease in connected components is 1.
          }
      }
  
      public static class Edge{
          int from;
          int to;
          int id;
          boolean visited;
          public Edge(int from, int to, int id){
              this.from = from;
              this.to = to;
              this.id =id;
              this.visited = false;
          }
      }
  
      public static int[] an(int n) {
          int ar[]=new int[n];
          for(int i=0;i<n;i++)
              ar[i]=in();
          return ar;
      }
  
      public static long[] lan(int n) {
          long ar[]=new long[n];
          for(int i=0;i<n;i++)
              ar[i]=lin();
          return ar;
      }
  
      public static String atos(Object ar[]) {
          return Arrays.toString(ar);
      }
  
      public static int in() {
          return in.readInt();
      }
  
      public static long lin() {
          return in.readLong();
      }
  
      public static String sn() {
          return in.readString();
      }
  
      public static void prln(Object o) {
          out.printLine(o);
      }
  
      public static void prn(Object o) {
          out.print(o);
      }
  
      public static void display(int a[]) {
          out.printLine(Arrays.toString(a));
      }
  
      public static HashMap<Integer,Integer> hm(int a[]){
          HashMap<Integer,Integer> map=new HashMap<>();
          for(int i=0; i < a.length;i++) {
              int keep = (int)map.getOrDefault(a[i],0);
              map.put(a[i],++keep);
          }
          return map;
      }
  
      public static void app(Object o) {
          sb.append(o);
      }
  
      public static long calcManhattanDist(int x1,int y1,int x2,int y2) {
          long xa = Math.abs(x1-x2);
          long ya = Math.abs(y1-y2);
          return (xa+ya);
      }
  
  
      static class InputReader {
          private InputStream stream;
          private byte[] buf = new byte[1024];
          private int curChar;
          private int numChars;
          private SpaceCharFilter filter;
  
          public InputReader(InputStream stream) {
              this.stream = stream;
          }
  
          public int read() {
              if (numChars == -1)
                  throw new InputMismatchException();
              if (curChar >= numChars) {
                  curChar = 0;
                  try {
                      numChars = stream.read(buf);
                  } catch (IOException e) {
                      throw new InputMismatchException();
                  }
                  if (numChars <= 0)
                      return -1;
              }
              return buf[curChar++];
          }
  
          public int readInt() {
              int c = read();
              while (isSpaceChar(c))
                  c = read();
              int sgn = 1;
              if (c == '-') {
                  sgn = -1;
                  c = read();
              }
              int res = 0;
              do {
                  if (c < '0' || c > '9')
                      throw new InputMismatchException();
                  res *= 10;
                  res += c - '0';
                  c = read();
              } while (!isSpaceChar(c));
              return res * sgn;
          }
  
          public long readLong() {
              int c = read();
              while (isSpaceChar(c))
                  c = read();
              int sgn = 1;
              if (c == '-') {
                  sgn = -1;
                  c = read();
              }
              long res = 0;
              do {
                  if (c < '0' || c > '9')
                      throw new InputMismatchException();
                  res *= 10;
                  res += c - '0';
                  c = read();
              } while (!isSpaceChar(c));
              return res * sgn;
          }
  
          public String readString() {
              int c = read();
              while (isSpaceChar(c))
                  c = read();
              StringBuilder res = new StringBuilder();
              do {
                  res.appendCodePoint(c);
                  c = read();
              } while (!isSpaceChar(c));
              return res.toString();
          }
  
          public boolean isSpaceChar(int c) {
              if (filter != null)
                  return filter.isSpaceChar(c);
              return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
          }
  
          public String next() {
              return readString();
          }
  
          public interface SpaceCharFilter {
              public boolean isSpaceChar(int ch);
          }
      }
  
      static class OutputWriter {
          private final PrintWriter writer;
  
          public OutputWriter(OutputStream outputStream) {
              writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
          }
  
          public OutputWriter(Writer writer) {
              this.writer = new PrintWriter(writer);
          }
  
          public void print(Object...objects) {
              for (int i = 0; i < objects.length; i++) {
                  if (i != 0)
                      writer.print(' ');
                  writer.print(objects[i]);
              }
          }
  
          public void printLine(Object...objects) {
              print(objects);
              writer.println();
          }
  
          public void close() {
              writer.close();
          }
      }
  }