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: /*
   * Java Coding Template for Competitive Programming
   * Author: Kartik Gola
   * Utilities Source: https://github.com/kartikgola/well-known-problems
   * Copyright (c) 2021 | https://kartikgola.com
   */
  
  import java.io.*;
  import java.util.*;
  import java.lang.*;
  
  public class E {
  
      private static Pair<String, String> f(String t) {
          StringBuilder sb = new StringBuilder(t);
          int[] ord = new int[26];
          int[] freq = new int[26];
  
          StringBuilder rord = new StringBuilder();
          int pos = -1;
          Arrays.fill(ord, pos);
          sb.reverse();
  
          for (int i = 0; i < sb.length(); ++i) {
              if (ord[sb.charAt(i)-'a'] == -1) {
                  ord[sb.charAt(i)-'a'] = ++pos;
                  rord.append(sb.charAt(i));
              }
              freq[sb.charAt(i)-'a']++;
          }
  
          int len = 0;
          for (int i = 0; i < freq.length; ++i) {
              if (freq[i] > 0) {
                  // freq[i] must be divisible by (pos+1-ord[i])
                  if (freq[i] % (pos+1-ord[i]) != 0) {
                      return null;
                  } else {
                      len += freq[i] / (pos+1-ord[i]);
                  }
              }
          }
  
          String s = t.substring(0, len);
          String rem = rord.reverse().toString();
          return new Pair<>(s, rem);
      }
  
      public static void main(String[] args) throws Exception {
          setIO(); // Comment setIO(); if using AtCoder
          int t = nextInt();
          while (t-- > 0) {
              String inp = nextString();
              Pair<String, String> pa = f(inp);
              if (pa == null) {
                  System.out.println(-1);
                  continue;
              }
              
              String sc = pa.key;
              String rc = pa.value;
              String tc = sc;
  
              for (int i = 0; i < rc.length(); ++i) {
                  sc = sc.replaceAll(Character.toString(rc.charAt(i)), "");
                  tc += sc;
              }
  
              if (tc.equals(inp)) {
                  System.out.println(pa.key + " " + rc);
              } else {
                  System.out.println(-1);
              }
          }
      }
  
      /* -----------------------------Common Utilities--------------------------- */
      private static class Pair<T, K> {
          T key;
          K value;
          public Pair(T key, K value) {
              this.key = key;
              this.value = value;
          }
      }
  
  
      /* -----------------------------Graph Utilities---------------------------- */
      private static class UnionFind {
  
          private int groups;
          private final int[] parent;
          private boolean zeroIndexed = true;
  
          public UnionFind(int size) {
              groups = size;
              parent = new int[size];
              Arrays.fill(parent, -1);
          }
  
          public UnionFind(int size, boolean zeroIndexed) {
              groups = size;
              if (zeroIndexed)
                  parent = new int[size];
              else
                  parent = new int[size+1];
              Arrays.fill(parent, -1);
              this.zeroIndexed = zeroIndexed;
          }
  
          public int getTotalGroups() {
              return this.groups;
          }
  
          public int find(int u) {
              if ( parent[u] < 0 )
                  return u;
              return parent[u] = find(parent[u]);
          }
  
          public boolean union(int u, int v) {
              int pu = find(u);
              int pv = find(v);
              if ( pu != pv ) {
                  // Weight of pu is more (more negative means higher weight)
                  if ( parent[pu] <= parent[pv] ) {
                      parent[pv] = pu;
                      parent[pu]--;
                  } else {
                      parent[pu] = pv;
                      parent[pv]--;
                  }
                  groups--;
                  return true;
              }
              // In case parents of 'u' and 'v' are same, we return false
              return false;
          }
      }
  
      private static class IntGraph {
          public final Map<Integer, Map<Integer, Integer>> adj = new HashMap<>();
          public List<int[]> edges;
          public final int size;
          public final boolean isDirected;
          public IntGraph(int size, boolean isDirected) {
              this.size = size;
              this.isDirected = isDirected;
              this.edges = new ArrayList<>(size);
              for (int u = 0; u < size; ++u)
                  adj.put(u, new HashMap<>());
          }
          public IntGraph(int size, boolean isDirected, int[][] edges) {
              this(size, isDirected);
              for (int[] edge: edges)
                  addEdge(edge);
          }
          public void addEdge(int[] edge) {
              int from = edge[0],
                      to = edge[1],
                      weight = edge.length == 3 ? edge[2] : 0;
              adj.get(from).put(to, weight);
              edges.add(new int[]{from, to, weight});
              if (!isDirected) {
                  adj.get(to).put(from, weight);
                  edges.add(new int[]{to, from, weight});
              }
          }
  
          private boolean isCyclic(int u, boolean[] visited, boolean[] path) {
              if (!visited[u]) {
                  visited[u] = true;
                  path[u] = true;
                  for (int v: adj.get(u).keySet()) {
                      if (!visited[v]) {
                          if (isCyclic(v, visited, path))
                              return true;
                      } else if (path[v])
                          return true;
                  }
              }
              path[u] = false;
              return false;
          }
          public boolean isCyclic() {
              boolean[] visited = new boolean[size];
              boolean[] path = new boolean[size];
              for (int u = 0; u < size; ++u) {
                  if (!visited[u] && isCyclic(u, visited, path)) {
                      return true;
                  }
              }
              return false;
          }
  
          public boolean isTree() {
              boolean[] visited = new boolean[size];
              boolean[] path = new boolean[size];
              if (isCyclic(0, visited, path))
                  return false;
              for (boolean vis: visited)
                  if (!vis) return false;
              return true;
          }
  
          public int[] topologicalSort() {
              int[] indegree = new int[size];
              int[] ans = new int[size];
              boolean[] visited = new boolean[size];
              Queue<Integer> q = new LinkedList<>();
              adj.values().stream().map(Map::keySet).flatMap(Collection::stream).forEach(u -> indegree[u]++);
              for (int u = 0; u < size; u++) {
                  if (indegree[u] == 0) {
                      q.add(u);
                  }
              }
              int j = 0;
              while (!q.isEmpty()) {
                  int u = q.poll();
                  ans[j++] = u;
                  for (int v: adj.get(u).keySet()) {
                      if (!visited[v] && --indegree[v] == 0) {
                          q.add(v);
                          visited[v] = true;
                      }
                  }
              }
              if (j < size)
                  return new int[]{};
              return ans;
          }
  
          public int[] dijkstra(int source) {
              int[] dist = new int[size];
              boolean[] visited = new boolean[size];
              Arrays.fill(dist, Integer.MAX_VALUE);
              dist[source] = 0;
              Queue<int[]> pq = new PriorityQueue<>(Comparator.comparingInt(v -> v[0]));
              pq.add(new int[]{0, source});
  
              while (!pq.isEmpty()) {
                  int d = pq.peek()[0],
                          u = pq.poll()[1];
                  if (visited[u])
                      continue;
                  visited[u] = true;
                  for (Map.Entry<Integer, Integer> e: adj.get(u).entrySet()) {
                      int v = e.getKey(),
                              w = e.getValue();
                      if (d + w < dist[v]) {
                          dist[v] = d + w;
                          pq.add(new int[]{dist[v], v});
                      }
                  }
              }
  
              return dist;
          }
  
          public int[] bellmanFord(int source) {
              int[] dist = new int[size];
              Arrays.fill(dist, Integer.MAX_VALUE);
              dist[source] = 0;
              for (int i = 0; i < size-1; ++i) {
                  for (int[] edge: edges) {
                      int from = edge[0], to = edge[1], weight = edge[2];
                      if (dist[from] != Integer.MAX_VALUE && dist[from] + weight < dist[to]) {
                          dist[to] = dist[from] + weight;
                      }
                  }
              }
              for (int[] edge: edges) {
                  int from = edge[0], to = edge[1], weight = edge[2];
                  if (dist[from] != Integer.MAX_VALUE && dist[from] + weight < dist[to]) {
                      // Graph has -ve weight cycle
                      return new int[]{};
                  }
              }
              return dist;
          }
  
          public int[][] floydWarshall() {
              int[][] dist = new int[size][size];
              for (int u = 0; u < size; ++u) {
                  Arrays.fill(dist[u], Integer.MAX_VALUE);
                  dist[u][u] = 0;
                  for (Map.Entry<Integer, Integer> e: adj.get(u).entrySet()) {
                      dist[u][e.getKey()] = e.getValue();
                  }
              }
              for (int k = 0; k < size; ++k) {
                  for (int u = 0; u < size; ++u) {
                      for (int v = 0; v < size; ++v) {
                          if (dist[u][k] != Integer.MAX_VALUE && dist[k][v] != Integer.MAX_VALUE
                                  && dist[u][k] + dist[k][v] < dist[u][v]) {
                              dist[u][v] = dist[u][k] + dist[k][v];
                          }
                      }
                  }
              }
              return dist;
          }
  
          public IntGraph kruskal() {
              IntGraph mst = new IntGraph(size, isDirected);
              edges.sort(Comparator.comparingInt(e -> e[2]));
              UnionFind uf = new UnionFind(size);
              for (int[] edge: edges) {
                  if (uf.union(edge[0], edge[2])) {
                      mst.addEdge(edge);
                  }
              }
              return mst;
          }
  
          public IntGraph prim() {
              boolean[] visited = new boolean[size];
              Queue<int[]> pq = new PriorityQueue<>(Comparator.comparingInt(e -> e[2]));
              IntGraph mst = new IntGraph(size, isDirected);
              int randomSource = new Random().nextInt(size);
              for (Map.Entry<Integer, Integer> edge: adj.get(randomSource).entrySet())
                  pq.add(new int[]{randomSource, edge.getKey(), edge.getValue()});
              visited[randomSource] = true;
  
              while (!pq.isEmpty()) {
                  int u = pq.peek()[0],
                          v = pq.peek()[1],
                          w = pq.poll()[2];
                  if (visited[v])
                      continue;
                  visited[v] = true;
                  mst.addEdge(new int[]{u, v, w});
                  for (Map.Entry<Integer, Integer> edge: adj.get(v).entrySet())
                      pq.add(new int[]{v, edge.getKey(), edge.getValue()});
              }
              return mst;
          }
      }
  
  
      /* -----------------------------Array Utilities--------------------------- */
      public static int bisectLeft(List<Integer> arr, int value) {
          if (arr.isEmpty()) return 0;
          int l = 0, r = arr.size()-1;
          while (l < r) {
              int m = l + (r-l) / 2;
              if (arr.get(m) == value) {
                  while (m-1 > -1 && arr.get(m-1) == value) --m;
                  return m;
              } else if (arr.get(m) < value) l = m+1;
              else r = m-1;
          }
          return arr.get(l) < value ? l+1 : l;
      }
  
      public static int bisectLeft(int[] arr, int value) {
          if (arr.length == 0) return 0;
          int l = 0, r = arr.length-1;
          while (l < r) {
              int m = l + (r-l) / 2;
              if (arr[m] == value) {
                  while (m-1 > -1 && arr[m-1] == value) --m;
                  return m;
              } else if (arr[m] < value) l = m+1;
              else  r = m-1;
          }
          return arr[l] < value ? l+1 : l;
      }
  
      public static int bisectRight(int[] arr, int value) {
          if (arr.length == 0) return 0;
          int l = 0, r = arr.length-1;
          while (l < r) {
              int m = l + (r-l) / 2;
              if (arr[m] == value) {
                  while (m+1 < arr.length && arr[m+1] == value) ++m;
                  return m+1;
              } else if (arr[m] < value) l = m+1;
              else r = m-1;
          }
          return arr[l] <= value ? l+1 : l;
      }
  
      public static int bisectRight(List<Integer> arr, int value) {
          if (arr.isEmpty())  return 0;
          int l = 0, r = arr.size()-1;
          while (l < r) {
              int m = l + (r-l) / 2;
              if (arr.get(m) == value) {
                  while (m+1 < arr.size() && arr.get(m+1) == value) ++m;
                  return m+1;
              } else if (arr.get(m) < value) l = m+1;
              else r = m-1;
          }
          return arr.get(l) <= value ? l+1 : l;
      }
  
  
      /* -----------------------------IO Utilities----------------------------- */
      private static BufferedReader rd = new BufferedReader(new InputStreamReader(System.in));
      private static StringTokenizer tkn = new StringTokenizer("");
  
      // "ONLINE_JUDGE" property
      // works on LeetCode, CodeForces, CodeChef
      // does not work on AtCoder
      private static void setIO() throws Exception {
          if (System.getProperty("ONLINE_JUDGE") == null) {
              rd = new BufferedReader(new FileReader("input.txt"));
              System.setOut(new PrintStream(new FileOutputStream("output.txt")));
          }
      }
  
      // Integer
      private static int nextInt() throws Exception {
          while (!tkn.hasMoreTokens()) tkn = new StringTokenizer(rd.readLine());
          return Integer.parseInt(tkn.nextToken());
      }
  
      private static int[] nextInts(int n) throws Exception {
          while (!tkn.hasMoreTokens()) tkn = new StringTokenizer(rd.readLine());
          int[] ans = new int[n];
          for (int i = 0; i < n; i++) ans[i] = Integer.parseInt(tkn.nextToken());
          return ans;
      }
  
      private static List<Integer> nextIntList(int n) throws Exception {
          while (!tkn.hasMoreTokens()) tkn = new StringTokenizer(rd.readLine());
          List<Integer> ans = new ArrayList<>(n);
          for (int i = 0; i < n; i++) ans.add(Integer.parseInt(tkn.nextToken()));
          return ans;
      }
  
      // Long
      private static long nextLong() throws Exception {
          while (!tkn.hasMoreTokens()) tkn = new StringTokenizer(rd.readLine());
          return Long.parseLong(tkn.nextToken());
      }
  
      private static long[] nextLongs(int n) throws Exception {
          while (!tkn.hasMoreTokens()) tkn = new StringTokenizer(rd.readLine());
          long[] ans = new long[n];
          for (int i = 0; i < n; i++) ans[i] = Long.parseLong(tkn.nextToken());
          return ans;
      }
  
      private static List<Long> nextLongList(int n) throws Exception {
          while (!tkn.hasMoreTokens()) tkn = new StringTokenizer(rd.readLine());
          List<Long> ans = new ArrayList<>(n);
          for (int i = 0; i < n; i++) ans.add(Long.parseLong(tkn.nextToken()));
          return ans;
      }
  
      // Double
      private static double nextDouble() throws Exception {
          while (!tkn.hasMoreTokens()) tkn = new StringTokenizer(rd.readLine());
          return Double.parseDouble(tkn.nextToken());
      }
  
      private static double[] nextDouble(int n) throws Exception {
          while (!tkn.hasMoreTokens()) tkn = new StringTokenizer(rd.readLine());
          double[] ans = new double[n];
          for (int i = 0; i < n; i++) ans[i] = Double.parseDouble(tkn.nextToken());
          return ans;
      }
  
      private static List<Double> nextDoubleList(int n) throws Exception {
          while (!tkn.hasMoreTokens()) tkn = new StringTokenizer(rd.readLine());
          List<Double> ans = new ArrayList<>(n);
          for (int i = 0; i < n; i++) ans.add(Double.parseDouble(tkn.nextToken()));
          return ans;
      }
  
      // String
      private static String nextString() throws Exception {
          while (!tkn.hasMoreTokens()) tkn = new StringTokenizer(rd.readLine());
          return tkn.nextToken();
      }
  
      private static String[] nextStrings(int n) throws Exception {
          while (!tkn.hasMoreTokens()) tkn = new StringTokenizer(rd.readLine());
          String[] ans = new String[n];
          for (int i = 0; i < n; i++) ans[i] = tkn.nextToken();
          return ans;
      }
  
      private static List<String> nextStringList(int n) throws Exception {
          while (!tkn.hasMoreTokens()) tkn = new StringTokenizer(rd.readLine());
          List<String> ans = new ArrayList<>(n);
          for (int i = 0; i < n; i++) ans.add(tkn.nextToken());
          return ans;
      }
  
  }