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.DataInputStream;
  import java.io.FileInputStream;
  import java.io.IOException;
  import java.util.*;
  
  public class A{
      static void sort(int[] A){
  
          int n = A.length;
          Random rnd = new Random();
          for(int i=0; i<n; ++i){
              int tmp = A[i];
              int randomPos = i + rnd.nextInt(n-i);
              A[i] = A[randomPos];
              A[randomPos] = tmp;
          }
          Arrays.sort(A);
      }
      static class Reader {
          final private int BUFFER_SIZE = 1 << 16;
          private DataInputStream din;
          private byte[] buffer;
          private int bufferPointer, bytesRead;
  
          public Reader() {
              din = new DataInputStream(System.in);
              buffer = new byte[BUFFER_SIZE];
              bufferPointer = bytesRead = 0;
          }
  
          public Reader(String file_name) throws IOException {
              din = new DataInputStream(
                      new FileInputStream(file_name));
              buffer = new byte[BUFFER_SIZE];
              bufferPointer = bytesRead = 0;
          }
  
          public String readLine() throws IOException {
              byte[] buf = new byte[64]; // line length
              int cnt = 0, c;
              while ((c = read()) != -1) {
                  if (c == '\n') {
                      if (cnt != 0) {
                          break;
                      } else {
                          continue;
                      }
                  }
                  buf[cnt++] = (byte) c;
              }
              return new String(buf, 0, cnt);
          }
  
          public int nextInt() throws IOException {
              int ret = 0;
              byte c = read();
              while (c <= ' ') {
                  c = read();
              }
              boolean neg = (c == '-');
              if (neg)
                  c = read();
              do {
                  ret = ret * 10 + c - '0';
              } while ((c = read()) >= '0' && c <= '9');
  
              if (neg)
                  return -ret;
              return ret;
          }
  
          public long nextLong() throws IOException {
              long ret = 0;
              byte c = read();
              while (c <= ' ')
                  c = read();
              boolean neg = (c == '-');
              if (neg)
                  c = read();
              do {
                  ret = ret * 10 + c - '0';
              } while ((c = read()) >= '0' && c <= '9');
              if (neg)
                  return -ret;
              return ret;
          }
  
          public double nextDouble() throws IOException {
              double ret = 0, div = 1;
              byte c = read();
              while (c <= ' ')
                  c = read();
              boolean neg = (c == '-');
              if (neg)
                  c = read();
  
              do {
                  ret = ret * 10 + c - '0';
              } while ((c = read()) >= '0' && c <= '9');
  
              if (c == '.') {
                  while ((c = read()) >= '0' && c <= '9') {
                      ret += (c - '0') / (div *= 10);
                  }
              }
  
              if (neg)
                  return -ret;
              return ret;
          }
  
          private void fillBuffer() throws IOException {
              bytesRead = din.read(buffer, bufferPointer = 0,
                      BUFFER_SIZE);
              if (bytesRead == -1)
                  buffer[0] = -1;
          }
  
          private byte read() throws IOException {
              if (bufferPointer == bytesRead)
                  fillBuffer();
              return buffer[bufferPointer++];
          }
  
          public void close() throws IOException {
              if (din == null)
                  return;
              din.close();
          }
      }
  
      static int editDistanceWith2Ops(String X, String Y) {
          // Find LCS
          int m = X.length(), n = Y.length();
          int L[][] = new int[m + 1][n + 1];
          for (int i = 0; i <= m; i++) {
              for (int j = 0; j <= n; j++) {
                  if (i == 0 || j == 0) {
                      L[i][j] = 0;
                  } else if (X.charAt(i - 1) == Y.charAt(j - 1)) {
                      L[i][j] = L[i - 1][j - 1] + 1;
                  } else {
                      L[i][j] = Math.max(L[i - 1][j], L[i][j - 1]);
                  }
              }
          }
          int lcs = L[m][n];
  
          // Edit distance is delete operations +
          // insert operations.
          return (m - lcs) + (n - lcs);
      }
  
      public static int lcs( char[] Y, char[] X, int n, int m )
      {
          int c=0;
          for(int j=0;j<n;j++)
          {
              if(X[c]==Y[j])
              {
                  c++;
              }
              if(c>=m)
              {
                  break;
              }
          }
          return c;
      }
  
      /* Utility function to get max of 2 integers */
      public static int max(int a, int b)
      {
          return (a > b)? a : b;
      }
  
      public static void main(String args[]) throws IOException {
          Scanner sc=new Scanner(System.in);
          long mod=1000000007l;
          int cases=sc.nextInt();
          StringBuilder prin=new StringBuilder();
  
          while(cases>0)
          {
              cases--;
              String s=sc.next();
              int n=s.length()-1;
              Map<Character,Integer> map=new HashMap<>();
              int arr[]=new int[26];
              int c=0;
              for(int j=n;j>=0;j--)
              {
                  char ch=s.charAt(j);
                  if(map.get(ch)==null)
                  {
                      map.put(ch,c);
                      c++;
                  }
                  arr[ch-'a']++;
              }
              int tot=0;
              int totchar=map.size();
              StringBuilder rem=new StringBuilder();
              char temp[]=new char[totchar];
              for(char y:map.keySet())
              {
                  tot=tot+arr[y-'a']/(totchar-map.get(y));
                  temp[map.get(y)]=y;
              }
              for(int j=temp.length-1;j>=0;j--)
              {
                  rem.append(temp[j]);
              }
  
              StringBuilder now=new StringBuilder(s.substring(0,tot));
  
              Stack<Character> white=new Stack<>();
              Stack<Character> black=new Stack<>();
  
              String store=now.toString();
              for(int j=now.length()-1;j>=0;j--)
              {
                  white.add(now.charAt(j));
              }
              for(int j=0;j<totchar;j++)
              {
                  while(white.isEmpty()==false) {
                      char z = white.pop();
                      if (z != rem.charAt(j)) {
                          now.append(z);
                          black.add(z);
                      }
                  }
                  while(black.isEmpty()==false)
                  {
                      white.add(black.pop());
                  }
              }
  
              if((now.toString()).equals(s))
              {
                  prin.append(store+" "+rem+"\n");
              }
              else{prin.append(-1+"\n");}
  
  
          }
          System.out.println(prin);
  
      }
  }
  