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.IOException;
  import java.io.InputStreamReader;
  import java.io.PrintWriter;
  import java.util.StringTokenizer;
  import java.io.BufferedReader;
  import java.util.*;
  
  public class E {
  	private static final FastReader fs = new FastReader();
  	private static final PrintWriter out = new PrintWriter(System.out);
  	private static long m = 1_000_000_009;
  	private static long p = 31;
  	private static long mod = 1_000_000_007;
  	
  	private static void debugArray(int[] lastOccurrence) {
  		int n = lastOccurrence.length;
  		out.println("Contents of array are ::");
  		for(int i = 0; i < n; i++) {
  			out.print(lastOccurrence[i] + " ");
  		}
  		out.println("----------------------------------");
  	}
  	
  	private static void debugArray(char[] lastOccurrence) {
  		int n = lastOccurrence.length;
  		out.println("Contents of array are ::");
  		for(int i = 0; i < n; i++) {
  			out.print(lastOccurrence[i] + " ");
  		}
  		out.println("----------------------------------");
  	}
  	
  	
  	private static void solve() throws Exception {
  		char[] t = fs.next().toCharArray();
  		int n = t.length;
  		int[] lastOccurrence = new int[26];
  		int[] f = new int[26];
  		Arrays.fill(lastOccurrence, -1);
  		for(int i = 0; i < n; i++) {
  			lastOccurrence[t[i]-'a'] = max(lastOccurrence[t[i] - 'a'], i);
  			f[t[i]-'a']++;
  		}
  		ArrayList<pair<Integer, Character>> order = new ArrayList<>();
  		for(int i = 0; i < 26; i++) {
  			if(lastOccurrence[i] != -1) {
  				order.add(new pair<>(lastOccurrence[i], (char)(i+'a')));
  			}
  		}
  		Collections.sort(order);
  		int lenOfS = 0;
  		for(int i = 0; i < order.size(); i++) {
  			if(f[order.get(i).ss - 'a'] % (i+1) != 0) {
  				out.println(-1);
  				return;
  			}
  			lenOfS += f[order.get(i).ss - 'a'] / (i+1);
  		}
  		char[] t_ = new char[n];
  		Set<Character> seen = new HashSet<>();
  		int idx = 0;
  		try {
  			for(int i = 0; i < order.size(); i++) {
  				for(int j = 0; j < lenOfS; j++) {
  					if(seen.contains(t[j]))
  						continue;
  					t_[idx++] = t[j];
  				}
  				seen.add(order.get(i).ss);
  			}
  			for(int i = 0; i < n; i++)
  				if(t_[i] != t[i]) {
  					out.println(-1);
  					return;
  				}
  		} catch (Exception ex) {
  			//out.println("error is " + ex.getMessage());
  			out.println(-1);
  			return;
  		}
  		for(int i = 0; i < lenOfS; i++)
  			out.print(t[i]);
  		out.print(" ");
  		for(int i = 0; i < order.size(); i++)
  			out.print(order.get(i).ss);
  		out.println();
  	}
   
  	public static void main(String[] args) {
  		Thread t = new Thread(null, null, "", 1 << 28) {
  			public void run() {
  				int test_case = 1;
  				test_case = fs.nextInt();
  				for (int cs = 1; cs <= test_case; cs++) {
  					try {
  						solve();
  					} catch (Exception e) {
  						// TODO Auto-generated catch block
  						e.printStackTrace();
  					}
  				}
  				out.close();
  			}
  		};
  		t.start();
  		try {
  			t.join();
  		} catch (InterruptedException e) {
  			e.printStackTrace();
  		}
  	}
   
  	private static class FastReader {
  		BufferedReader br;
  		StringTokenizer st;
   
  		public FastReader() {
  			br = new BufferedReader(new InputStreamReader(System.in));
  		}
   
  		String next() {
  			while (st == null || !st.hasMoreElements()) {
  				try {
  					st = new StringTokenizer(br.readLine());
  				} catch (IOException e) {
  					e.printStackTrace();
  				}
  			}
  			return st.nextToken();
  		}
   
  		int nextInt() {
  			return Integer.parseInt(next());
  		}
   
  		long nextLong() {
  			return Long.parseLong(next());
  		}
   
  		double nextDouble() {
  			return Double.parseDouble(next());
  		}
   
  		String nextLine() {
  			String str = "";
  			try {
  				str = br.readLine();
  			} catch (IOException e) {
  				e.printStackTrace();
  			}
  			return str;
  		}
   
  		int[] readintarray(int n) {
  			int res[] = new int[n];
  			for (int i = 0; i < n; i++)
  				res[i] = nextInt();
  			return res;
  		}
   
  		long[] readlongarray(int n) {
  			long res[] = new long[n];
  			for (int i = 0; i < n; i++)
  				res[i] = nextLong();
  			return res;
  		}
  	}
   
  	public static class pair<T1 extends Comparable<T1>, T2 extends Comparable<T2>> implements Comparable<pair<T1, T2>> {
  		T1 ff;
  		T2 ss;
   
  		public pair(T1 ff, T2 ss) {
  			this.ff = ff;
  			this.ss = ss;
  		}
   
  		public int compareTo(pair<T1, T2> o) {
  			if (ff == o.ff)
  				return ss.compareTo(o.ss);
  			return ff.compareTo(o.ff);
  		}
  	}
  	
  	private static int max(int... arg) throws Exception {
  		int length = arg.length;
  		if(length == 0)
  			throw new Exception("Exception from maxFunction with Integer return type. Reason is :: Argument length cannot be zero");
  		int maxVal = arg[0];
  		for(int i = 1; i < length; i++)
  			maxVal = Math.max(maxVal, arg[i]);
  		return maxVal;
  	}
  	
  	private static int min(int... arg) throws Exception {
  		int length = arg.length;
  		if(length == 0)
  			throw new Exception("Exception from minFunction with Integer return type. Reason is :: Argument length cannot be zero");
  		int maxVal = arg[0];
  		for(int i = 1; i < length; i++)
  			maxVal = Math.min(maxVal, arg[i]);
  		return maxVal;
  	}
  	
  	private static long max(long... arg) throws Exception {
  		int length = arg.length;
  		if(length == 0)
  			throw new Exception("Exception from maxFunction with Long return type. Reason is :: Argument length cannot be zero");
  		long maxVal = arg[0];
  		for(int i = 1; i < length; i++)
  			maxVal = Math.max(maxVal, arg[i]);
  		return maxVal;
  	}
  	
  	private static long min(long... arg) throws Exception {
  		int length = arg.length;
  		if(length == 0)
  			throw new Exception("Exception from minFunction with Long return type. Reason is :: Argument length cannot be zero");
  		long maxVal = arg[0];
  		for(int i = 1; i < length; i++)
  			maxVal = Math.min(maxVal, arg[i]);
  		return maxVal;
  	}
  	
  	private static int abs(int a) {
  		return a >= 0 ? a : -a;
  	}
  	
  	private static int abs(int a, int b) {
  		return a-b >= 0 ? a-b : b-a;
  	}
  	
  	private static long abs(long a) {
  		return a >= 0 ? a : -a;
  	}
  	
  	private static long abs(long a, long b) {
  		return a-b >= 0 ? a-b : b-a;
  	}
  	
  	private static int power(int base, int exponent) {
  		int res = 1;
  		while(exponent > 0) {
  			if((exponent & 1) != 0)
  				res *= base;
  			exponent >>= 1;
  			base *= base;
  		}
  		return res;
  	}
  	
  	private static long power(long base, long exponent) {
  		long res = 1;
  		while(exponent > 0) {
  			if((exponent & 1) != 0)
  				res *= base;
  			exponent >>= 1;
  			base *= base;
  		}
  		return res;
  	}
  	
  	private static long mPower(long base, long exponent) throws Exception {
  		long res = 1;
  		base %= mod;
  		while(exponent > 0) {
  			if((exponent & 1) != 0)
  				res = mul(res, base);
  			exponent >>= 1;
  			base = mul(base, base);
  		}
  		return res;
  	}
  	
  	private static long mul(long... arg) throws Exception {
  		long mulRes = 1;
  		for(long arg0 : arg)
  			mulRes = (mulRes % mod * arg0 % mod) % mod;
  		return mulRes;
  	}
  	
  	private static long add(long... arg) throws Exception {
  		long mulRes = 1;
  		for(long arg0 : arg)
  			mulRes = (mulRes % mod + arg0 % mod) % mod;
  		return mulRes;
  	}
  	
  	private static long sub(long... arg) throws Exception {
  		long mulRes = 1;
  		for(long arg0 : arg)
  			mulRes = ((mulRes % mod - arg0 % mod) % mod + mod) % mod;
  		return mulRes;
  	}
  }