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.io.*;
  
  public class E {
  
  	private static final FastScanner fs = new FastScanner();
  	private static final int MOD = 1000000007;
  
  	public static void main(String[] args) throws IOException {
  		int cases = fs.nextInt();
  		while (cases-- > 0)
  			solve();
  	}
  	static void solve() throws IOException {
  		String t = fs.next();
  		int[] occur = new int[26];
  		LinkedList<Character> order = new LinkedList<>();
  		for (int i = t.length()-1; i >= 0; i--) {
  			char c = t.charAt(i);
  			if (occur[c-'a'] == 0) {
  				order.addFirst(c);
  			}
  			occur[c-'a']++;
  		}
  		int i = 1;
  		int sum = 0;
  		StringBuilder s = new StringBuilder();
  		for (char c : order) {
  			s.append(c);
  			occur[c-'a'] = occur[c-'a']/i;
  			sum+=occur[c-'a'];
  			i++;
  		}
  		String result = t.substring(0,sum);
  		if (t.equals(build(result,s.toString()))) {
  			System.out.println(result + " " + s);
  		}
  		else {
  			System.out.println(-1);
  		}
  //		if (check(t, result, s.toString())) {
  //			System.out.println(result + " " + s);
  //		} else {
  //			System.out.println(-1);
  //		}
  	}
  	static boolean check(String t, String result, String order) {
  		int l = 0;
  		int r = result.length();
  		if (!t.substring(l,r).equals(result)) return false;
  		for (int i = 0; i < order.length(); i++) {
  			char rem = order.charAt(i);
  			StringBuilder sb = new StringBuilder();
  			for (char c : result.toCharArray()) {
  				if (c == rem) continue;
  				sb.append(c);
  			}
  			result = sb.toString();
  			l = r;
  			r = r+sb.length();
  			if (l > r || r > t.length()) return false;
  			if (!t.substring(l, r).equals(result)) return false;
  		}
  		return true;
  	}
  
  	static String build(String result, String order) {
  		StringBuilder sb = new StringBuilder(result);
  		for (int i = 0; i < order.length(); i++) {
  			char rem = order.charAt(i);
  			StringBuilder cut = new StringBuilder();
  			for (char c : result.toCharArray()) {
  				if (c == rem) continue;
  				cut.append(c);
  			}
  			result = cut.toString();
  			sb.append(cut);
  		}
  		return sb.toString();
  	}
  
  	static class FastScanner
  	{
  		//I don't understand how this works lmao
  		private int BS = 1 << 16;
  		private char NC = (char) 0;
  		private byte[] buf = new byte[BS];
  		private int bId = 0, size = 0;
  		private char c = NC;
  		private double cnt = 1;
  		private BufferedInputStream in;
  
  		public FastScanner() {
  			in = new BufferedInputStream(System.in, BS);
  		}
  
  		public FastScanner(String s) {
  			try {
  				in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
  			} catch (Exception e) {
  				in = new BufferedInputStream(System.in, BS);
  			}
  		}
  
  		private char getChar() {
  			while (bId == size) {
  				try {
  					size = in.read(buf);
  				} catch (Exception e) {
  					return NC;
  				}
  				if (size == -1) return NC;
  				bId = 0;
  			}
  			return (char) buf[bId++];
  		}
  
  		public int nextInt() {
  			return (int) nextLong();
  		}
  
  		public int[] nextInts(int N) {
  			int[] res = new int[N];
  			for (int i = 0; i < N; i++) {
  				res[i] = (int) nextLong();
  			}
  			return res;
  		}
  
  		public ArrayList<Integer> nextIntsArrayList(int N) {
  			ArrayList<Integer> res = new ArrayList<>(N);
  			for (int i = 0; i < N; i++) {
  				res.add((int) nextLong());
  			}
  			return res;
  		}
  
  		public long[] nextLongs(int N) {
  			long[] res = new long[N];
  			for (int i = 0; i < N; i++) {
  				res[i] = nextLong();
  			}
  			return res;
  		}
  
  		public long nextLong() {
  			cnt = 1;
  			boolean neg = false;
  			if (c == NC) c = getChar();
  			for (; (c < '0' || c > '9'); c = getChar()) {
  				if (c == '-') neg = true;
  			}
  			long res = 0;
  			for (; c >= '0' && c <= '9'; c = getChar()) {
  				res = (res << 3) + (res << 1) + c - '0';
  				cnt *= 10;
  			}
  			return neg ? -res : res;
  		}
  
  		public double nextDouble() {
  			double cur = nextLong();
  			return c != '.' ? cur : cur + nextLong() / cnt;
  		}
  
  		public double[] nextDoubles(int N) {
  			double[] res = new double[N];
  			for (int i = 0; i < N; i++) {
  				res[i] = nextDouble();
  			}
  			return res;
  		}
  
  		public String next() {
  			StringBuilder res = new StringBuilder();
  			while (c <= 32) c = getChar();
  			while (c > 32) {
  				res.append(c);
  				c = getChar();
  			}
  			return res.toString();
  		}
  
  		public String nextLine() {
  			StringBuilder res = new StringBuilder();
  			while (c <= 32) c = getChar();
  			while (c != '\n') {
  				res.append(c);
  				c = getChar();
  			}
  			return res.toString();
  		}
  
  		public boolean hasNext() {
  			if (c > 32) return true;
  			while (true) {
  				c = getChar();
  				if (c == NC) return false;
  				else if (c > 32) return true;
  			}
  		}
  	}
  }