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 com.company;
  
  import java.util.*;
  import java.io.*;
  
  public class Main {
  
      static Boolean less,greater,flg2;
      static ArrayList<Character> order=new ArrayList<>();
  
      public static void predicate(String t,int idx){
          var old = new HashMap<Character,Integer>();
          for(int i=0;i<=idx;i++){
              if(old.get(t.charAt(i))!=null){
                  old.put(t.charAt(i),old.get(t.charAt(i)) + 1 );
              }
              else old.put(t.charAt(i),1);
          }
          StringBuilder ans=new StringBuilder();
          var blacklist = new HashMap<Character,Integer>();
          for(int i=0;i<=idx;i++) ans.append(t.charAt(i));
        //  ArrayList<Character> order = new ArrayList<>();
       //   order=new ArrayList<>();
       //   order.clear();
          int id =0;
          while(true){
              if(id>=order.size()) break;
  //            var nw = new TreeMap<Character,Integer>();
  //            for(int i=ans.length();i<=Math.min(idx+ans.length(),t.length()-1);i++){
  //                if(nw.get(t.charAt(i))!=null){
  //                    nw.put(t.charAt(i),nw.get(t.charAt(i)) + 1 );
  //                }
  //                else nw.put(t.charAt(i),1);
  //            }
              // find character in old not present in new
              char c=order.get(id);
              id++;
  //            for(var v : old.keySet()){
  //                if(nw.get((v))==null && blacklist.get(v)==null){
  //                    c = v;
  //                    break;
  //                }
  //            }
            //  assert(c!='0');
              if(c!='0') {
                 // order.add(c);
                  blacklist.put(c, 1);
                  for (int i = 0; i <= idx; i++) {
                      if (blacklist.get(t.charAt(i)) == null) ans.append(t.charAt(i));
                  }
              }
  //            for(var v: nw.keySet()){
  //                old.put(v,1);
  //            }
  
              if(c=='0') break;
  
          }
          less=false; greater=false;
          flg2=false;
        //  Boolean flg1,flg2=false;
          if(ans.toString().compareTo(t)==0) flg2=true;
          if(ans.length()<=t.length()) less=true;
          else if(ans.length()>t.length()) greater=true;
  //        else flg1=false;
  
         // return new pair<pair<Boolean,Boolean>,ArrayList<Character>>(new pair<>(flg1,flg2) , order);
  
      }
  
      public static void main(String[] args) throws Exception {
          long start=System.currentTimeMillis();
          FastScanner fs=new FastScanner();
          int T=1; T=fs.nextInt();
          int idx=1;
          boolean dbgflg=false;
        //  if(T==10000) dbgflg=true;
          while(T--!=0) {
              order.clear();
             String t = fs.next();
             int lo =0,hi = t.length()-1;
             int ans = -1;
             //first of all i must fix the order lel , the most crucial observwtion iun this ques
              var st = new HashSet<Character>();
              for(int i=t.length()-1;i>=0;i--){
                  if(st.contains(t.charAt(i))==false){
                      order.add(t.charAt(i));
                      st.add(t.charAt(i));
                  }
              }
              Collections.reverse(order);
              int cntr=0;
             while(lo<=hi){
                 if(cntr>64) throw new Exception();
                 int mid = (lo+hi)/2;
                // pair<Boolean,Boolean> pp =
                 predicate(t,mid);
                 if(less == true) lo = mid+1;
                 else if(greater == true )hi = mid - 1;
  
                 if(flg2 == true ) {
                     ans = mid;
                     break;
                 }
                 
                 cntr++;
             }
             if(dbgflg==false) {
                 if (flg2 == true) {
                     StringBuilder fnl = new StringBuilder();
                     for (int i = 0; i <= ans; i++) fnl.append(t.charAt(i));
                     System.out.print(fnl.toString() + " ");
  //               System.out.println(order.toString());
                     for (var v : order) {
                         if (v != '0')
                             System.out.print(v);
                     }
                     System.out.println();
                 } else System.out.println("-1");
             }
             else if(dbgflg==true && idx==1975){
                 System.out.println(t);
             }
  
             idx++;
          }
  //         long end=(System.currentTimeMillis()-start);
  //         System.err.println("Time taken is "+end+" ms");
      }
  
  
  
  
      public static long binexp(long a, long b,long md){
          if(b==0) return 1;
          if(b==1) return a%md;
          long xx=binexp(a,b/2,md);
          if(b%2==0){
              return (xx%md * xx%md)%md;
          }
          else {
              return (xx%md * xx%md * a)%md;
          }
      }
  
  
      public static int gcd(int a,int b) {
          if (b == 0) return a;
          if (a == 0) return b;
          if (a > b) return gcd(b, a);
          return gcd(a, b % a);
  
      }
  
  
      @Override
      protected Object clone() throws CloneNotSupportedException {
          return super.clone();
      }
  
      static void sort(int[] a) {
          ArrayList<Integer> l=new ArrayList<>();
          for (int i:a) l.add(i);
          Collections.sort(l);
          for (int i=0; i<a.length; i++) a[i]=l.get(i);
      }
  
  
      static class FastScanner {
          BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
          StringTokenizer st=new StringTokenizer("");
          String next() {
              while (!st.hasMoreTokens())
                  try {
                      st=new StringTokenizer(br.readLine());
                  } catch (IOException e) {
                      e.printStackTrace();
                  }
              return st.nextToken();
          }
  
          int nextInt() {
              return Integer.parseInt(next());
          }
  
          double nextDouble() { return Double.parseDouble(next()); }
  
          int[] readArray(int n) {
              int[] a=new int[n];
              for (int i=0; i<n; i++) a[i]=nextInt();
              return a;
          }
          long nextLong() {
              return Long.parseLong(next());
          }
  
      }
      static class pair<t1 extends Comparable<t1>, t2 extends Comparable<t2> > implements Comparable<pair<t1,t2>>{
          public t1 ff;
          public t2 ss;
          pair(){}
          pair(t1 first,t2 second){
              this.ff=first;
              this.ss=second;
          }
  
          @Override
          public boolean equals(Object obj) {
              if(obj==null) return false;
              else if(obj.getClass()!=this.getClass()) return false;
              pair<?,?> pp = (pair<?,?>) obj;
              return pp.ff.equals(this.ff) && pp.ss.equals(this.ss);
          }
  
          @Override
          public int hashCode() {
              return Objects.hash(ff,ss);
              //return 31 * ff.hashCode() + ss.hashCode();
          }
  
          @Override
          public int compareTo(pair<t1,t2> pp) {
              pair<?,?> p = (pair<?,?>) pp;
              var res = this.ff.compareTo(pp.ff);
              if(res==0) res=this.ss.compareTo(pp.ss);
  
              return res;
          }
      }
  }