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.util.Map.Entry;
  import java.lang.*;
  import java.io.*;
  import java.math.BigInteger;
  
  public class CF {
  	private static FS sc = new FS();
  	
  	private static class FS {
  		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) {}
  			return st.nextToken();
  		}
  		
  		int nextInt() {
  			return Integer.parseInt(next());
  		}
  		long nextLong() {
  			return Long.parseLong(next());
  		}
  	}
  	
  	private static class extra {
  		
  		static int[] intArr(int size) {
  			int[] a = new int[size];
  			for(int i = 0; i < size; i++) a[i] = sc.nextInt();
  			return a;
  		}
  		
  		static long[] longArr(int size) {
  			long[] a = new long[size];
  			for(int i = 0; i < size; i++) a[i] = sc.nextLong();
  			return a;
  		}
  		
  		static long intSum(int[] a) {
  			long sum = 0; 
  			for(int i = 0; i < a.length; i++) {
  				sum += a[i];
  			}
  			return sum;
  		}
  		
  		static long longSum(long[] a) {
  			long sum = 0; 
  			for(int i = 0; i < a.length; i++) {
  				sum += a[i];
  			}
  			return sum;
  		}
  		
  		static LinkedList[] graphD(int vertices, int edges) {
  			LinkedList<Integer>[] temp = new LinkedList[vertices+1];
  			for(int i = 0; i <= vertices; i++) temp[i] = new LinkedList<>();
  			for(int i = 0; i < edges; i++) {
  				int x = sc.nextInt();
  				int y = sc.nextInt();
  				temp[x].add(y);
  			}
  			return temp;
  		}
  		
  		static LinkedList[] graphUD(int vertices, int edges) {
  			LinkedList<Integer>[] temp = new LinkedList[vertices+1];
  			for(int i = 0; i <= vertices; i++) temp[i] = new LinkedList<>();
  			for(int i = 0; i < edges; i++) {
  				int x = sc.nextInt();
  				int y = sc.nextInt();
  				temp[x].add(y);
  				temp[y].add(x);
  			}
  			return temp;
  		}
  		
  		static void printG(LinkedList[] temp) {
  			for(LinkedList<Integer> aa:temp) System.out.println(aa);
  		}
  		
  		static long cal(long val, long pow) {
  			if(pow == 0) return 1;
  			long res = cal(val, pow/2);
  			
  			long ret = (res*res)%mod;
  			if(pow%2 == 0) return ret;
  			return (val*ret)%mod;
  		}
  		
  		static long gcd(long a, long b) { return b == 0 ? a:gcd(b, a%b); }
  		
  	}
  	
  	static int mod = (int) 1e9 + 7;
  //	static int mod = (int) 998244353;
  	//static int max = (int) 1e6;//, sq = 316;
  	static LinkedList<Integer>[] temp;
  	static double ans;
  	
  	public static void main(String[] args) {	
  		int t = sc.nextInt();
  //		int t = 1;
  		StringBuilder ret = new StringBuilder();
  		while(t-- > 0) {
  			String s = sc.next();
  			int[] f = new int[26];
  			StringBuilder out = new StringBuilder();
  			for(int i = s.length()-1; i >= 0; i--) {
  				if(f[s.charAt(i)-'a'] == 0) out.append(s.charAt(i));
  				f[s.charAt(i)-'a']++;
  			}
  			out.reverse();
  			int flag = 0;
  //			System.out.println(out);
  			int len = 0;
  			for(int i = 0; i < out.length(); i++) {
  				len += f[out.charAt(i)-'a']/(i+1);
  			}
  			StringBuilder fin = new StringBuilder(s.substring(0, len)), ans = new StringBuilder(s.substring(0, len));
  			for(int i = 0; i < out.length(); i++) {
  				StringBuilder tran = new StringBuilder();
  				for(int j = 0; j < fin.length(); j++) {
  					if(fin.charAt(j) != out.charAt(i)) {
  						tran.append(fin.charAt(j));
  						ans.append(fin.charAt(j));
  					}
  				}
  				fin = tran;
  			}
  			if(ans.toString().equals(s)) ret.append(s.substring(0, len) + " " + out + "\n");
  			else ret.append(-1 + "\n");
  //			System.out.println(ans);
  		}
  		System.out.println(ret);
  	}
  }