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.io.BufferedReader;
  import java.io.IOException;
  import java.io.InputStreamReader;
  import java.io.PrintWriter;
  import java.util.*;
  
  public class CodeForces {
      static reader input = new reader();
      static PrintWriter output = new PrintWriter(System.out);
  
      public static void main(String[] args) throws IOException {
          /*
          BufferedReader bf = new BufferedReader(new FileReader("input.txt"));
          PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter("output.txt")));
          StringTokenizer stk= new StringTokenizer(bf.readLine());;
          int n=Integer.parseInt(stk.nextToken());
          */
          E();
          output.close();
      }
  
      public static void A(){
  
      }
  
      public static void B(){
  
      }
  
      public static void C(){
  
      }
  
      public static void D(){
  
      }
  
      public static void E(){
          int T=input.nextInt();
          for(int i=0;i<T;i++) {
              String t= input.next();
              HashMap<Character,Integer>count=new HashMap<>();
              HashMap<Character,Integer>index=new HashMap<>();
              int n=t.length();
              for(int j=0;j<n;j++){
                  count.put(t.charAt(j),count.getOrDefault(t.charAt(j),0)+1);
                  index.put(t.charAt(j),j);
              }
              ArrayList<Pair>sorted=new ArrayList<>();
              for(Map.Entry<Character,Integer>x: index.entrySet()){
                  sorted.add(new Pair(x.getKey(),x.getValue()));
              }
              Collections.sort(sorted, Comparator.comparingInt(p -> p.cnt));
              StringBuilder order=new StringBuilder("");
              for(Pair x:sorted)
                  order.append(x.ch);
              int totallen=0;
              for(int j=0;j<sorted.size();j++){
                  totallen+=count.get(sorted.get(j).ch)/(j+1);
              }
              if(totallen>n)
                  output.println(-1);
              else{
                  StringBuilder s=new StringBuilder(t.substring(0,totallen));
                  StringBuilder temp=new StringBuilder("");
                  int ind=0;
                  while (s.length()>0){
                      temp.append(s);
                      StringBuilder stemp=new StringBuilder("");
                      for(int j=0;j<s.length();j++){
                          if(s.charAt(j)!=order.charAt(ind))
                              stemp.append(s.charAt(j));
                      }
                      s=stemp;
                      ind++;
                  }
                  if(temp.toString().equals(t))
                      output.println(t.substring(0,totallen)+" "+order);
                  else
                      output.println(-1);
              }
          }
      }
  
      public static void F(){
  
      }
  
  
  
      public static long factorial(int a){
          long ans=1;
          for(int i=1;i<=a;i++){
              ans*=i;
          }
          return ans;
      }
      public static long LCM(long a,long b){
          return (a*b)/GCD(a,b);
      }
      public static long GCD(long a,long b){
          if(a==0)
              return b;
          else if(b==0)
              return a;
          else
              return GCD(b%a,a);
      }
  
      public static boolean isPrime(long num){
          if(num==1)
              return false;
          else if(num==2||num==3)
              return true;
          else if(num%2==0||num%3==0)
              return false;
          else{
              for(long i=5;i*i<=num;i+=6){
                  if(num%i==0||num%(i+2)==0)
                      return false;
              }
          }
          return true;
      }
  
      public static ArrayList<Integer> SieveofEratothenis(){
          ArrayList<Integer>ans=new ArrayList<>();
          boolean visited[]=new boolean[1000000];
          for(int i=2;i<1000000;i++){
              if(!visited[i]){
                  ans.add(i);
                  for(long j=(long)i*i;j<1000000;j+=i){
                      visited[(int)j]=true;
                  }
              }
          }
          return ans;
      }
  
      public static void mergesort(long arr[],int start,int end){//start and end must be indexes
          if(start<end) {
              int mid=(start+end)/2;
              mergesort(arr,start,mid);
              mergesort(arr, mid+1, end);
              merge(arr, start,mid,end);
          }
      }
      public static void merge(long arr[],int start,int mid,int end){
          int lsize=mid-start+1,rsize=end-mid;
          long l[]=new long[lsize],r[]=new long[rsize];
          for(int i=start;i<=mid;i++){
              l[i-start]=arr[i];
          }
          for(int i=mid+1;i<=end;i++){
              r[i-mid-1]=arr[i];
          }
          int i=0,j=0,k=start;
          while(i<lsize&&j<rsize){
              if(l[i]<=r[j]){
                  arr[k++]=l[i++];
              }else{
                  arr[k++]=r[j++];
              }
          }
          while(i<lsize)
              arr[k++]=l[i++];
          while(j<rsize)
              arr[k++]=r[j++];
      }
  }
  
  class Value{
      int ans;
      Value(int ans)
      {
          this.ans=ans;
      }
  }
  
  class Triple{
      int x,y,z;
      Triple(int x,int y,int z){
          this.x=x;
          this.y=y;
          this.z=z;
      }
  }
  
  class Pair{
      char ch;
      int cnt;
      Pair(char ch,int cnt){
          this.ch=ch;
          this.cnt=cnt;
      }
  }
  
  class Op{
      int op,count;
      char dir;
      public Op(int op){
          this.op=op;
      }
  }
  
  class reader {
      BufferedReader br;
      StringTokenizer st;
  
      public reader() {
          br = new BufferedReader(new
                  InputStreamReader(System.in));
      }
  
      String next() {
          while (st == null || !st.hasMoreElements()) {
              try {
                  st = new StringTokenizer(br.readLine());
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
          return st.nextToken();
      }
  
      int nextInt() {
          return Integer.parseInt(next());
      }
  
      long nextLong() {
          return Long.parseLong(next());
      }
  
      double nextDouble() {
          return Double.parseDouble(next());
      }
  
      String nextLine() {
          String str = "";
          try {
              str = br.readLine();
          } catch (IOException e) {
              e.printStackTrace();
          }
          return str;
      }
  
      public int[] nextIntArray(int arraySize) {
          int array[] = new int[arraySize];
          for (int i = 0; i < arraySize; i++) {
              array[i] = nextInt();
          }
          return array;
      }
  
      public long[] nextLongArray(int arraySize) {
          long array[] = new long[arraySize];
          for (int i = 0; i < arraySize; i++) {
              array[i] = nextLong();
          }
          return array;
      }
  }