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.IOException;
  import java.io.InputStreamReader;
  import java.util.*;
  public class Main{
      static int mod=(int)1e9+9;
      static boolean isPerfectSquare(long x)
      {
          if (x >= 0) {
             
              // Find floating point value of
              // square root of x.
              long sr = (long)Math.sqrt(x);
             
              // if product of square root
              // is equal, then
              // return T/F
   
              return ((sr * sr) == x);
          }
          return false;
      }
         public static void main(String args[]){
                FastScanner in=new FastScanner();
                int test=in.nextInt();
                while(test-->0){
                    int count[]=new int[26];
                    String t=in.next();
                    for(int i=0;i<t.length();i++)
                        count[t.charAt(i)-'a']++;
                    
                    int total=0;
                    for(int i=0;i<26;i++){
                        if(count[i]!=0)
                            total++;
                    }
                    int check[]=new int[26];
                    
                    int k=total;
                    StringBuilder sb=new StringBuilder();
                    for(int j=t.length()-1;j>=0;j--){
                        if(check[t.charAt(j)-'a']==0){
                            sb.append(t.charAt(j));
                            check[t.charAt(j)-'a']=k;
                            k--;
                        }
                    }
                    int len=0;
                    boolean flag=true;
                    for(int i=0;i<26;i++){
                        if(check[i]!=0){
                            if(count[i]%check[i]==0)
                            len+=count[i]/check[i];
                            else{
                                flag=false;
                                break;
                            }
                        }
                    }
                    if(!flag)
                        System.out.println(-1);
                    else{
                        String s=t.substring(0,len);
                        String str=s;
                        String order=sb.reverse().toString();
                       for(int i=0;i<order.length() && s.length()!=0;i++){
                           char ch=order.charAt(i);
                           s=s.replaceAll(String.valueOf(ch),"");
                           str=str.concat(s);
                       }
                       if(str.equals(t))
                        System.out.println(t.substring(0,len)+" "+order);
                       else
                           System.out.println(-1);
                    }
                }
                }
                
         public static int dfs(int n,int node,ArrayList<Pair> arr[],boolean visited[],int sum){
            visited[node]=true;
            if(node==n-1)
                return sum;
                
            int max=Integer.MIN_VALUE;
            for(Pair i:arr[node]){
                int ans=0;
                if(!visited[i.x])
                   ans=dfs(n,i.x,arr,visited,sum+i.y);
                
                max=Math.max(ans,max);
            }
             return max;
         }
         public static void factor(long n,HashSet<Long> set){
             for(long i=2;i*i<=n;i++){
                 if(n%i==0){
                     set.add(i);
                     while(n%i==0){
                         n=n/i;
                     }
                 }
             }
             if(n!=0 && n!=1)
                 set.add(n);
         }
         public static int bakchodi(int arr[],int dp[][],int n,int turn,int index){
             if(index>=n)
                 return 0;
             
             if(dp[index][turn]!=-1)
                 return dp[index][turn];
             
             int ans1=Integer.MAX_VALUE;
             int ans2=Integer.MAX_VALUE;
             if(turn==0){
                 if(index<n)
                     ans1=arr[index]+bakchodi(arr,dp,n,1-turn,index+1);
                 
                 if(index+1<n)
                     ans2=arr[index]+arr[index+1]+bakchodi(arr,dp,n,1-turn,index+2);
             }
             else{
                 ans1=bakchodi(arr,dp,n,1-turn,index+1);
                 ans2=bakchodi(arr,dp,n,1-turn,index+2);
             }
              return dp[index][turn]=Math.min(ans1,ans2);
         }
         public static int rec1(int arr[],int turn,int index,int n){
             int ans1=0;
             int ans2=0;
             if(index>=n)
                 return 0;
             
             if(turn==0){
                 if(index<n)
                 ans1=arr[index]+rec1(arr,1-turn,index+1,n);
                 
                 if(index+1<n)
                     ans2=arr[index]+arr[index+1]+rec1(arr,1-turn,index+2,n);
             }
             else{
                 ans1=rec1(arr,1-turn,index+1,n);
                 ans2=rec1(arr,1-turn,index+2,n);
             }
             return Math.min(ans1,ans2);
         }
         public static int rec(int arr[][],int i,int j,int n){
             int sum=0;
             sum+=arr[i][j];
             
             int max=0;
            for(int k=j+1;k<n;k++)
                max=Math.max(max,rec(arr,1-i,k,n));
            
            sum+=max;
            
            return sum;
         }
        
         public static void rec(int i,int n,int count){
             if(i==n){
                 count++;
                 return;
             }
             if(i>n)
                 return;
             
             rec(i+1,n,count);
             rec(i+2,n,count);
         }
         public static long lcm(long x, long y) {
          return ((x * y) / gcd(x, y));
      }
         public static long gcd(long a,long b){
             if(a==0)
                 return b;
             
             return gcd(b%a,a);
         }
         public static int bakloli(char ch[],char c,int k){
             int n=ch.length;
             int k1=0;
             int i=0;
             int j=0;
             int ans=0;
             while(i<n){
                 if(j>=n)
                     break;
                 while(j<n && (ch[j]==c || k1<k)){
                     if(ch[j]!=c){
                         k1++;
                         
                     }
                     j++;
                 }
                 ans=Math.max(j-i,ans);
                 if(ch[i]!=c)
                     k1--;
                 
                 i++;
             }
             return ans;
         }
         
         public static long power(long a,long b){
            long ans=1;
            while(b > 0) {
      		if((b&1) == 1) ans = (ans*a) % mod;
      		a = (a*a) % mod;
      		b >>= 1;
      	}
            return ans;
         }
         public static int largestfactor(int n){
            
             for(int i=2;i*i<=n;i++){
                 if(n%i==0)
                     return n/i;
             }
             return 1;
         }
        
         public static int bs(int ele,int n,int arr[]){
             int low=0;
             int high=n-1;
             while(low<=high){
                 int mid=(low+high)/2;
                 if(arr[mid]>=ele){
                     low=mid+1;
                 }
                 else
                     high=mid-1;
             }
             return low;
         }
         private static int mergeAndCount(long[] arr, int l,
                                       int m, int r)
      {
   
          // Left subarray
          long[] left = Arrays.copyOfRange(arr, l, m + 1);
   
          // Right subarray
          long[] right = Arrays.copyOfRange(arr, m + 1, r + 1);
   
          int i = 0, j = 0, k = l, swaps = 0;
   
          while (i < left.length && j < right.length) {
              if (left[i] <= right[j])
                  arr[k++] = left[i++];
              else {
                  arr[k++] = right[j++];
                  swaps += (m + 1) - (l + i);
              }
          }
          while (i < left.length)
              arr[k++] = left[i++];
          while (j < right.length)
              arr[k++] = right[j++];
          return swaps;
      }
   
      // Merge sort function
      private static int mergeSortAndCount(long[] arr, int l,
                                           int r)
      {
   
          // Keeps track of the inversion count at a
          // particular node of the recursion tree
          int count = 0;
   
          if (l < r) {
              int m = (l + r) / 2;
   
              // Total inversion count = left subarray count
              // + right subarray count + merge count
   
              // Left subarray count
              count += mergeSortAndCount(arr, l, m);
   
              // Right subarray count
              count += mergeSortAndCount(arr, m + 1, r);
   
              // Merge count
              count += mergeAndCount(arr, l, m, r);
          }
   
          return count;
      }
  }
  class FastScanner {
  		java.io.BufferedReader br = new java.io.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());
  		}
   
  		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());
  		}
  	}
  class Pair{
      int x;
      int y;
      Pair(int x,int y){
          this.x=x;
          this.y=y;
      }
  }
  class Sorting implements Comparator<Pair>{
      public int compare(Pair p1,Pair p2){
         
          return (int)(p2.x-p1.x);
      }
  }