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.BufferedReader;
  import java.io.IOException;
  import java.io.InputStreamReader;
  import java.util.StringTokenizer;
  
  
  public class practiceb{
  
      static FastScanner sc;
      static TreeSet<Integer> ans;
      static long[] arr,a,dp;
      static char[][] board;
      static long mul,mul1;
      static int[] spf;
      static char[] ch;
      static int n,q,m;
      static long k,x;
      static StringBuilder sb,sb1;
      static long b,sum;
      static Map<Integer,List<Integer>> map;
      static Map<Long,List<Integer>> map2;
      static Map<Long,List<Integer>> map3;
      static Map<Integer,Integer> shortest;
      static Map<Integer,List<Integer>> map1;
      static List<Integer> list,list1;
      static int[] count;
  
      // static class Node{
      //     long dist;
      //     Set<Integer> set;
      //     Node(){
      //         this.set = new HashSet<>();
      //     }
      //     Node(int f){
      //         this.dist = f;
      //         this.set = new HashSet<>();
      //     }
      // }
  
      // public static class Lca {
  
      //     int[] depth;
      //     int[] dfs_order;
      //     int cnt;
      //     int[] first;
      //     int[] minPos;
      //     int n;
  
      //     void dfs(List<Integer>[] tree, int u, int d) {
      //         depth[u] = d;
      //         dfs_order[cnt++] = u;
      //         for (int v : tree[u])
      //             if (depth[v] == -1) {
      //                 dfs(tree, v, d + 1);
      //                 dfs_order[cnt++] = u;
      //             }
      //     }
  
      //     void buildTree(int node, int left, int right) {
      //         if (left == right) {
      //             minPos[node] = dfs_order[left];
      //             return;
      //         }
      //         int mid = (left + right) >> 1;
      //         buildTree(2 * node + 1, left, mid);
      //         buildTree(2 * node + 2, mid + 1, right);
      //         minPos[node] = depth[minPos[2 * node + 1]] < depth[minPos[2 * node + 2]] ? minPos[2 * node + 1] : minPos[2 * node + 2];
      //     }
  
      //     public Lca(List<Integer>[] tree, int root) {
      //         int nodes = tree.length;
      //         depth = new int[nodes];
      //         Arrays.fill(depth, -1);
  
      //         n = 2 * nodes - 1;
      //         dfs_order = new int[n];
      //         cnt = 0;
      //         dfs(tree, root, 0);
  
      //         minPos = new int[4 * n];
      //         buildTree(0, 0, n - 1);
  
      //         first = new int[nodes];
      //         Arrays.fill(first, -1);
      //         for (int i = 0; i < dfs_order.length; i++)
      //             if (first[dfs_order[i]] == -1)
      //                 first[dfs_order[i]] = i;
      //     }
  
      //     public int lca(int a, int b) {
      //         return minPos(Math.min(first[a], first[b]), Math.max(first[a], first[b]), 0, 0, n - 1);
      //     }
  
      //     int minPos(int a, int b, int node, int left, int right) {
      //         if (a == left && right == b)
      //             return minPos[node];
      //         int mid = (left + right) >> 1;
      //         if (a <= mid && b > mid) {
      //             int p1 = minPos(a, Math.min(b, mid), 2 * node + 1, left, mid);
      //             int p2 = minPos(Math.max(a, mid + 1), b, 2 * node + 2, mid + 1, right);
      //             return depth[p1] < depth[p2] ? p1 : p2;
      //         } else if (a <= mid) {
      //             return minPos(a, Math.min(b, mid), 2 * node + 1, left, mid);
      //         } else if (b > mid) {
      //             return minPos(Math.max(a, mid + 1), b, 2 * node + 2, mid + 1, right);
      //         } else {
      //             throw new RuntimeException();
      //         }
      //     }
      // }
  
      // private static long dfs(int v, int parent,long ht) {
  
      //     List<Integer> list = map.get(v);
      //     hyt[v] = ht;
  
      //     if(list.size() == 1){
      //         if(!map3.containsKey(ht))
      //             map3.put(ht,new ArrayList<>());
  
      //         map3.get(ht).add(v);
      //         return ht;
  
      //     }
  
      //     long maxl = -1;
      //     for(Integer i : list){
      //         if(i == parent)
      //             continue;
      //         maxl = Math.max(maxl,dfs(i,v,ht+1));
      //     }
  
      //     return maxl;
  
      // }
      // public static int N = 100005;
  
      // long a[N];
      // long sfx[N];
      // long pfx[N];
  
      public static boolean f(int width){
  
          // long[] a = new long[n];
          long[] sfx = new long[n];
          long[] pfx = new long[n];
  
          for (int j = 0; j < n; j++){
              if (j % width == 0){
                  pfx[j] = a[j];
              }
              else pfx[j] = gcd(pfx[j - 1], a[j]);
          }
          for (int j = n - 2; j >= 0; j--){
              if (j % width == width - 1){
                  sfx[j] = a[j];
              }
              else sfx[j] = gcd(sfx[j + 1], a[j]);
          }
  
          for(int j = 0; j < n - width + 1 ; j++){
              if (gcd(sfx[j], pfx[j + width - 1]) >= k) return true;
              if (((j % width) == width - 1) && pfx[j] >= k){
                  return true;
              }
          }
          return false;
      }
  
  
      public static void solve(){
  
          int[] count = new int[26];
          int n = ch.length;
          sb = new StringBuilder();
  
          for(int i = n-1 ; i > -1 ; i--) {
              if(count[ch[i]-'a'] == 0) {
                  sb.append(ch[i]);
              }
              count[ch[i]-'a'] += 1;
          }
  
          sb = sb.reverse();
          char[] cb = sb.toString().toCharArray();
  
          int[] cap = new int[26];
          int curr = sb.length();
          int rem = 0;
  
          for(int i = cb.length-1 ; i > -1 ; i--,curr--) {
              if(count[cb[i]-'a']%curr != 0) {
                  sb1.append("-1").append("\n");
                  return;
              }
              cap[cb[i]-'a'] = count[cb[i]-'a']/curr;
              rem += cap[cb[i]-'a'];
          }
  
          StringBuilder sb4 = new StringBuilder();
          for(int i = 0 ; i < rem ; i++) {
              sb4.append(ch[i]);
          }
  
          char[] ch1 = sb4.toString().toCharArray();
          curr = -1;
          StringBuilder sb3 = new StringBuilder();
          for(int i = 0 ; i < sb.length() ; i++,curr++) {
              if(curr >= 0) {
                  for(int j = 0 ; j < ch1.length ; j++) {
                      if(ch1[j] != cb[curr] && ch1[j] != '#') {
                          sb3.append(ch1[j]);
                      }
                      else
                          ch1[j] = '#';
                  }
              }
              else{
                  for(int j = 0 ; j < ch1.length ; j++) {
                      sb3.append(ch1[j]);
                  }
              }
  
          }
  
          if(!sb3.toString().equals(String.valueOf(ch))) {
              sb1.append("-1").append("\n");
              return;
          }
  
          sb1.append(sb4);
  
  
  //        for(int i = 0 ; i < rem ; i++) {
  //            sb1.append(ch[i]);
  //        }
  
          sb1.append(" ").append(sb).append("\n");
  
  
      }
  
      public static void main(String[] args) {
  
          sc = new FastScanner();
          // Scanner sc = new Scanner(System.in);
          // SpecialSieve(5000000+5);
          int t = sc.nextInt();
           sb1 = new StringBuilder();
          // int t = 1;
          while(t > 0){
  
              // a = sc.nextLong();
  //            n = sc.nextInt();
              // x = sc.nextLong();
              // m = sc.nextInt();
              // mat = new int[2][m];
  
              // for(int i = 0 ; i < 2 ; i++)
              //     for(int j = 0 ; j < m ; j++)
              //         mat[i][j] = sc.nextLong();
  
              // for(int i = 1 ; i <= 15 ; i++){
              //     m = i;
              //     solve();
              // // }
              // board = new char[3][3];
              // for(int i = 0 ; i < 3 ; i++){
              //     String s = sc.next();
              //     for(int j = 0 ; j < 3 ; j++){
              //         board[i][j] = s.charAt(j);
              //     }
              // }
              // x = sc.nextInt();
              // ch = sc.next().toCharArray();
              // q = sc.nextInt();
               ch = sc.next().toCharArray();
  //            arr = new long[n];
  //            for(int i = 0 ; i < n ; i++)
  //                arr[i] = sc.nextLong();
  //
  //            a = new long[n-1];
  //            for(int i = 1 ; i < n ; i++)
  //                a[i-1] = Math.abs(arr[i] - arr[i-1]);
  //
  //            n -= 1;
  
              solve();
              t -= 1;
          }
           System.out.print(sb1);
  
      }
  
      // Use this instead of Arrays.sort() on an array of ints. Arrays.sort() is n^2
      // worst case since it uses a version of quicksort. Although this would never
      // actually show up in the real world, in codeforces, people can hack, so
      // this is needed.
      static void ruffleSort(long[] a) {
          //ruffle
          int n=a.length;
          Random r=new Random();
          for (int i=0; i<a.length; i++) {
              int oi=r.nextInt(n);long temp=a[i];
              a[i]=a[oi];
              a[oi]=temp;
          }
  
          //then sort
          Arrays.sort(a);
      }
      public static long gcd(long a, long b)
      {
          if (b == 0)
              return a;
  
          return gcd(b, a % b);
  
      }
      public static int log(double n,double base){
  
          if(n == 0 || n == 1)
              return 0;
  
          if(n == base)
              return 1;
  
          double num = Math.log(n);
          double den = Math.log(base);
  
          if(den == 0)
              return 0;
  
          return (int)(num/den);
      }
      public static long mod(long x, long mod)
      {
          long result = x % mod;
          if (result < 0)
          {
              result += mod;
          }
          return result;
      }
  
      // Use this to input code since it is faster than a Scanner
      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());
          }
          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());
          }
      }
  }
  