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.*;
  import java.util.*;
   
  public class Practice
  {
  	static final int mod=1000000007;
  	static FastReader sc=new FastReader(System.in);
  //	static Reader sc=new Reader();
  	static  PrintWriter out=new PrintWriter(System.out);
  	public static void main(String[] args) throws IOException
  	{ 
  		int t=1;
  		t=sc.nextInt();
  //		StringBuilder sb=new StringBuilder();
  		while(t-->0)
  		{
  			solve();
  //			sb.append("\n");
  		}
  //		out.print(sb);
  		out.close();
  		out.flush();
  	}
  	static class Pair
  	{
  		int num	,
  		size;
  		Pair(int i,int j)
  		{
  			num=i;	//weight
  			size=j;	//height
  		}
  	}
  	static void arraySort(int arr[])
  	{
  		ArrayList<Integer> a=new ArrayList<Integer>();
  		for (int i = 0; i < arr.length; i++) {
  			a.add(arr[i]);
  		}
  		Collections.sort(a);
  		for (int i = 0; i < arr.length; i++) {
  			arr[i]=a.get(i);
  		}
  	}
  	static void solve() throws IOException
  	{
  		String t=sc.next();
  		HashMap<Character,Integer> set=new HashMap<Character, Integer>();
  		Stack<Character> st=new Stack<Character>();
  		for(int i=t.length()-1;i>=0;i--)
  		{
  			if(!set.containsKey(t.charAt(i)))
  				st.push(t.charAt(i));
  			set.put(t.charAt(i), set.getOrDefault(t.charAt(i), 0)+1);
  		}
  		StringBuilder seq=new StringBuilder();
  		int len=0;
  		while(!st.isEmpty())
  		{
  			char ch=st.pop();
  			seq.append(ch);
  		}
  		for(int i=0;i<seq.length();i++)
  		{
  			set.put(seq.charAt(i), set.get(seq.charAt(i))/(i+1));
  			len+=set.get(seq.charAt(i));
  		}
  		HashSet<Character> rem=new HashSet<Character>();
  		String ans=t.substring(0,len);
  		StringBuilder check=new StringBuilder();
  //		out.println(ans+" "+seq);
  		int c=0;
  		while(rem.size()<seq.length())
  		{
  			for(int i=0;i<ans.length();i++)
  				if(!rem.contains(ans.charAt(i)))
  						check.append(ans.charAt(i));
  			rem.add(seq.charAt(c++));
  		}
  		if(t.equals(check.toString()))
  			out.println(ans+" "+seq);
  		else
  			out.println(-1);
  	}
  	static class UnionFind
  	{
  		  private int size;
  		  private int[] sz;
  		  private int[] parent;
  		  private int numComponents;
  		  public UnionFind(int size,Pair dancers[]) 
  		  {
  		    if (size <= 0) throw new IllegalArgumentException("Size <= 0 is not allowed");
  		    this.size = numComponents = size;
  		    sz = new int[size];
  		    parent = new int[size];
  		    for (int i = 0; i < size; i++) 
  		    {
  		      parent[i] = i; 									// Link to itself (self root)
  		      sz[i] = 1; 										// Each component is originally of size one
  		    }
  		  }
  		  public int find(int p) 
  		  {
  		    int root = p;
  		    while (root != parent[root])
  		    	root = parent[root];
  		    while (p != root)
  		    {
  		      int next = parent[p];
  		      parent[p] = root;
  		      p = next;
  		    }
  		    return root;
  		  }
  		  public boolean isConnected(int p, int q) 
  		  {
  		    return find(p) == find(q);
  		  }
  		  public int componentSize(int x) 
  		  {
  		    return sz[find(x)];
  		  }
  		  public int size() 
  		  {
  		    return size;
  		  }
  		  public int components() 
  		  {
  		    return numComponents;
  		  }
  		  public void unify(int p, int q) 
  		  {
  		    int root1 = find(p);
  		    int root2 = find(q);
  		    if(root1==root2)
  		    {
  		    	return;
  		    }
  		    else if (sz[root1] < sz[root2]) 
  		    {
  		    	parent[root1] = root2;
  		    	sz[root2] += sz[root1];
  		    	sz[root1] = 0;
  		  } 
  		    else 
  		    {
  		    	parent[root2] = root1;
  		    	sz[root1] += sz[root2];
  		    	sz[root2] = 0;
  		    }
  		    numComponents--;
  		  }
  		  void calc()
  		  {
  			  for(int i=0;i<size;i++)
  				  find(i);
  			  
  		  }
  	}
  	static class Node
  	{
  		int vertex;
  		ArrayList<Node> adj;
  		boolean mark;
  		boolean vis;
  		int size;
  		Node(int v)
  		{
  			vertex=v;
  			adj=new ArrayList<Node>();
  			mark=true;
  			vis=false;
  			size=1;
  		}
  		@Override
  		public String toString() 
  		{
  			return vertex+" ";
  		}
  	}
  	static class Edge
  	{
  		Node a;
  		Node b;
  		Edge(Node m,Node n)
  		{
  			this.a=m;
  			this.b=n;
  		}
  		@Override
  		public String toString() {
  			return a.vertex+" "+b.vertex;
  		}
  	}
  	static long power(long x, long y)
  	  {
  	    long res = 1; 
  	    x = x % mod; 
  	    if (x == 0)
  	      return 0; 
  	    while (y > 0)
  	    {
  	    	if ((y & 1) != 0)
  	    		res = (res * x) % mod;
  	    	
  	    	y = y >> 1; // y = y/2
  	    	x = (x * x) % mod;
  	    }
  	    return res;
  	  }
  	static long binomialCoeff(long n, long k)
      {
          long res = 1;
          if(k>n)
          	return 0;
          // Since C(n, k) = C(n, n-k)
          if (k > n - k)
              k = n - k;
   
          // Calculate value of
          // [n * (n-1) *---* (n-k+1)] / [k * (k-1) *----* 1]
          for (long i = 0; i < k; ++i) {
              res *= (n - i);
              res /= (i + 1);
          }
   
          return res;
      }
  	static class FastReader
  	{
          byte[] buf = new byte[2048];
          int index, total;
          InputStream in;
   
          FastReader(InputStream is) 
          {
              in = is;
          }
   
          int scan() throws IOException 
          {
              if (index >= total) {
                  index = 0;
                  total = in.read(buf);
                  if (total <= 0) {
                      return -1;
                  }
              }
              return buf[index++];
          }
   
          String next() throws IOException 
          {
              int c;
              for (c = scan(); c <= 32; c = scan());
              StringBuilder sb = new StringBuilder();
              for (; c > 32; c = scan()) {
                  sb.append((char) c);
              }
              return sb.toString();
          }
   
          int nextInt() throws IOException 
          {
              int c, val = 0;
              for (c = scan(); c <= 32; c = scan());
              boolean neg = c == '-';
              if (c == '-' || c == '+') {
                  c = scan();
              }
              for (; c >= '0' && c <= '9'; c = scan()) {
                  val = (val << 3) + (val << 1) + (c & 15);
              }
              return neg ? -val : val;
          }
   
          long nextLong() throws IOException 
          {
              int c;
              long val = 0;
              for (c = scan(); c <= 32; c = scan());
              boolean neg = c == '-';
              if (c == '-' || c == '+') {
                  c = scan();
              }
              for (; c >= '0' && c <= '9'; c = scan()) {
                  val = (val << 3) + (val << 1) + (c & 15);
              }
              return neg ? -val : val;
          }
      }
  	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();
          }
          public void printarray(int arr[])
          {
          	for (int i = 0; i < arr.length; i++)
  				System.out.print(arr[i]+" ");
          	System.out.println();
          }
      }
  }
  
  
  
  
  
  
  
  
  