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 \le T \le 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 \cdot 10^5$. The sum of lengths of all strings $t$ in the test cases doesn't exceed $5 \cdot 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.


-----Examples-----

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.

Source: codeforces | Difficulty: MEDIUM_HARD
Tags: String algorithms

Sorting

Implementation


Solutions:
import sys
import math
from math import factorial, inf, gcd, sqrt
from heapq import *
from functools import *
from itertools import *
from collections import *
from typing import *
from bisect import *
import random
from sys import stdin, stdout
sys.setrecursionlimit(10 ** 5)

def inp():
	return stdin.readline().strip()

def iinp():
	return int(inp())

def mp():
	return map(int, inp().split())

def lmp():
	return list(mp())

def f(t, s, v):
	temp = ''
	i = 0
	while s:
		temp += s
		x = []
		for j in s:
			if j != v[i]:
				x.append(j)
		s = ''.join(x)
		i += 1
	return t == temp
ti = int(input())
for i in range(ti):
	s = inp()
	n = len(s)
	h = Counter()
	v = []
	for i in reversed(range(n)):
		if s[i] not in h:
			v.append(s[i])
		h[s[i]] += 1
	v = v[::-1]
	su = 0
	for (i, j) in enumerate(v):
		k = h[j]
		if k % (i + 1) != 0:
			su = -1
			break
		su += k // (i + 1)
	if su != -1 and f(s, s[:su], v):
		print(s[:su], ''.join(v))
	else:
		print(-1)


t = int(input())
results = []
for i in range(t):
	line = input()
	counts = {}
	order = []
	for c in line[::-1]:
		if c not in counts:
			counts[c] = 0
			order.append(c)
		counts[c] += 1
	for (j, c) in enumerate(order):
		real = counts[c] // (len(order) - j)
		if real * (len(order) - j) != counts[c]:
			results.append(-1)
			break
		counts[c] = real
	else:
		order = order[::-1]
		size = sum([val for val in counts.values()])
		s = line[:size]
		bad = set()
		index = size
		for k in range(len(order) - 1):
			bad.add(order[k])
			for char in s:
				if char not in bad:
					if index >= len(line):
						results.append(-1)
						break
					elif char != line[index]:
						results.append(-1)
						break
					else:
						index += 1
			else:
				continue
			break
		else:
			if index == len(line):
				results.append(s + ' ' + ''.join(order))
			else:
				results.append(-1)
for i in range(t):
	print(results[i])


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time

def II():
	return int(input())

def S():
	return input()

def solve():
	s = list(S())
	cnts = collections.Counter(s)
	res2 = ''
	for c in s[::-1]:
		if c not in res2:
			res2 += c
	res2 = res2[::-1]
	for i in range(len(res2))[::-1]:
		if cnts[res2[i]] % (i + 1) > 0:
			return [-1]
		cnts[res2[i]] //= i + 1
	first_str = s[:sum(cnts.values())]
	tmp_str = first_str[:]
	cnts_check = collections.Counter(first_str)
	if cnts != cnts_check:
		return [-1]
	index = len(first_str)
	for c in res2:
		tmp_str = [x for x in tmp_str if x != c]
		if tmp_str != s[index:index + len(tmp_str)]:
			return [-1]
		index += len(tmp_str)
	return [''.join(first_str), res2]

def main():
	t = II()
	res = list()
	for _ in range(t):
		ans = solve()
		res.append(ans)
	for ans in res:
		if len(ans) < 2:
			print(-1)
		else:
			print(ans[0], ans[1])
	return 0
main()


def check(a, alf, anus):
	ans = a[:]
	curr = ans[:]
	for i in alf[:-1]:
		cu = []
		for j in curr:
			if j != i:
				cu.append(j)
		curr = cu[:]
		ans += curr
	return ans == anus
for _ in range(int(input())):
	s = list(input())
	sa = s[:]
	l = s[-1]
	cnt = len(set(s))
	ans = [l]
	an = set(ans)
	alf = {}
	k = 0
	for i in s:
		if i in alf:
			alf[i] += 1
		else:
			alf[i] = 1
	for i in range(cnt, 1, -1):
		k += alf[l] // i
		while s[-1] in an:
			del s[-1]
		ans.append(s[-1])
		an.add(s[-1])
		l = s[-1]
	k += alf[l]
	if check(sa[:k], ans[::-1], sa):
		print(''.join(sa[:k]), ''.join(ans[::-1]))
	else:
		print(-1)


import sys
from sys import stdin
tt = int(stdin.readline())
for loop in range(tt):
	T = stdin.readline()[:-1]
	dic = {}
	cndic = {}
	for i in range(len(T)):
		c = T[i]
		dic[c] = i
		if c not in cndic:
			cndic[c] = 0
		cndic[c] += 1
	ic = []
	for c in dic:
		ic.append((dic[c], c))
	ic.sort()
	ans2 = [ic[i][1] for i in range(len(ic))]
	ans2 = ''.join(ans2)
	stlen = 0
	for j in range(len(ic)):
		c = ic[j][1]
		stlen += cndic[c] // (j + 1)
	ans1 = T[:stlen]
	now = list(ans1)
	nex = []
	s = set(dic)
	T2 = []
	for j in range(len(ic)):
		for k in now:
			if k in s:
				T2.append(k)
				nex.append(k)
		s.remove(ic[j][1])
	flag = True
	if len(T) != len(T2):
		flag = False
	else:
		for j in range(len(T)):
			if T[j] != T2[j]:
				flag = False
				break
	if flag:
		print(ans1, ans2)
	else:
		print(-1)


import sys
LI = lambda : list(map(int, sys.stdin.readline().split()))
MI = lambda : map(int, sys.stdin.readline().split())
SI = lambda : sys.stdin.readline().strip('\n')
II = lambda : int(sys.stdin.readline())
for _ in range(II()):
	t = SI()
	p = ''
	for c in t[::-1]:
		if c not in p:
			p += c
	p = p[::-1]
	cnt = {}
	ok = 1
	for (i, c) in enumerate(p, 1):
		cnt[c] = t.count(c)
		if cnt[c] % i:
			ok = 0
		else:
			cnt[c] //= i
	l = sum(cnt.values())
	s = t[:l]
	x = ''
	for c in p:
		x += s
		s = s.replace(c, '')
	ok = x == t
	if ok:
		print(t[:l], p)
	else:
		print(-1)


from __future__ import division, print_function
import math
import sys
import os
from io import BytesIO, IOBase
from collections import deque, Counter, OrderedDict, defaultdict
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def inp():
	return int(input())

def inps():
	return input().strip()

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input().strip()
	return list(s[:len(s)])

def invr():
	return map(int, input().split())

def verify(st, orb):
	val = st
	for i in range(len(orb)):
		temp = ''
		v = orb[i]
		for j in range(len(st)):
			if st[j] != v:
				temp = ''.join([temp, st[j]])
		val = ''.join([val, temp])
		st = temp
	return val
for _ in range(inp()):
	s = insr()
	n = len(s)
	c = Counter(s)
	v = ''
	for i in range(n - 1, -1, -1):
		if s[i] not in v:
			v = s[i] + v
	cnt = defaultdict(lambda : 0)
	flag = 1
	for each in c:
		g = v.index(each) + 1
		if c[each] / g % 1 == 0:
			cnt[each] = c[each] // g
		else:
			flag = 0
	if flag:
		sm = sum(cnt.values())
		for i in range(sm):
			cnt[s[i]] -= 1
		for each in cnt:
			if cnt[each] != 0:
				flag = 0
		if verify(''.join(s[:sm]), v) == ''.join(s):
			print(''.join(s[:sm]), v)
		else:
			print(-1)
	else:
		print(-1)


for _ in range(int(input())):
	t = input()
	l = sorted(set(t), key=t.rindex)
	c = 0
	for i in set(t):
		if t.count(i) % (l.index(i) + 1):
			print(-1)
			break
		c += t.count(i) // (l.index(i) + 1)
	else:
		s = t[:c]
		u = s
		for i in l:
			s = ''.join((j for j in s if j != i))
			u += s
		if u != t:
			print(-1)
		else:
			print(t[:c], ''.join(l))


from collections import Counter
for _ in range(int(input())):
	t = input()
	m = n = len(set(t))
	ans2 = ''
	for i in t[::-1]:
		if i not in ans2:
			ans2 += i
	c = Counter(t)
	count = 0
	for i in ans2:
		count += c[i] // n
		n -= 1
	test = t[:count]
	temp1 = test
	ans2 = ans2[::-1]
	for i in range(m):
		temp = ''
		for j in temp1:
			if j != ans2[i]:
				temp += j
		test += temp
		temp1 = temp
	if test == t:
		print(t[:count], ans2)
	else:
		print(-1)


for _ in range(int(input())):
	t = input()
	a = t[-1]
	b = a
	f = s = 0
	hi = []
	for i in range(len(t) - 1, -1, -1):
		if t[i] != a:
			a = t[i]
			if a not in b:
				b = b + a
	l = len(b)
	for ele in b:
		h = t.count(ele)
		if h % l == 0:
			h = h // l
			s = s + h
			hi.append(h)
			l = l - 1
		else:
			f = 1
			break
	if f == 1:
		print(-1)
	else:
		x1 = x = t[:s]
		b = b[::-1]
		s1 = s
		s2 = s
		for i in range(len(b)):
			x = x.replace(b[i], '')
			s1 = s1 - hi[len(b) - 1 - i]
			s2 = s1 + s2
			if x != t[s:s2]:
				f = 1
				break
			s = s2
		if f == 1:
			print(-1)
		else:
			print(x1, b)


from collections import *
a = int(input())
for i in range(a):
	z = input()
	al = defaultdict(int)
	ans = []
	for i in range(len(z) - 1, -1, -1):
		if al[z[i]] == 0:
			al[z[i]] = 1
			ans.append(z[i])
	dl = defaultdict(int)
	rl = defaultdict(int)
	ans.reverse()
	for i in range(len(z)):
		dl[z[i]] += 1
		rl[z[i]] += 1
	flag = 0
	for i in range(len(ans)):
		if dl[ans[i]] % (i + 1) != 0:
			flag = 1
			break
		dl[ans[i]] = dl[ans[i]] // (i + 1)
	index = -1
	for i in range(len(z)):
		if dl[z[i]] > 0:
			dl[z[i]] -= 1
		else:
			index = i
			break
	for i in dl:
		if dl[i] > 0:
			flag = 1
	if flag == 1:
		print(-1)
		continue
	if index == -1:
		index = len(z)
	alpha = z[0:index]
	m1 = []
	for i in range(len(ans)):
		for j in range(len(alpha)):
			if rl[alpha[j]] != 0:
				m1.append(alpha[j])
		rl[ans[i]] = 0
	if ''.join(m1) == z:
		print(alpha, ''.join(ans))
	else:
		print(-1)


for t in range(int(input())):
	mystr = input()
	pat = ''
	mydict = {}
	printed = False
	for i in range(len(mystr) - 1, -1, -1):
		if mystr[i] not in pat:
			pat = mystr[i] + pat
		if mystr[i] in mydict:
			mydict[mystr[i]] += 1
		else:
			mydict[mystr[i]] = 1
	for j in range(1, len(pat) + 1):
		mydict[pat[j - 1]] = mydict[pat[j - 1]] / j
	if not printed:
		ansstr = ''
		for let in mystr:
			if mydict[let] > 0:
				ansstr += let
				mydict[let] -= 1
			else:
				break
	chkstr = ansstr
	xstr = ansstr[:]
	for x in pat:
		xstr = xstr.replace(x, '')
		chkstr += xstr
	if chkstr == mystr:
		print(ansstr, pat)
	else:
		print(-1)


t = int(input())
for i in range(t):
	s = input()
	n = len(s)
	sq = []
	d = {}
	for i in range(n - 1, -1, -1):
		if s[i] not in d:
			sq.append(s[i])
		d[s[i]] = d.get(s[i], 0) + 1
	sq = sq[::-1]
	dc = {}
	for i in range(n):
		dc[s[i]] = dc.get(s[i], 0) + 1
		d[s[i]] = d[s[i]] - 1
		flag = True
		for j in range(len(sq)):
			if j * dc.get(sq[j], 0) != d[sq[j]]:
				flag = False
				break
		if flag:
			pos = i
			break
	if flag == False:
		print(-1)
		continue
	ans = s[:pos + 1]
	ans1 = ans
	curr = ans
	for a in sq:
		x = ''
		for b in curr:
			if b == a:
				continue
			x = x + b
		ans1 = ans1 + x
		curr = x
	if s == ans1:
		print(ans, end=' ')
		x = ''
		for a in sq:
			x = x + a
		print(x)
	else:
		print(-1)


t = int(input())
while t:
	t -= 1
	s = list(input())
	was = s.copy()
	deleted_list = []
	while s:
		deleted_list.append(s[-1])
		s = list(filter(lambda x: x != deleted_list[-1], s))
	deleted_list.reverse()
	multi = [0 for _ in range(26)]
	cnt = 1
	for i in deleted_list:
		multi[ord(i) - ord('a')] = cnt
		cnt += 1
	start_s = []
	now_len = 0
	for i in was:
		now_len += multi[ord(i) - ord('a')]
		start_s.append(i)
		if now_len == len(was):
			break
	if now_len == len(was):
		new_was = []
		ss = start_s.copy()
		for i in deleted_list:
			new_was.extend(ss)
			ss = list(filter(lambda x: x != i, ss))
		if new_was == was:
			print(''.join(start_s), ''.join(deleted_list))
		else:
			print(-1)
	else:
		print(-1)


import sys
import math
import random
from queue import PriorityQueue as PQ
from bisect import bisect_left as BSL
from bisect import bisect_right as BSR
from collections import OrderedDict as OD
from collections import Counter
from itertools import permutations
from decimal import Decimal as BIGFLOAT
mod = 1000000007
try:
	sys.stdin = open('actext.txt', 'r')
	OPENFILE = 1
except:
	pass

def get_ints():
	return map(int, input().split())

def palindrome(s):
	mid = len(s) // 2
	for i in range(mid):
		if s[i] != s[len(s) - i - 1]:
			return False
	return True

def check(i, n):
	if 0 <= i < n:
		return True
	else:
		return False
t = int(input())
for tt in range(t):
	s = input()
	orderset = set()
	order = []
	chrcounter = {}
	for i in s[::-1]:
		if i not in orderset:
			orderset.add(i)
			order.append(i)
		if i not in chrcounter:
			chrcounter[i] = 0
		chrcounter[i] += 1
	order.reverse()
	flag = 0
	s_chr_counter = {}
	for (num, i) in enumerate(order):
		if chrcounter[i] % (num + 1) != 0:
			flag = 1
			break
		else:
			s_chr_counter[i] = chrcounter[i] // (num + 1)
	nn = len(order)
	if flag:
		print(-1)
	else:
		ans_s = []
		for i in s:
			s_chr_counter[i] -= 1
			ans_s.append(i)
			if s_chr_counter[i] == 0:
				nn -= 1
			if nn == 0:
				break
			if s_chr_counter[i] <= -1:
				flag = 1
				break
		if flag:
			print(-1)
		else:
			finals = ''.join(ans_s)
			ss = []
			i = 0
			for i in range(0, len(order)):
				news = []
				for j in ans_s:
					if j != order[i]:
						news.append(j)
					ss.append(j)
				ans_s = news.copy()
			if ''.join(ss) == s:
				print(finals, ''.join(order))
			else:
				print(-1)


import sys
n = int(input())
for _ in range(n):
	t = input()
	lastOccur = dict()
	count = dict()
	for pos in range(len(t)):
		c = t[pos]
		count[c] = count.get(c, 0) + 1
		lastOccur[c] = pos
	remOrder = sorted(lastOccur.keys(), key=lambda c: lastOccur[c])
	impossible = False
	for pos in range(len(remOrder)):
		if not count[remOrder[pos]] % (pos + 1):
			count[remOrder[pos]] //= pos + 1
		else:
			impossible = True
			break
	try:
		if impossible:
			print(-1)
		else:
			s = []
			i = 0
			while count != dict():
				s.append(t[i])
				count[t[i]] -= 1
				if count[t[i]] == 0:
					del count[t[i]]
				i += 1
			sCopy = s.copy()
			newT = s.copy()
			for r in remOrder:
				sCopy = list(filter(lambda x: x != r, sCopy))
				newT.extend(sCopy)
			if newT == list(t):
				print('{} {}'.format(''.join(s), ''.join(remOrder)))
			else:
				print(-1)
	except:
		print(-1)


def res(s: str) -> [str]:
	order = []
	orderSet = set()
	lettersCount = dict()
	for i in range(len(s) - 1, -1, -1):
		lettersCount[s[i]] = lettersCount.get(s[i], 0) + 1
		if s[i] not in orderSet:
			order.append(s[i])
			orderSet.add(s[i])
	order.reverse()
	for (i, letter) in enumerate(order):
		lettersCount[letter] /= i + 1
	for i in range(len(s)):
		lettersCount[s[i]] -= 1
		if lettersCount[s[i]] < 0:
			endIndex = i
			break
	else:
		endIndex = len(s)
	s2 = s[:endIndex]
	t = s2
	for letter in order:
		s2 = s2.replace(letter, '')
		t += s2
	if t == s:
		return f"{s[:endIndex]} {''.join(order)}"
	else:
		return '-1'
n = int(input())
c = [''] * n
for i in range(n):
	c[i] = str(input())
answ = []
for i in range(n):
	answ.append(res(c[i]))
for x in answ:
	print(x)


def reform(s, order):
	t = ''
	for c in order:
		t += s
		s = s.replace(c, '')
	return t

def main():
	t = int(input())
	for tc in range(t):
		inp = input()
		cur = inp
		uniq = len(set(inp))
		n = 0
		order = ''
		org = ''
		ok = True
		for i in range(uniq):
			last = cur[-1]
			order += last
			if inp.count(last) % (uniq - i) > 0:
				ok = False
				break
			else:
				n += inp.count(last) / (uniq - i)
			cur = cur.replace(last, '')
		if ok == False:
			print('-1')
			continue
		order = order[::-1]
		org = inp[0:int(n)]
		if reform(org, order) == inp:
			print(org, order)
		else:
			print('-1')
main()


import sys
input = sys.stdin.readline

def mp():
	return map(int, input().split())

def lmp():
	return list(map(int, input().split()))

def mps(A):
	return [tuple(map(int, input().split())) for _ in range(A)]
import math
import bisect
from copy import deepcopy as dc
from itertools import accumulate
from collections import Counter, defaultdict, deque

def ceil(U, V):
	return (U + V - 1) // V

def modf1(N, MOD):
	return (N - 1) % MOD + 1
inf = int(1e+20)
mod = int(1000000000.0 + 7)
T = int(input())
for _ in range(T):
	t = input()[:-1]
	cnt = [0] * 26
	for i in t:
		cnt[ord(i) - ord('a')] += 1
	used = set()
	ans = []
	for i in t[::-1]:
		if i not in used:
			used.add(i)
			ans.append(i)
	ans.reverse()
	for i in range(len(ans)):
		cnt[ord(ans[i]) - ord('a')] = cnt[ord(ans[i]) - ord('a')] // (i + 1)
	anss = []
	for i in t:
		if cnt[ord(i) - ord('a')] == 0:
			break
		cnt[ord(i) - ord('a')] -= 1
		anss.append(i)
	conf = [''.join(anss)]
	now = ''.join(anss)
	for i in ans:
		now = now.replace(i, '')
		conf.append(now)
	if ''.join(conf) == t:
		print(''.join(anss), ''.join(ans))
	else:
		print(-1)


def find(t):
	list = []
	for i in range(-1, -len(t) - 1, -1):
		if t[i] not in list:
			list.append(t[i])
	d = len(list)
	initial_length = 0
	for letter in list:
		occ = t.count(letter)
		if divmod(occ, d)[1] == 0:
			initial_length += divmod(occ, d)[0]
			d -= 1
		else:
			return -1
	initial_t = t[0:initial_length]
	s = t[0:initial_length]
	for i in range(-1, -len(list) - 1, -1):
		s = s.replace(list[i], '')
		initial_t += s
	if initial_t == t:
		remove_order = ''
		for i in range(-1, -len(list) - 1, -1):
			remove_order += list[i]
		return (t[0:initial_length], remove_order)
	else:
		return -1
q = int(input())
for _ in range(q):
	t = input()
	if find(t) == -1:
		print(find(t))
	else:
		print(*find(t))


from collections import defaultdict
for _ in range(int(input())):
	t = input()
	d = defaultdict(lambda : 0)
	ans = ''
	for i in range(len(t) - 1, -1, -1):
		if d[t[i]] == 0:
			ans += t[i]
		d[t[i]] += 1
	ans = ans[::-1]
	ok = True
	l = 0
	for i in range(len(ans)):
		if d[ans[i]] % (i + 1) != 0:
			ok = False
		else:
			l += d[ans[i]] // (i + 1)
	s = t[:l]
	i = 0
	d = defaultdict(lambda : 0)
	comp = ''
	while i < len(ans):
		n = ans[i]
		for j in range(l):
			if d[s[j]] == 0:
				comp += s[j]
		d[ans[i]] = 1
		i += 1
	if ok and comp == t:
		print(s, ans)
	else:
		print(-1)


import sys
import math
import bisect
from collections import *
import heapq
from sys import stdin, stdout
from math import gcd, floor, sqrt, log
from collections import defaultdict as dd
from bisect import bisect_left as bl, bisect_right as br
from itertools import *
from functools import *
import random
sys.setrecursionlimit(100000000)
inp = lambda : int(input())
strng = lambda : input().strip()
jn = lambda x, l: x.join(map(str, l))
strl = lambda : list(input().strip())
mul = lambda : map(int, input().strip().split())
mulf = lambda : map(float, input().strip().split())
seq = lambda : list(map(int, input().strip().split()))
ceil = lambda x: int(x) if x == int(x) else int(x) + 1
ceildiv = lambda x, d: x // d if x % d == 0 else x // d + 1
flush = lambda : stdout.flush()
stdstr = lambda : stdin.readline()
stdint = lambda : int(stdin.readline())
stdpr = lambda x: stdout.write(str(x))
INF = float('inf')
MOD = 1000000007

def solve(s, n):
	temp = s[:]
	s = s[::-1]
	cnt = Counter()
	order = ''
	for c in s:
		if c not in cnt:
			order += c
		cnt[c] += 1
	m = len(order)
	truelen = 0
	for i in range(m):
		truelen += cnt[order[i]] // (m - i)
	order = order[::-1]
	return (temp[:truelen], order)

def encrypt(string, order):
	res = string[:]
	for c in order:
		temp = ''
		for d in string:
			if d != c:
				temp += d
				res += d
		string = temp[:]
	return res
for _ in range(inp()):
	s = strng()
	n = len(s)
	(original, order) = solve(s, n)
	check = encrypt(original, order)
	if s == check:
		print(original, order)
	else:
		print(-1)


def solve():
	s = input()
	d = {}
	for i in s:
		if i not in d:
			d[i] = 0
		d[i] += 1
	l = len(d)
	rems = set()
	flag = True
	counts = {}
	r = []
	for i in reversed(s):
		if i not in rems:
			if d[i] % (l - len(rems)) != 0:
				flag = False
				break
			counts[i] = d[i] // (l - len(rems))
			rems.add(i)
			r.append(i)
	if not flag:
		print(-1)
		return
	ll = sum(counts.values())
	word = s[:ll]
	symbs = ''.join(reversed(r))
	res = word
	prev = word
	for i in symbs:
		current = []
		for c in prev:
			if c != i:
				current.append(c)
		res += ''.join(current)
		prev = current
	if res != s:
		print(-1)
		return
	print(f'{word} {symbs}')
t = int(input())
for tt in range(t):
	solve()


import os, sys
from io import BytesIO, IOBase

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, 8192))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, 8192))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

class dict(dict):

	def __missing__(self, key):
		return 0
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
inp = lambda dtype: dtype(input().strip())
inp_d = lambda dtype: [dtype(x) for x in input().split()]
inp_2d = lambda dtype, n: [inp(dtype) for _ in range(n)]
inp_2ds = lambda dtype, n: [inp_d(dtype) for _ in range(n)]
inp_enu = lambda dtype: [(i, x) for (i, x) in enumerate(inp_d(dtype))]
inp_enus = lambda dtype, n: [[i] + [inp_d(dtype)] for i in range(n)]
ceil1 = lambda a, b: (a + b - 1) // b
for _ in range(inp(int)):
	(s, mem, chrs) = (inp(str), dict(), [])
	for i in s[::-1]:
		mem[i] += 1
		if mem[i] == 1:
			chrs.append(i)
	for (i, j) in enumerate(chrs):
		(div, mod) = divmod(mem[j], len(chrs) - i)
		if mod:
			print(-1)
			break
		mem[j] = div
	else:
		ans = []
		chrs.reverse()
		for i in s:
			if not mem[i]:
				break
			ans.append(i)
			mem[i] -= 1
		(be, tem) = (len(ans), ans.copy())
		for i in chrs:
			en = be
			for j in tem:
				if i != j:
					if en == len(s) or s[en] != j:
						ans = -1
						break
					en += 1
			else:
				tem = s[be:en]
				be = en
				continue
		if ans == -1:
			print(-1)
		else:
			print(*ans, ' ', *chrs, sep='')


from collections import defaultdict, OrderedDict
import math

def check(w, o, n, s):
	d = OrderedDict()
	m = len(w)
	w = list(w)
	new = []
	le = m
	for i in range(m):
		d[i] = w[i]
		new.append(w[i])
	for j in o:
		for i in range(m):
			if w[i] == j:
				w[i] = '1'
			elif w[i] != '1':
				new.append(w[i])
	if new == list(s):
		return True
	return False
for _ in range(int(input())):
	s = input()
	d = defaultdict(lambda : 0)
	for i in s:
		d[i] += 1
	order = []
	n = len(s)
	f = 0
	main = -1
	for i in range(n):
		d[s[i]] -= 1
		if d[s[i]] == 0:
			if f == 0:
				main = i
				f = 1
			order.append(s[i])
			d[s[i]]
	d = defaultdict(lambda : 0)
	for i in s:
		d[i] += 1
	d2 = defaultdict(lambda : 0)
	ans = []
	for x in d.keys():
		d2[x] = 0
	for i in range(main):
		d2[s[i]] += 1
		d[s[i]] -= 1
	for i in range(main, n):
		d2[s[i]] += 1
		d[s[i]] -= 1
		if 0 not in d2.values():
			f = 1
			c = 0
			new = []
			for (x, y) in d.items():
				if y % d2[x] != 0:
					f = 0
					break
				new.append(y // d2[x])
			new.sort()
			m = len(new)
			for j in range(m - 1):
				if new[j + 1] - new[j] != 1:
					f = 0
			if f == 1:
				ans.append(i)
	if not ans:
		print(-1)
	else:
		s1 = s[:ans[0] + 1]
		if check(s1, order, n, s):
			print(s1, ''.join(order))
		else:
			print(-1)


import collections
t = int(input())
for case in range(t):
	s = input()
	order = []
	visit = set()
	for i in range(len(s) - 1, -1, -1):
		if s[i] not in visit:
			order.append(s[i])
			visit.add(s[i])
	order = order[::-1]
	cnt = collections.Counter(s)
	d = dict()
	flag = True
	res_len = 0
	for i in range(len(order)):
		if cnt[order[i]] % (i + 1) != 0:
			print(-1)
			flag = False
			break
		d[order[i]] = cnt[order[i]] // (i + 1)
		res_len += d[order[i]]
	if not flag:
		continue
	cur = s[:res_len]
	res = ''
	l = 0
	while cur:
		res += cur
		cur = cur.replace(order[l], '')
		l += 1
	if res == s:
		print(s[:res_len], ''.join(order))
	else:
		print(-1)


def testDual(dual, seen, index):
	tmp = ''
	siz = len(dual)
	ch = seen[index]
	for i in range(siz):
		if dual[i] != ch:
			tmp += dual[i]
	if index + 1 == len(seen):
		return tmp
	return tmp + testDual(tmp, seen, index + 1)
case = int(input())
for t in range(case):
	s = input()
	dic = {}
	siz = len(s) - 1
	seen = []
	for i in range(siz, -1, -1):
		c = s[i]
		if c not in dic:
			seen.append(c)
			dic[c] = 1
		else:
			dic[c] += 1
	noChar = len(seen)
	res = 0
	option = True
	for se in seen:
		if dic[se] % noChar == 0:
			res += dic[se] // noChar
			noChar -= 1
		else:
			option = False
			break
	if option:
		seen.reverse()
		dual = s[:res]
		if dual + testDual(dual, seen, 0) == s:
			print(dual + ' ' + ''.join(seen))
		else:
			print(-1)
	else:
		print(-1)


import sys
inputt = sys.stdin.readline
printt = sys.stdout.write
import math
import functools
from collections import deque
import heapq
from queue import PriorityQueue

def get():
	return inputt().split()

def getint():
	return int(inputt())

def getints():
	return map(int, inputt().split())

def nya(curse, curs):
	if curs == []:
		return True
	i = 0
	for char in curse:
		if char == curs[i]:
			i += 1
			if i == len(curs):
				return True
	return False
for _ in range(getint()):
	t = inputt().strip()
	sett = set(t)
	n = len(sett)
	dic = {}
	for char in sett:
		dic[char] = t.count(char)
	found = []
	foundn = []
	impossible = False
	tt = t
	curs = []
	for i in range(n):
		char = tt.rstrip(''.join(found))[-1]
		found.append(char)
		if dic[char] % (n - i) != 0:
			impossible = True
			break
		k = dic[char] // (n - i)
		foundn.append(k)
		curse = tt[-sum(foundn):]
		if len(set(curse)) != i + 1:
			impossible = True
			break
		if nya(curse, curs):
			curs = curse
		else:
			impossible = True
			break
		tt = tt[:-sum(foundn)]
	if impossible:
		print(-1)
	else:
		print(curs, ''.join(reversed(found)))


import os
import sys
from io import BytesIO, IOBase
import math
from collections import Counter
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
	input = lambda : sys.stdin.readline().rstrip('\r\n')

def simulate(s, order):
	ans = s
	for i in order:
		s = s.replace(i, '')
		ans += s
	return ans
for tt in range(int(input())):
	t = input()
	rev = t[::-1]
	order = [rev[0]]
	orderset = set(order)
	for i in range(1, len(t)):
		if rev[i] != order[-1] and rev[i] not in orderset:
			order.append(rev[i])
			orderset.add(rev[i])
	order = ''.join(order[::-1])
	if len(order) == 1:
		print(t, order[0])
		continue
	cnt = Counter(t)
	og_counts = dict()
	for i in cnt:
		og_counts[i] = cnt[i] // (order.index(i) + 1)
	s = t[:sum(og_counts.values())]
	if simulate(s, order) == t:
		print(s, order)
	else:
		print(-1)


import sys
t = int(sys.stdin.readline())
N = 26

def check(s1, s2):
	s = s1
	for c in s2:
		s1 = s1.replace(c, '')
		s += s1
	return s == t
for _ in range(t):
	t = sys.stdin.readline().strip()
	cnt = {}
	s2 = ''
	for c in t[::-1]:
		if c not in cnt:
			cnt[c] = 1
			s2 += c
		else:
			cnt[c] += 1
	s2 = s2[::-1]
	tot = 0
	flag = True
	for k in range(len(s2)):
		c = s2[k]
		if cnt[c] % (k + 1) != 0:
			flag = False
			break
		else:
			tot += cnt[c] // (k + 1)
	s1 = t[:tot]
	if flag and check(s1, s2):
		print(s1, s2)
	else:
		print(-1)


from collections import defaultdict
from collections import deque
from sys import stdout
for _ in range(int(input())):
	t = list(input())
	m = defaultdict(int)
	q = deque()
	for i in range(len(t) - 1, -1, -1):
		ch = t[i]
		if not ch in m:
			q.appendleft(ch)
		m[ch] += 1
	valid = True
	for i in range(len(q)):
		ch = q[i]
		if m[ch] % (i + 1) != 0:
			valid = False
			break
		m[ch] //= i + 1
	if not valid:
		print(-1)
		continue
	i = 0
	while i < len(t):
		ch = t[i]
		if not ch in m:
			break
		m[ch] -= 1
		if m[ch] == 0:
			del m[ch]
		i += 1
	if len(m) != 0:
		valid = False
	if not valid:
		print(-1)
		continue
	s = t[:i]
	s2 = s
	t2 = s
	for ch in q:
		s2 = ''.join([i for i in s2 if i != ch])
		t2 += s2
	if t2 != t:
		print(-1)
		continue
	print(''.join(t[:i]), ''.join(q))


from collections import defaultdict as dft
t = int(input())
for _ in range(t):
	s = input()
	dct = dft(int)
	res = ''
	for c in s[::-1]:
		if c not in dct:
			res += c
		dct[c] += 1
	res = res[::-1]
	case = 1
	ln = 0
	for i in range(len(res)):
		if dct[res[i]] % (i + 1) != 0:
			case = 0
			break
		ln += dct[res[i]] // (i + 1)
	if case:
		t = []
		temp = s[:ln]
		dct = set()
		i = 0
		while i < len(res):
			for c in temp:
				if c not in dct:
					t.append(c)
			dct.add(res[i])
			i += 1
		if ''.join(t) == s:
			print(s[:ln], res)
		else:
			print(-1)
	else:
		print(-1)


import bisect
import collections
import functools
import itertools
import math
import heapq
import random
import string

def repeat(_func=None, *, times=1):

	def decorator(func):

		@functools.wraps(func)
		def wrapper(*args, **kwargs):
			for _ in range(times):
				func(*args, **kwargs)
		return wrapper
	if _func is None:
		return decorator
	else:
		return decorator(_func)

def unpack(func=int):
	return map(func, input().split())

def l_unpack(func=int):
	return list(map(func, input().split()))

def getint():
	return int(input())

def getmatrix(rows):
	return [list(map(int, input().split())) for _ in range(rows)]

def display_matrix(mat):
	for i in range(len(mat)):
		print(mat[i])
	print('-' * 20)
MOD = 1000000007

def check(text, order, given_t):
	t = text[:]
	t_append = t.append
	removed = set()
	for r in order:
		removed.add(r)
		for c in text:
			if c not in removed:
				t_append(c)
	return ''.join(t) == given_t

@repeat(times=int(input()))
def main():
	s = input()
	freq = collections.Counter(s)
	order = []
	hset = set()
	for c in reversed(s):
		if c not in hset:
			hset.add(c)
			order.append(c)
	order = ''.join(reversed(order))
	count = {}
	for (i, c) in enumerate(order, 1):
		if freq[c] % i != 0:
			print(-1)
			return
		count[c] = freq[c] // i
	for (i, c) in enumerate(s):
		count[c] -= 1
		if count[c] < 0:
			print(-1)
			return
		if all((v == 0 for v in count.values())):
			original = s[:i + 1]
			if check(list(original), order, s):
				print(original, order)
				return
	print(-1)
main()


import sys, collections, copy
tc = int(sys.stdin.readline())
for _ in range(tc):
	arr = list(sys.stdin.readline().rstrip())
	n = len(arr)
	m = len(set(arr))
	temp = set()
	order = dict()
	cnt = m
	res = dict()
	for i in range(n - 1, -1, -1):
		if arr[i] not in temp:
			temp.add(arr[i])
			order[arr[i]] = cnt
			cnt -= 1
		if arr[i] not in res:
			res[arr[i]] = 1
		else:
			res[arr[i]] += 1
	init = dict().fromkeys(res, -1)
	for i in order:
		if res[i] % order[i] == 0:
			init[i] = res[i] // order[i]
	can = True
	for i in init:
		if init[i] == -1:
			can = False
	if not can:
		print(-1)
	else:
		now = []
		for i in range(n):
			if init[arr[i]] > 0:
				now.append(arr[i])
				init[arr[i]] -= 1
		ans = [[] for _ in range(m)]
		idx = 0
		ans[idx] = now
		rev_order = [i for i in order]
		rev_order = rev_order[::-1]
		for i in rev_order:
			for j in ans[idx]:
				for k in j:
					if k == i:
						continue
					ans[idx + 1].append(k)
			ans[idx] = ''.join(ans[idx])
			idx += 1
		if ''.join(ans) == ''.join(arr):
			print(ans[0], ''.join(rev_order))
		else:
			print(-1)


for i in range(int(input())):
	st = input()
	d = {}
	r = ''
	for j in range(len(st) - 1, -1, -1):
		if st[j] in d:
			d[st[j]] += 1
		else:
			r = st[j] + r
			d[st[j]] = 1
	total = sum([d[r[j]] // (j + 1) for j in range(len(r))])
	s = st[:total]
	s_copy = s[:]
	nt = ''
	j = 0
	while j != len(r):
		nt += s_copy
		s_copy = s_copy.replace(r[j], '')
		j += 1
	print(s + ' ' + r) if nt == st else print(-1)


from sys import stdin
inp = stdin.readline
t = int(inp())
for _ in range(t):
	s = input()
	s2 = s[::-1]
	arr = ''
	length = 0
	for c in s2:
		if c not in arr:
			arr += c
	arr = arr[::-1]
	if len(arr) * (len(arr) + 1) // 2 > len(s):
		print(-1)
	else:
		for i in range(len(arr)):
			length += s.count(arr[i]) // (i + 1)
		word = s[:length]
		test = word
		rest = word
		for i in range(len(arr) - 1):
			rest = rest.replace(arr[i], '')
			test += rest
		if test == s:
			print(word, arr)
		else:
			print(-1)


def chek():
	s = input()
	arr = {}
	e = set(s[::-1])
	for i in e:
		arr[i] = s.count(i)
	d = sorted(arr.keys(), key=lambda x: s.rfind(x))
	for i in range(2, len(d) + 1):
		a = d[i - 1]
		if arr[a] % i:
			print(-1)
			return
		arr[a] //= i
	k = sum(arr.values())
	c = s[:k]
	for i in e:
		if c.count(i) != arr[i]:
			print(-1)
			return
	c0 = c
	l = k
	for i in range(1, len(d)):
		k -= arr[d[i - 1]]
		cc = s[l:l + k]
		w = d[i - 1]
		r = 0
		for j in cc:
			while r < len(c) and c[r] == w:
				r += 1
			if r >= len(c) or j != c[r]:
				print(-1)
				return
			r += 1
		while r < len(c) and c[r] == w:
			r += 1
		if r != len(c):
			print(-1)
			return
		c = cc
		l += k
	print(c0, end=' ')
	print(*d, sep='')
t = int(input())
for _ in range(t):
	chek()


for _ in range(int(input())):
	tmp = input()
	z = ''
	p = -1
	for i in range(len(tmp) - 1, -1, -1):
		if tmp[i] in z:
			continue
		else:
			z += tmp[i]
			p = i
	z = z[::-1]
	lan = 0
	for i in range(len(z)):
		lan += tmp.count(z[i]) // (i + 1)
	ans = tmp[:lan]
	check = ''
	tp = ans
	p = 0
	while tp != '':
		check += tp
		tp = tp.replace(z[p], '')
		p += 1
	if check == tmp:
		print(ans, z)
	else:
		print(-1)


from collections import Counter

def solve(s, n):
	temp = s[:]
	s = s[::-1]
	order = ''
	cnt = Counter()
	for c in s:
		if c not in cnt:
			order += c
		cnt[c] += 1
	m = len(order)
	true_l = 0
	for i in range(m):
		true_l += cnt[order[i]] // (m - i)
	order = order[::-1]
	return (temp[:true_l], order)

def order_find(strs, order):
	res = strs[:]
	for c in order:
		temp = ''
		for d in strs:
			if d != c:
				temp += d
				res += d
		strs = temp[:]
	return res
for _ in range(int(input())):
	s = input()
	n = len(s)
	(ori, order) = solve(s, n)
	check = order_find(ori, order)
	if s == check:
		print(ori, order)
	else:
		print(-1)


def confirm(origin, sequence, after):
	x = origin
	for it in sequence:
		origin = origin.replace(it, '')
		x += origin
	if x == after:
		return True
	else:
		return False
for _ in range(int(input())):
	s = input()
	d = dict()
	b = ''
	for it in s[::-1]:
		if not d.get(it):
			b = it + b
			d[it] = True
	l = 0
	division = len(b)
	t = True
	while division > 0:
		k = s.count(b[division - 1])
		if k % division != 0:
			t = False
			break
		l += s.count(b[division - 1]) // division
		division -= 1
	if t and confirm(s[:l], b, s):
		print(f'{s[:l]} {b}')
	else:
		print(-1)


import sys, os
from math import *
from bisect import *
from heapq import *
from collections import *
if os.path.exists('in.txt'):
	sys.stdin = open('in.txt', 'r')
from io import BytesIO, IOBase

def main():
	for _ in range(int(input())):
		t = input()
		possible = True
		c = Counter(t)
		order = []
		k = len(c)
		(n, l) = (len(t) - 1, k)
		f = defaultdict(lambda : 0)
		prev = []
		while n >= 0 and l and possible:
			j = 0
			nn = []
			while n >= 0 and f[t[n]] != 0 and (j < len(prev)):
				if prev[j] != t[n]:
					possible = False
					break
				nn.append(t[n])
				j += 1
				n -= 1
			if n < 0:
				possible = False
				break
			if f[t[n]] == 0:
				if c[t[n]] % l:
					possible = False
					break
				order.append(t[n])
				f[t[n]] = c[t[n]] // l
				(u, h) = (c[t[n]] // l, t[n])
			while n >= 0 and f[t[n]] != 0:
				if t[n] == h:
					if u:
						u -= 1
						nn.append(t[n])
					elif j == len(prev):
						break
					else:
						possible = False
						break
				elif t[n] == prev[j]:
					nn.append(prev[j])
					j += 1
				else:
					possible = False
					break
				n -= 1
				if u == 0 and j == len(prev):
					break
			if u == 0 and j == len(prev):
				pass
			else:
				possible = False
				break
			l -= 1
			prev = nn
		if not possible or n >= 0:
			print(-1)
		else:
			print(''.join(prev[::-1]), ''.join(order[::-1]))
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def MI():
	return map(int, input().split())

def outP(var):
	sys.stdout.write(str(var) + '\n')
MOD = 10 ** 9 + 7
mod = 998244353
main()


import sys

def check(order, t):
	numOcc = [0] * len(order)
	for i in range(len(order)):
		x = t.count(order[i])
		if x % (i + 1) != 0:
			return '-1'
		numOcc[i] = x // (i + 1)
	lenS = sum(numOcc)
	s = t[:lenS]
	for (i, num) in enumerate(numOcc):
		if s.count(order[i]) != num:
			return '-1'
	correctT = ''
	i = 0
	ns = s
	while ns:
		correctT += ns
		ns = ns.replace(order[i], '')
		i += 1
	return '-1' if correctT != t else s + ' ' + ''.join(order)
for _ in range(int(sys.stdin.readline())):
	t = sys.stdin.readline().strip()
	order = []
	tmp = set()
	for c in reversed(t):
		if c not in tmp:
			tmp.add(c)
			order.append(c)
	order.reverse()
	sys.stdout.write(check(order, t) + '\n')


import sys
from math import factorial, gcd
from collections import Counter, deque, defaultdict
from bisect import bisect_left, bisect_right
from heapq import heappop, heappush, heapify, nlargest, nsmallest
from itertools import groupby
from copy import deepcopy
MOD = 10 ** 9 + 7
INF = float('inf')
rl = lambda : list(map(int, sys.stdin.readline().split()))
rs = lambda : sys.stdin.readline().strip()

def reform(s, order):
	t = ''
	for c in order:
		t += s
		s = s.replace(c, '')
	return t
for _ in range(int(input())):
	s = input()
	cur = s
	uniq = len(set(s))
	n = 0
	order = ''
	org = ''
	ok = True
	for i in range(uniq):
		last = cur[-1]
		order += last
		if s.count(last) % (uniq - i) != 0:
			ok = False
			break
		else:
			n += s.count(last) // (uniq - i)
		cur = cur.replace(last, '')
	if ok == False:
		print(-1)
		continue
	order = order[::-1]
	org = s[:n]
	if reform(org, order) == s:
		print(org, order)
	else:
		print(-1)


from sys import stdin, stdout
import heapq
from collections import defaultdict
import math
import bisect
import io, os

def repli(ss, ans):
	new = []
	for s in ss:
		new.append(s)
	t = ss
	for c in ans:
		temp = []
		for s in t:
			if c != s:
				new.append(s)
				temp.append(s)
		t = temp
	return ''.join(new)

def main():
	t = int(stdin.readline())
	for T in range(t):
		cnt = [0] * 27
		cnt_div = [-1] * 27
		total = 0
		ans = []
		is_ok = True
		ss = stdin.readline().strip()
		for S in reversed(ss):
			s = ord(S) - 97
			cnt[s] += 1
			if cnt[s] == 1:
				cnt_div[s] = total
				total += 1
				ans.append(S)
		total_cnt = 0
		for i in range(27):
			if cnt_div[i] == -1:
				continue
			if cnt[i] % (total - cnt_div[i]) != 0:
				is_ok = False
				break
			cnt[i] = cnt[i] // (total - cnt_div[i])
			total_cnt += cnt[i]
		if not is_ok:
			stdout.write('-1\n')
			continue
		base = ss[:total_cnt]
		ans = ''.join(reversed(ans))
		rep = repli(base, ans)
		if rep != ss:
			stdout.write('-1\n')
			continue
		stdout.write(base + ' ' + ans + '\n')
main()


from collections import defaultdict, deque, Counter
from heapq import heapify, heappop, heappush
import math
from copy import deepcopy
from itertools import combinations, permutations, product, combinations_with_replacement
from bisect import bisect_left, bisect_right
import sys

def input():
	return sys.stdin.readline().rstrip()

def getN():
	return int(input())

def getNM():
	return map(int, input().split())

def getList():
	return list(map(int, input().split()))

def getListGraph():
	return list(map(lambda x: int(x) - 1, input().split()))

def getArray(intn):
	return [int(input()) for i in range(intn)]
mod = 10 ** 9 + 7
MOD = 998244353
inf = float('inf')
eps = 10 ** (-10)
dy = [0, 1, 0, -1]
dx = [1, 0, -1, 0]
T = getN()
for _ in range(T):
	S = input()
	N = len(S)
	d = {}
	add = []
	for i in range(N - 1, -1, -1):
		if not S[i] in d:
			d[S[i]] = 1
			add.append(S[i])
	add = list(reversed(add))

	def f(x):
		s = S[:x]
		t = ''
		for i in range(len(add)):
			t += s
			s = s.replace(add[i], '')
		return (len(t), t)
	ok = 0
	ng = N + 1
	while abs(ng - ok) > 1:
		mid = (ok + ng) // 2
		if f(mid)[0] > N:
			ng = mid
		else:
			ok = mid
	if f(ok)[1] == S:
		print(S[:ok], ''.join(add))
	else:
		print(-1)


from __future__ import division, print_function
import os, sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
from bisect import bisect_left as lower_bound, bisect_right as upper_bound

def so():
	return int(input())

def st():
	return input()

def mj():
	return map(int, input().strip().split(' '))

def msj():
	return map(str, input().strip().split(' '))

def le():
	return list(map(int, input().split()))

def lebe():
	return list(map(int, input()))

def dmain():
	sys.setrecursionlimit(1000000)
	threading.stack_size(1024000)
	thread = threading.Thread(target=main)
	thread.start()

def joro(L):
	return ''.join(map(str, L))

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def isprime(n):
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			return False
	return True

def npr(n, r):
	return factorial(n) // factorial(n - r) if n >= r else 0

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(n - r)) if n >= r else 0

def lower_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] >= num:
			answer = middle
			end = middle - 1
		else:
			start = middle + 1
	return answer

def upper_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] <= num:
			answer = middle
			start = middle + 1
		else:
			end = middle - 1
	return answer

def abs(x):
	return x if x >= 0 else -x

def binary_search(li, val, lb, ub):
	ans = -1
	while lb <= ub:
		mid = (lb + ub) // 2
		if li[mid] > val:
			ub = mid - 1
		elif val > li[mid]:
			lb = mid + 1
		else:
			ans = mid
			break
	return ans

def kadane(x):
	sum_so_far = 0
	current_sum = 0
	for i in x:
		current_sum += i
		if current_sum < 0:
			current_sum = 0
		else:
			sum_so_far = max(sum_so_far, current_sum)
	return sum_so_far

def pref(li):
	pref_sum = [0]
	for i in li:
		pref_sum.append(pref_sum[-1] + i)
	return pref_sum

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	li = []
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	for p in range(2, len(prime)):
		if prime[p]:
			li.append(p)
	return li

def primefactors(n):
	factors = []
	while n % 2 == 0:
		factors.append(2)
		n //= 2
	for i in range(3, int(sqrt(n)) + 1, 2):
		while n % i == 0:
			factors.append(i)
			n //= i
	if n > 2:
		factors.append(n)
	return factors

def read():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def tr(n):
	return n * (n + 1) // 2

def iu():
	import sys
	input = sys.stdin.buffer.readline
	import math as my
	t = st()
	p = {}
	op = ''
	c = 0
	k = len(t) - 1
	zp = ''
	while k >= 0:
		if t[k] not in p:
			op = t[k] + op
			p[t[k]] = 1
		else:
			p[t[k]] += 1
		k -= 1
	for k in range(len(op)):
		z = 1 + k
		c = c + p[op[k]] // z
	ho = t[:c]
	uo = ho[:]
	k = 0
	while len(op) != k:
		zp += uo
		uo = uo.replace(op[k], '')
		k = 1 + k
	if zp != t:
		print(-1)
	else:
		print(ho + ' ' + op)

def main():
	for i in range(so()):
		iu()
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


t = int(input())
for _ in range(t):
	g = input()
	s = len(g)
	ll = ''
	lli = -1
	mark = [0] * 26
	ans = ''
	te = -1
	for i in reversed(range(s)):
		if mark[ord(g[i]) - ord('a')]:
			continue
		mark[ord(g[i]) - ord('a')] += 1
		lli = i
		ll = g[i]
		ans = g[i] + ans
	su = 0
	ans1 = ''
	for i in g:
		for x in range(len(ans)):
			if i == ans[x]:
				break
		if su >= s:
			break
		ans1 = ans1 + i
		su = su + x + 1
	if su != s:
		print('-1')
	else:
		s = ans1
		fin = s
		for i in range(len(ans)):
			s = s.replace(ans[i], '')
			fin = fin + s
		if fin == g:
			print(ans1, ans)
		else:
			print('-1')


import sys, os, io
from sys import stdin
import math
from collections import defaultdict
from heapq import heappush, heappop, heapify
from bisect import bisect_left, bisect_right
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
alphabets = list('abcdefghijklmnopqrstuvwxyz')
from types import GeneratorType

def bootstrap(f, stack=[]):

	def wrappedfunc(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		else:
			to = f(*args, **kwargs)
			while True:
				if type(to) is GeneratorType:
					stack.append(to)
					to = next(to)
				else:
					stack.pop()
					if not stack:
						break
					to = stack[-1].send(to)
			return to
	return wrappedfunc

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(int(i))
			n = n / i
	if n > 2:
		l.append(n)
	return list(set(l))

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def sieveForSmallestPrimeFactor():
	MAXN = 100001
	spf = [0 for i in range(MAXN)]
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, math.ceil(math.sqrt(MAXN))):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i
	return spf

def getPrimeFactorizationLOGN(x):
	spf = sieveForSmallestPrimeFactor()
	ret = list()
	while x != 1:
		ret.append(spf[x])
		x = x // spf[x]
	return ret

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime

def si():
	return input()

def divideCeil(n, x):
	if n % x == 0:
		return n // x
	return n // x + 1

def ii():
	return int(input())

def li():
	return list(map(int, input().split()))
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def satisfy(freq, curfreq, order, ind):
	for xx in range(len(order) - 1, -1, -1):
		i = order[xx]
		x = curfreq[i]
		if x * xx != freq[i]:
			return False
	return True

def check(t, s, order):
	ans = []
	ss = set()
	for i in range(len(order) - 1, -1, -1):
		for j in range(len(s)):
			if s[j] not in ss:
				ans.append(s[j])
		ss.add(order[i])
	return ''.join(ans) == ''.join(t)

def solve():
	s = list(si())
	n = len(s)
	order = []
	ss = set()
	ff = []
	for i in range(n - 1, -1, -1):
		if s[i] not in ss:
			ff.append(s[i])
			order.append(ord(s[i]) - 97)
			ss.add(s[i])
	order.reverse()
	freq = [0] * 26
	for i in s:
		freq[ord(i) - 97] += 1
	curfreq = [0] * 26
	for i in range(n):
		curfreq[ord(s[i]) - 97] += 1
		freq[ord(s[i]) - 97] -= 1
		if satisfy(freq, curfreq, order, i):
			if check(s, s[:i + 1], ff):
				print(''.join(s[:i + 1]), ''.join(ff[::-1]))
				return
	print(-1)
t = 1
t = ii()
for _ in range(t):
	solve()


from collections import defaultdict
t = int(input())

def solve():
	t = input()
	L = len(t)
	set_n = set()
	letters = []
	d = defaultdict(int)
	for i in range(L - 1, -1, -1):
		if t[i] not in set_n:
			set_n.add(t[i])
			letters.append(t[i])
		d[t[i]] += 1
	test = defaultdict(int)
	count = 0
	for (i, l) in enumerate(letters):
		if d[l] % (len(letters) - i) != 0:
			print(-1)
			return
		test[l] = d[l] // (len(letters) - i)
		count += test[l]
	s = t[:count]
	if len(s) != count:
		print(-1)
		return
	cur = s
	c = len(letters)
	l = count
	while c != 0:
		next = cur.replace(letters[c - 1], '')
		if next == t[l:l + (len(cur) - test[letters[c - 1]])]:
			l = l + (len(cur) - test[letters[c - 1]])
			cur = next
			c -= 1
		else:
			print(-1)
			return
	if c == 0 and l == len(t):
		print(s, ''.join([str(x) for x in letters[::-1]]))
	else:
		print(-1)
for _ in range(t):
	solve()


def makestr(a, b):
	addedset = set()
	ans = list(a)
	for el in b:
		addedset.add(el)
		for word in a:
			if word not in addedset:
				ans.append(word)
	return ''.join(ans)

def func(s):
	words = set()
	word = []
	for i in range(len(s) - 1, -1, -1):
		if s[i] not in words:
			words.add(s[i])
			word.append(s[i])
	if len(word) <= 1:
		return (s, word[0])
	count = 0
	pos = 0
	for i in range(len(s)):
		if s[i] == word[-2]:
			pos = i
			count += 1
	if count % 2:
		return (-1, -1)
	count3 = 0
	count2 = 0
	pos2 = 0
	i = 0
	while count2 < count / 2:
		if s[i] == word[-2]:
			pos2 = i
			count2 += 1
		if s[i] == word[-1]:
			count3 += 1
		i += 1
	word.reverse()
	a = ''.join(s[0:pos - pos2 + count3])
	b = ''.join(word)
	if s == makestr(a, b):
		return (a, b)
	else:
		return (-1, -1)

def main():
	loop = int(input())
	ss = []
	for _ in range(loop):
		ss.append(input())
	for i in range(loop):
		(s, a) = func(ss[i])
		if a == -1:
			print(-1)
		else:
			print(s + ' ' + a)
main()


for input_number in range(int(input())):
	s = input()
	s = s[::-1]
	d = dict()
	for i in range(len(s)):
		d[s[i]] = d.get(s[i], 0) + 1
	s1 = ''.join([x for x in d])
	k = 0
	s2 = ''
	for i in range(len(d)):
		if d[s1[i]] % (len(d) - i) != 0:
			print(-1)
			break
		c = 0
		count = 0
		s3 = ''
		for j in range(len(s2) + d[s1[i]] // (len(d) - i)):
			if s[k + j] == s1[i]:
				s3 += s[k + j]
				count += 1
				if count > d[s1[i]] // (len(d) - i):
					break
			else:
				if c >= len(s2) or s[k + j] != s2[c]:
					break
				s3 += s[k + j]
				c += 1
		else:
			k += len(s2) + d[s1[i]] // (len(d) - i)
			s2 = s3
			continue
		print(-1)
		break
	else:
		print(s2[::-1], s1[::-1])


import sys
import os
import math
from io import BytesIO, IOBase
from collections import defaultdict, Counter, deque
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
t = int(input())
for i in range(t):
	s = input()
	l = len(s)
	ans2 = ''
	s1 = set()
	cur = 0
	d = defaultdict(int)
	for j in range(l - 1, -1, -1):
		s1.add(s[j])
		d[s[j]] += 1
		if len(s1) > cur:
			ans2 += s[j]
			cur += 1
	ans2 = ans2[::-1]
	l1 = len(d)
	su = 0
	for j in range(l1, 0, -1):
		if d[ans2[j - 1]] % j == 0:
			d[ans2[j - 1]] //= j
			su += d[ans2[j - 1]]
		else:
			print(-1)
			break
	else:
		ans1 = s[:su]
		cur = list(ans1)
		s1 = set()
		for j in ans2:
			s1.add(j)
			for k in ans1:
				if k not in s1:
					cur.append(k)
		if ''.join(cur) == s:
			print(ans1, ans2)
		else:
			print(-1)


import math

def solve(s):
	letters = {}
	uniques = []
	for i in range(len(s)):
		ref = len(s) - 1 - i
		if uniques.count(s[ref]) == 0:
			uniques.append(s[ref])
			letters[s[ref]] = 1
		else:
			letters[s[ref]] += 1
	tot = 0
	removed = ''
	for i in range(len(uniques)):
		ref = len(uniques) - 1 - i
		removed = removed + uniques[ref]
		letters[uniques[ref]] = int(letters[uniques[ref]] / (i + 1))
		tot += letters[uniques[ref]]
	init = s[:tot]
	init2 = init
	test = ''
	for i in range(len(removed)):
		test += init2
		init2 = init2.replace(removed[i], '')
	if test == s:
		print(init, removed)
	else:
		print(-1)
tot = int(input())
for i in range(tot):
	solve(input())


import sys
input = lambda : sys.stdin.readline().rstrip('\r\n')
from collections import Counter
T = int(input())
for _ in range(T):
	t = input()
	lset = set(t)
	del_ord = []
	del_set = set()
	i = -1
	res = 0
	while del_set != lset:
		let = t[i]
		if let not in del_set:
			del_set.add(let)
			del_ord.append(let)
		i -= 1
	let_cnt = Counter(t)
	orig_counter = {}
	for (i, let) in enumerate(reversed(del_ord), start=1):
		resid = let_cnt[let] % i
		if resid > 0:
			res = -1
			break
		orig_counter[let] = let_cnt[let] // i
	if res != -1:
		w_len = sum(orig_counter.values())
		word = t[:w_len]
		(test_word, test_idx, test_cnt) = (word, len(word), len(word))
		for (i, let) in enumerate(reversed(del_ord)):
			next_test = test_word.replace(let, '')
			next_idx = test_idx + len(test_word) - orig_counter[let]
			if t[test_idx:next_idx] != next_test:
				res = -1
				break
			test_word = next_test
			test_idx = next_idx
	if res == -1:
		print(res)
		continue
	del_ord = ''.join(map(str, reversed(del_ord)))
	print(word, del_ord)


import sys
import math
from math import factorial, inf, gcd, sqrt
from heapq import *
from functools import *
from itertools import *
from collections import *
from typing import *
from bisect import *
import random
from sys import stdin, stdout
sys.setrecursionlimit(10 ** 5)

def inp():
	return stdin.readline().strip()

def iinp():
	return int(inp())

def mp():
	return map(int, inp().split())

def lmp():
	return list(mp())

def f(s, p, h, v):
	if len(v) == 1:
		if all((i == v[p] for i in v[p:])):
			return s[p:]
		return ''
	cur = v[-1]
	l = h[cur]
	r = h[v[-2]]
	pos = []
	for i in range(p, r + 1):
		if s[i] == v[-2]:
			pos.append(i)
	if len(pos) % 2 != 0:
		return ''
	temp = pos[len(pos) // 2 - 1]
	i = r
	j = temp
	while j >= p:
		if s[j] != cur:
			if i <= temp or i <= l or s[j] != s[i]:
				return ''
			i -= 1
		j -= 1
	j = temp
	k = r
	while j < i:
		if s[j] != cur:
			if k >= len(s) or s[j] != s[k]:
				return ''
			k += 1
		j += 1
	return s[p:i + 1]

def g(s, p, t, v, p2):
	while p2 < len(v):
		c = []
		for i in t:
			if i != v[p2]:
				c.append(i)
		n = len(c)
		if p + n > len(s) or s[p:p + n] != ''.join(c):
			return False
		t = c
		p += n
		p2 += 1
	return p == len(s)
ti = int(input())
for i in range(ti):
	s = inp()
	n = len(s)
	h = {}
	v = []
	for i in reversed(range(n)):
		if s[i] not in h:
			h[s[i]] = i
			v.append(s[i])
	ans = f(s, 0, h, v)
	v = v[::-1]
	if ans == '' or not g(s, len(ans), ans, v, 0):
		print(-1)
	else:
		print(ans, ''.join(v))


import sys
from collections import defaultdict
input = sys.stdin.readline

def ri():
	return [int(i) for i in input().split()]

def rs():
	return input().split()[0]

def get_t(s: str, order):
	t = ''
	for c in order:
		t += s
		s = s.replace(c, '')
	return t

def get_order(s):
	done = [0] * 200
	order = ''
	for c in reversed(s):
		if done[ord(c)] == 0:
			order = c + order
			done[ord(c)] = 1
	return order

def main():
	t = ri()[0]
	for _ in range(t):
		T = rs()
		order = get_order(T)
		mi = 1
		mx = len(T) + 1
		m = (mi + mx) // 2
		for i in range(30):
			t = get_t(T[:m], order)
			if len(t) < len(T):
				mi = m
			elif len(t) > len(T):
				mx = m
			elif len(t) == len(T) and t == T:
				print(T[:m], order)
				break
			else:
				print(-1)
				break
			m = (mi + mx) // 2
			if mx - mi <= 1:
				print(-1)
				break
main()


class Solution:

	def restoreOriginal(self, word):
		alphabets = {}
		order_removed = []
		for i in range(len(word) - 1, -1, -1):
			if word[i] not in alphabets:
				alphabets[word[i]] = 1
				order_removed.append(word[i])
			else:
				alphabets[word[i]] += 1
		order_removed.reverse()
		order_string = ''
		multiple_of_letters = 1
		for i in order_removed:
			if alphabets[i] % multiple_of_letters != 0:
				return [-1]
			else:
				alphabets[i] = alphabets[i] // multiple_of_letters
				order_string += i
			multiple_of_letters += 1
		ans = ''
		for i in word:
			if alphabets[i] == 0:
				break
			else:
				ans += i
				alphabets[i] -= 1
		create_word = ans
		psuedo_ans = ans
		for i in order_removed:
			t = ''
			for j in psuedo_ans:
				if i != j:
					t += j
			create_word += t
			psuedo_ans = t
		if create_word != word:
			return [-1]
		else:
			return (ans, order_string)
n = int(input())
while n > 0:
	word = input()
	obj = Solution()
	ans = obj.restoreOriginal(word)
	if len(ans) == 1:
		print(ans[0])
	else:
		print(ans[0], ans[1])
	n = n - 1


import math
import os
import random
import re
import sys

def init_string_dict(s):
	a = dict()
	for i in range(1, len(s)):
		for j in range(i, len(s)):
			a[s[i:j + 1]] = i
	return a

def get_last_location(s):
	a = dict()
	for i in range(len(s)):
		a[s[i]] = i
	return a

def count_char(s, s_dict: dict):
	a = dict()
	for (key, _) in s_dict.items():
		a[key] = 0
	for i in range(len(s)):
		a[s[i]] += 1
	return a

def rebuild_string(s: str, order: str):
	t = s
	for i in order:
		s = s.replace(i, '')
		t += s
	return t

def s_length(s_loc: dict, s_cnt: dict, s_order: list):
	s_len = 0
	for (i, value) in enumerate(s_order):
		char = value[1]
		s_len += s_cnt[char] // (i + 1)
	return int(s_len)
n = int(input())
for i in range(n):
	s1 = input()
	s1_loc = get_last_location(s1)
	if len(s1_loc) == 1:
		print(s1, s1[0])
		continue
	s1_cnt = count_char(s1, s1_loc)
	s1_order = sorted([(value, key) for (key, value) in s1_loc.items()])
	s1_origin_length = s_length(s1_loc, s1_cnt, s1_order)
	s1_origin = s1[:s1_origin_length]
	s1_order_str = ''.join([i[1] for i in s1_order])
	if s1 != rebuild_string(s1_origin, s1_order_str):
		print(-1)
	else:
		print(s1_origin, s1_order_str)


from collections import defaultdict, deque, Counter
from sys import stdin, stdout
from heapq import heappush, heappop
import math
import io
import os
import math
import bisect

def isPrime(x):
	for i in range(2, x):
		if i * i > x:
			break
		if x % i == 0:
			return False
	return True

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(int(i))
			n = n / i
	if n > 2:
		l.append(n)
	return list(set(l))

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime

def digits(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def ceil(n, x):
	if n % x == 0:
		return n // x
	return n // x + 1

def mapin():
	return map(int, input().split())
t = int(input())
for _ in range(t):
	l = list(input())
	n = len(l)
	o = len(set(l))
	b = ''
	d = [-1] * 26
	e = [0] * 26
	for i in range(n - 1, -1, -1):
		if d[ord(l[i]) - ord('a')] == -1:
			d[ord(l[i]) - ord('a')] = i
			b += l[i]
		e[ord(l[i]) - ord('a')] += 1
	b = b[::-1]
	k = len(b)
	fl = 1
	f = 0
	for i in range(1, k + 1):
		x = b[i - 1]
		if e[ord(x) - ord('a')] % i != 0:
			fl = 0
		else:
			f += e[ord(x) - ord('a')] // i
	s = l[0:f]
	result = s[:]
	for c in b:
		temp = []
		for d in s:
			if d != c:
				temp.append(d)
				result.append(d)
		s = temp
	if result != l:
		fl = 0
	if fl == 0:
		print(-1)
	else:
		print(''.join(l[0:f]), b)


cases = int(input())
while cases != 0:
	cases -= 1
	count = 0
	num = 1
	flag = 0
	l = []
	s = input()
	for i in range(len(s)):
		l.append(s[i])
	d = {}
	for i in l:
		if i in d:
			d[i] += 1
		else:
			d[i] = 1
	order_lst = []
	for i in range(len(l) - 1, -1, -1):
		if l[i] not in order_lst:
			order_lst.append(l[i])
		else:
			continue
	order_lst.reverse()
	for i in order_lst:
		if d[i] % num == 0:
			count += d[i] // num
			num += 1
		else:
			print(-1)
			flag = 1
			break
	if flag == 1:
		continue
	lst = l[:count]
	lst_org = l[:count]
	for i in order_lst:
		lst_org = [a for a in lst_org if a != i]
		for i in lst_org:
			lst.append(i)
	if lst == l:
		for i in l[:count]:
			print(i, end='')
		print(' ', end='')
		for i in order_lst:
			print(i, end='')
		print()
	else:
		print(-1)


def check(word, symbols, refer):
	(word_new, w_n) = (word, word)
	for s in symbols:
		if s in word:
			w_n = w_n.replace(s, '')
			word_new = word_new + w_n
		else:
			return False
	if refer != word_new:
		return False
	return True
for _ in range(int(input())):
	t = input()
	t_set = set(t)
	if len(t_set) == 0:
		print('')
	elif len(t_set) == 1:
		print(t, list(t_set)[0])
	else:
		symbols = ''.join(sorted(t_set, key=t.rindex))
		symbolcount_dict = dict.fromkeys(list(symbols))
		for (i, symbol) in enumerate(symbols, 1):
			key_val = t.count(symbol) / i
			if key_val % 1 != 0:
				print(-1)
				break
			symbolcount_dict[symbol] = key_val
		else:
			(i, word) = (0, '')
			flag = False
			while not flag:
				try:
					symbolcount_dict[t[i]] = symbolcount_dict[t[i]] - 1
				except:
					print(-1)
					break
				word = word + t[i]
				try:
					flag = all((val == 0 for val in symbolcount_dict.values()))
				except:
					print('All')
					break
				i += 1
			else:
				if check(word, symbols, t):
					print(word, symbols)
				else:
					print(-1)


from sys import stdin, stdout
input = stdin.readline
t = int(input())
for _ in range(t):
	q = input().strip()
	freq = {}
	for i in q:
		freq[i] = freq.get(i, 0) + 1
	round = len(freq)
	new = set()
	actual_freq = {}
	flg = 0
	seq = []
	for i in q[::-1]:
		if i not in new:
			seq.append(i)
			new.add(i)
			if round == 0 or freq[i] % round:
				flg = 1
				break
			actual_freq[i] = freq[i] // round
			round -= 1
	if flg:
		print(-1)
	else:
		sum_all = sum(actual_freq.values())
		ans = q[:sum_all]
		to_check = ans
		for i in seq[::-1]:
			ans = ans.replace(i, '')
			to_check += ans
		if to_check == q:
			print(q[:sum_all], ''.join(seq)[::-1])
		else:
			print(-1)


def fun(t):
	n = len(t)
	h = {}
	order = ''
	for i in range(n - 1, -1, -1):
		if t[i] not in h:
			h[t[i]] = 1
			order = t[i] + order
		else:
			h[t[i]] += 1
	cnt = 0
	for i in range(len(order)):
		if h[order[i]] % (i + 1) != 0:
			print(-1)
			return
		else:
			cnt = cnt + h[order[i]] // (i + 1)
	s = t[:cnt]
	ts = s
	ans = s
	for i in range(len(order)):
		temp = s.replace(order[i], '')
		ts += temp
		s = temp
	if ts == t:
		print(ans, order)
		return
	else:
		print(-1)
		return
t = int(input())
for i in range(t):
	t = input()
	fun(t)


def solve():
	s = input()
	m = set()
	a = []
	for c in s[::-1]:
		if c not in m:
			a.append(c)
			m.add(c)
	a = a[::-1]
	d = {c: 0 for c in a}
	for c in s:
		d[c] += 1
	for (i, c) in enumerate(a, 1):
		if d[c] % i:
			print(-1)
			return
		d[c] //= i
	i = 0
	ans = s[:sum(d.values())]
	ans1 = ans
	for j in range(len(a)):
		if s[i:i + len(ans)] != ans:
			print(-1)
			return
		i += len(ans)
		ans = ans.replace(a[j], '')
	print(ans1, ''.join(a))
import sys
input = lambda : sys.stdin.readline().rstrip()
t = int(input())
for i in range(t):
	solve()


import sys, os.path
from collections import *
from heapq import *
from copy import *
from bisect import *
import math
mod = 10 ** 9 + 7
input = lambda : sys.stdin.readline().rstrip()
read = lambda : map(int, input().split())
inf = float('inf')
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
t = int(input())
for i in range(t):
	st = input()
	d = {}
	r = ''
	for j in range(len(st) - 1, -1, -1):
		if st[j] in d:
			d[st[j]] += 1
		else:
			r = st[j] + r
			d[st[j]] = 1
	total = 0
	for j in range(len(r)):
		total += d[r[j]] // (j + 1)
	s = st[:total]
	s_copy = s[:]
	nt = ''
	j = 0
	while j != len(r):
		nt += s_copy
		s_copy = s_copy.replace(r[j], '')
		j += 1
	if nt == st:
		print(s + ' ' + r)
	else:
		print(-1)


from math import *
from collections import *
from functools import *
from bisect import *
from itertools import *
from heapq import *
inf = float('inf')
ninf = -float('inf')
ip = input
alphal = 'abcdefghijklmnopqrstuvwxyz'
alphau = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
mod = 10 ** 9 + 7

def ipl():
	return list(map(int, ip().split()))

def ipn():
	return int(ip())

def ipf():
	return float(ip())

def ptrres(a):
	for i in a:
		print(i, end=' ')
	print()

def solve():
	t = ip()
	n = len(t)
	h = Counter(t)
	c = len(set(t))
	se = set()
	prev = ''
	r = ''
	i = n - 1
	while c:
		st = i
		en = i
		while st >= 0 and t[st] in se:
			st -= 1
		if st < 0:
			print(-1)
			return
		e = t[st]
		r += e
		if h[e] % c == 0:
			o = h[e] / c
		else:
			print(-1)
			return
		se.add(e)
		k = len(prev) - 1
		j = en
		while j >= 0 and (k >= 0 or o > 0):
			if t[j] not in se:
				print(-1)
				return
			if t[j] == e:
				o -= 1
			else:
				if k < 0 or t[j] != prev[k]:
					print(-1)
					return
				k -= 1
			j -= 1
		prev = t[j + 1:i + 1]
		i = j
		c -= 1
	print(prev, r[::-1])
t = ipn()
for _ in range(t):
	solve()


t = int(input())
for _ in range(t):
	s = list(str(input()))
	sset = set(s)
	v = len(sset)
	ans2 = ['a' for _ in range(v)]
	pointa = 1
	for i in range(len(s) - 1, -1, -1):
		if s[i] in sset:
			sset.remove(s[i])
			ans2[-pointa] = s[i]
			pointa += 1
	numbers = [0 for _ in range(v)]
	sign = True
	for i in range(v):
		k = s.count(ans2[i])
		if k % (i + 1) != 0:
			sign = False
			break
		numbers[i] = k // (i + 1)
	if not sign:
		print(-1)
		continue
	length = sum(numbers)
	ans = s[:length]
	check = set([])
	pointa = 0
	for i in range(v):
		for j in range(length):
			if ans[j] not in check:
				if ans[j] != s[pointa]:
					sign = False
					break
				pointa += 1
		if not sign:
			break
		check.add(ans2[i])
	if not sign:
		print(-1)
		continue
	print(''.join(ans), ''.join(ans2))


import sys
from collections import Counter

def rall():
	return sys.stdin.readlines()

def rl():
	return sys.stdin.readline().strip()

def rl_types(types):
	str_list = [x for x in sys.stdin.readline().strip().split(' ')]
	return [types[i](str_list[i]) for i in range(len(str_list))]

def pr(something):
	sys.stdout.write(str(something) + '\n')

def pra(array):
	sys.stdout.write(' '.join([str(x) for x in array]) + '\n')

def solve(array):
	return array
NT = int(rl())
for ti in range(NT):
	orig = rl()
	s = [c for c in orig]
	order = []
	while True:
		nxt = s[-1]
		order.append(nxt)
		s = [c for c in s if not c == nxt]
		if len(s) == 0:
			break
	freqs = Counter(orig)
	lo = len(order)
	wlen = 0
	valid = True
	for (i, c) in enumerate(order):
		lrem = lo - i
		if not freqs[c] % lrem == 0:
			valid = False
			break
		wlen += freqs[c] // lrem
	if not valid:
		pr(-1)
	else:
		word = orig[:wlen]
		wtest = word
		order = ''.join(order[::-1])
		proper = ''
		for co in order:
			proper += wtest
			wtest = ''.join([cw for cw in wtest if not cw == co])
		if proper == orig:
			pr(f'{word} {order}')
		else:
			pr(-1)


from collections import Counter

def generate_sentence(sentence, deleted_chars):
	res = sentence
	for char in deleted_chars:
		sentence = sentence.replace(char, '')
		res += sentence
	return res
n = int(input())
for _ in range(n):
	s = input()
	chars_count = Counter(s)
	tmp = s
	sorted_deleted_chars = []
	while tmp:
		c = tmp[-1]
		sorted_deleted_chars.append(c)
		tmp = tmp.replace(c, '')
	sorted_deleted_chars.reverse()
	k = 0
	for (i, ch) in enumerate(sorted_deleted_chars):
		c = chars_count[sorted_deleted_chars[i]] / (i + 1)
		if c != int(c):
			k = -1
			break
		k += int(c)
	if k == -1 or generate_sentence(s[:k], sorted_deleted_chars) != s:
		print(-1)
	else:
		print(s[:k], ''.join(sorted_deleted_chars))


from collections import defaultdict
import sys
input = sys.stdin.readline
q = int(input())
for _ in range(q):
	t = list(input().rstrip())
	n = len(t)
	x = []
	xs = set()
	cnt = defaultdict(lambda : 0)
	for i in range(n - 1, -1, -1):
		ti = t[i]
		cnt[ti] += 1
		if not ti in xs:
			xs.add(ti)
			x.append(ti)
	l = len(x)
	ok = 1
	for i in x:
		if cnt[i] % l:
			ok = 0
		cnt[i] //= l
		l -= 1
	if not ok:
		print(-1)
		continue
	s = []
	for i in t:
		if cnt[i]:
			s.append(i)
			cnt[i] -= 1
		else:
			break
	t0 = []
	ng = set()
	x.reverse()
	l = len(x)
	for i in x:
		for j in s:
			if not j in ng:
				t0.append(j)
		ng.add(i)
	if not ''.join(t) == ''.join(t0):
		print(-1)
		continue
	print(''.join(s), ''.join(x))


from sys import stdin, stdout
input = stdin.readline

def output(answer):
	stdout.write('{}\n'.format(answer))
for _ in range(int(input())):
	s = input()
	if s[-1] == '\n':
		s = s[:-1]
	n = len(s)
	flag = False
	counter = [0 for i in range(26)]
	order = []
	visited = [False for i in range(26)]
	for i in range(n - 1, -1, -1):
		if visited[ord(s[i]) - 97] == False:
			order.append(s[i])
			visited[ord(s[i]) - 97] = True
		counter[ord(s[i]) - 97] += 1
	div = len(order)
	for char in order:
		val = counter[ord(char) - 97]
		if val % div != 0:
			flag = True
			break
		counter[ord(char) - 97] = val // div
		div -= 1
	if flag == True:
		output(-1)
		continue
	total = sum(counter)
	data = list(counter)
	index = None
	for i in range(n):
		if data[ord(s[i]) - 97] == 0:
			flag = True
			break
		data[ord(s[i]) - 97] -= 1
		total -= 1
		if total == 0:
			index = i
			break
	if flag == True:
		output(-1)
		continue
	m = index + 1
	order = order[::-1]
	k = len(order)
	itr = 0
	itr_t = 0
	itr_a = 0
	removed = [False for i in range(26)]
	while itr < k:
		itr_a = 0
		while itr_a < m and itr_t < n:
			if removed[ord(s[itr_a]) - 97] == True:
				itr_a += 1
			elif s[itr_a] == s[itr_t]:
				itr_a += 1
				itr_t += 1
			else:
				flag = True
				break
		if flag == True:
			break
		removed[ord(order[itr]) - 97] = True
		itr += 1
		if itr_t == n and itr < k:
			flag = True
			break
	if flag == True:
		output(-1)
		continue
	for i in range(index + 1):
		stdout.write(s[i])
	stdout.write(' ')
	for i in order:
		stdout.write(i)
	stdout.write('\n')


from collections import Counter

def checksol(s, ord):
	ans = ''
	s = str(s)
	for c in ord:
		ans += s
		s = s.replace(c, '')
	return ans

def main():
	s = input()
	order = []
	coutn = dict(Counter(s))
	for i in range(len(s) - 1, -1, -1):
		if s[i] not in order:
			order.insert(0, s[i])
	le = 0
	for i in range(len(order)):
		a = coutn[order[i]] // (i + 1)
		le += a
	if s == checksol(s[:le], order[:]):
		print(s[:le], ''.join(order))
		return
	print(-1)
	pass
t = int(input())
for _ in range(t):
	main()


import sys
input = lambda : sys.stdin.readline().rstrip('\r\n')
inp = lambda : list(map(int, sys.stdin.readline().rstrip('\r\n').split()))
mod = 10 ** 9 + 7
Mod = 998244353
INF = float('inf')
import math
from bisect import *
from heapq import *
from collections import defaultdict as dd
from collections import OrderedDict as odict
from collections import Counter as cc
from collections import deque
from itertools import groupby
sys.setrecursionlimit(20 * 20 * 20 * 20 + 10)

def order(string):
	s = set()
	st = ''
	for i in string[::-1]:
		if i not in s:
			st += i
			s.add(i)
	return st[::-1]

def solve():
	string = takesr()
	dict_1 = cc(string)
	st = order(string)
	dict_2 = dd(lambda : 0)
	count = 1
	for i in st:
		if dict_1[i] % count != 0:
			print(-1)
			return
		else:
			dict_2[i] = dict_1[i] // count
		count += 1
	ans = ''
	for i in string:
		if dict_2[i] > 0:
			ans += i
			dict_2[i] -= 1
		else:
			break
	temp = first = ans
	s = set()
	index = 0
	while first and index < len(st):
		s.add(st[index])
		for i in first:
			if i not in s:
				temp += i
		index += 1
	if temp == string:
		print(ans, st)
	else:
		print(-1)

def main():
	global tt
	if not ONLINE_JUDGE:
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	t = 1
	t = takein()
	for tt in range(1, t + 1):
		solve()
	if not ONLINE_JUDGE:
		print('Time Elapsed :', time.time() - start_time, 'seconds')
		sys.stdout.close()

def takein():
	return int(sys.stdin.readline().rstrip('\r\n'))

def takesr():
	return sys.stdin.readline().rstrip('\r\n')

def takeiar():
	return list(map(int, sys.stdin.readline().rstrip('\r\n').split()))

def takesar():
	return list(map(str, sys.stdin.readline().rstrip('\r\n').split()))

def takeivr():
	return map(int, sys.stdin.readline().rstrip('\r\n').split())

def takesvr():
	return map(str, sys.stdin.readline().rstrip('\r\n').split())

def ispalindrome(s):
	return s == s[::-1]

def invert(bit_s):
	temp = int(bit_s, 2)
	inverse_s = temp ^ 2 ** (len(bit_s) + 1) - 1
	rslt = bin(inverse_s)[3:]
	return str(rslt)

def counter(a):
	q = [0] * max(a)
	for i in range(len(a)):
		q[a[i] - 1] = q[a[i] - 1] + 1
	return q

def counter_elements(a):
	q = dict()
	for i in range(len(a)):
		if a[i] not in q:
			q[a[i]] = 0
		q[a[i]] = q[a[i]] + 1
	return q

def string_counter(a):
	q = [0] * 26
	for i in range(len(a)):
		q[ord(a[i]) - 97] = q[ord(a[i]) - 97] + 1
	return q

def factorial(n, m=1000000007):
	q = 1
	for i in range(n):
		q = q * (i + 1) % m
	return q

def factors(n):
	q = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			q.append(i)
			q.append(n // i)
	return list(sorted(list(set(q))))

def prime_factors(n):
	q = []
	while n % 2 == 0:
		q.append(2)
		n = n // 2
	for i in range(3, int(n ** 0.5) + 1, 2):
		while n % i == 0:
			q.append(i)
			n = n // i
	if n > 2:
		q.append(n)
	return list(sorted(q))

def transpose(a):
	(n, m) = (len(a), len(a[0]))
	b = [[0] * n for i in range(m)]
	for i in range(m):
		for j in range(n):
			b[i][j] = a[j][i]
	return b

def power_two(x):
	return x and (not x & x - 1)

def ceil(a, b):
	return -(-a // b)

def seive(n):
	a = [1]
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p ** 2, n + 1, p):
				prime[i] = False
		p = p + 1
	for p in range(2, n + 1):
		if prime[p]:
			a.append(p)
	return a

def pref(li):
	pref_sum = [0]
	for i in li:
		pref_sum.append(pref_sum[-1] + i)
	return pref_sum

def kadane(x):
	sum_so_far = 0
	current_sum = 0
	for i in x:
		current_sum += i
		if current_sum < 0:
			current_sum = 0
		else:
			sum_so_far = max(sum_so_far, current_sum)
	return sum_so_far

def binary_search(li, val):
	ans = -1
	lb = 0
	ub = len(li) - 1
	while lb <= ub:
		mid = (lb + ub) // 2
		if li[mid] > val:
			ub = mid - 1
		elif val > li[mid]:
			lb = mid + 1
		else:
			ans = mid
			break
	return ans

def upper_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] <= num:
			answer = middle
			start = middle + 1
		else:
			end = middle - 1
	return answer

def lower_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] >= num:
			answer = middle
			end = middle - 1
		else:
			start = middle + 1
	return answer
ONLINE_JUDGE = __debug__
if ONLINE_JUDGE:
	input = sys.stdin.readline
main()


from collections import Counter
for _ in range(int(input())):
	t = input()
	letters = set()
	order = ''
	for i in range(len(t) - 1, -1, -1):
		if t[i] not in letters:
			letters.add(t[i])
			order = t[i] + order
	c = Counter(t)
	s_length = 0
	for i in range(len(order)):
		if c[order[i]] % (i + 1) == 0:
			s_length += c[order[i]] // (i + 1)
		else:
			print(-1)
			break
	else:
		candidate = t[:s_length]
		ans = candidate
		actual = candidate
		for char in order:
			candidate = ''.join([x for x in candidate if x != char])
			actual += candidate
		if actual == t:
			print(ans, order)
		else:
			print(-1)


import collections as _collections
import sys as _sys

def _main():
	[tests_n] = _read_ints()
	for i_test in range(tests_n):
		t = _read_string()
		try:
			(s, order) = restore_s_and_removing_order(t)
		except ValueError:
			print(-1)
		else:
			print(s, order)

def restore_s_and_removing_order(t: str):
	rev_t = t[::-1]
	removing_order = _restore_removing_order(t)
	chars_counts = _collections.Counter(t)
	initial_s_size = 0
	groups_curr_char_engaged_in = len(chars_counts)
	for ch in removing_order[::-1]:
		ch_count = chars_counts[ch]
		if ch_count % groups_curr_char_engaged_in != 0:
			raise ValueError
		initial_s_size += ch_count // groups_curr_char_engaged_in
		groups_curr_char_engaged_in -= 1
	s = t[:initial_s_size]
	_verify_scenario(s, t, removing_order)
	return (s, removing_order)

def _restore_removing_order(t: str):
	rev_order = []
	passed = set()
	for ch in t[::-1]:
		if ch not in passed:
			rev_order.append(ch)
			passed.add(ch)
	rev_order = ''.join(rev_order)
	order = rev_order[::-1]
	return order

def _verify_scenario(s: str, t: str, removing_order: str):
	i_start = 0
	for ch in removing_order:
		if s != t[i_start:i_start + len(s)]:
			raise ValueError
		i_start += len(s)
		s = s.replace(ch, '')

def _read_ints():
	return map(int, _read_string().split())

def _read_string():
	result = _sys.stdin.readline()
	assert result and result[-1] == '\n'
	return result[:-1]
_main()


def solver(t):
	z = len(t)
	order_arr = []
	for i in range(z - 1, -1, -1):
		if t[i] not in order_arr:
			order_arr.append(t[i])
	order_without_change = order_arr
	order_arr.reverse()
	t_char = [0] * 26
	for i in t:
		t_char[ord(i) - 97] += 1
	for i in range(len(t_char)):
		if t_char[i] > 0:
			if t_char[i] % (order_without_change.index(chr(97 + i)) + 1) != 0:
				return -1
	k = len(order_arr)
	count = 0
	for i in range(len(t_char)):
		if t_char[i] > 0:
			count += t_char[i] // (order_without_change.index(chr(97 + i)) + 1)
	j = count
	if True:
		temp_s = t[0:j]
		temp_t = ''
		i = 0
		order_str = ''
		while temp_s != '':
			temp_t = temp_t + temp_s
			temp_s = temp_s.replace(order_arr[i], '')
			order_str += order_arr[i]
			i += 1
		if temp_t == t:
			final = t[0:j] + ' '
			final += order_str
			return final
	return -1
t = int(input())
z = [None] * t
for i in range(t):
	z[i] = input()
for i in range(t):
	print(solver(z[i]))


from pprint import pprint
INF = 1 << 63

def do():
	import collections
	s = input()
	c = collections.Counter(s)
	delorder = []
	delset = set()
	for x in s[::-1]:
		if x in delset:
			continue
		delset.add(x)
		delorder.append(x)
	d = collections.defaultdict(int)
	cnt = len(delset)
	seikai = collections.defaultdict(int)
	total = 0
	for i in range(len(delorder)):
		ch = delorder[i]
		chcnt = c[ch] / (len(delorder) - i)
		if chcnt.is_integer() is False:
			print(-1)
			return
		total += chcnt
		seikai[ch] = chcnt
	total = int(total)
	base = s[:total]
	resbase = s[:total]
	very = base
	for x in delorder[::-1]:
		base = base.replace(x, '')
		very += base
	if very != s:
		print(-1)
		return
	print(resbase, ''.join(delorder[::-1]))
q = int(input())
for _ in range(q):
	do()


from collections import defaultdict, deque, Counter
from heapq import heapify, heappop, heappush
import math
from copy import deepcopy
from itertools import combinations, permutations, product, combinations_with_replacement
from bisect import bisect_left, bisect_right
import sys

def input():
	return sys.stdin.readline().rstrip()

def getN():
	return int(input())

def getNM():
	return map(int, input().split())

def getList():
	return list(map(int, input().split()))

def getListGraph():
	return list(map(lambda x: int(x) - 1, input().split()))

def getArray(intn):
	return [int(input()) for i in range(intn)]
mod = 10 ** 9 + 7
MOD = 998244353
inf = float('inf')
eps = 10 ** (-10)
dy = [0, 1, 0, -1]
dx = [1, 0, -1, 0]
str = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
rev = {0: 'a', 1: 'b', 2: 'c', 3: 'd', 4: 'e', 5: 'f', 6: 'g', 7: 'h', 8: 'i', 9: 'j', 10: 'k', 11: 'l', 12: 'm', 13: 'n', 14: 'o', 15: 'p', 16: 'q', 17: 'r', 18: 's', 19: 't', 20: 'u', 21: 'v', 22: 'w', 23: 'x', 24: 'y', 25: 'z'}
T = getN()
for _ in range(T):
	S = [str[s] for s in list(input())]
	N = len(S)
	d = {}
	add = []
	for i in range(N - 1, -1, -1):
		if not S[i] in d:
			d[S[i]] = 1
			add.append(S[i])
	add = list(reversed(add))

	def f(x):
		c = [0] * 26
		res = 0
		for i in range(x):
			c[S[i]] += 1
		all = sum(c)
		for i in range(len(add)):
			res += all
			all -= c[add[i]]
		return res
	ok = 0
	ng = N + 1
	while abs(ng - ok) > 1:
		mid = (ok + ng) // 2
		if f(mid) > N:
			ng = mid
		else:
			ok = mid
	psu = S[:ok]
	ans = ''.join([rev[s] for s in psu])
	t = []
	for i in range(len(add)):
		t += psu
		psu = [s for s in psu if s != add[i]]
	if t == S:
		print(ans, ''.join([rev[s] for s in add]))
	else:
		print(-1)


import sys

def input():
	return sys.stdin.readline().rstrip('\r\n')

def maps():
	return [int(i) for i in input().split()]
from collections import defaultdict

def check(se, dic):
	for i in se:
		if not dic[i] and already[ord(i) - 97] == -1:
			already[ord(i) - 97] = 1
			return True
	return False

def check2(d, s2, occ):
	for i in range(len(s2)):
		if d[s2[i]] != occ[i]:
			return False
	return True

def main():
	s = input()
	n = len(s)
	unique = set(s)
	if len(unique) == 1:
		print(s, s[0])
		return
	global already
	already = [0] * 26
	for i in unique:
		already[ord(i) - 97] = -1
	og = defaultdict(int)
	di = defaultdict(list)
	I = 0
	for i in s:
		og[i] += 1
		di[i].append(I)
		I += 1
	s2 = ''.join([i for (i, j) in sorted(di.items(), key=lambda x: x[1][-1])])
	ok = True
	occ = []
	for i in range(len(s2)):
		if og[s2[i]] % (i + 1):
			ok = False
			break
		else:
			occ.append(og[s2[i]] // (i + 1))
	if ok:
		s1 = ''
		i = 0
		d = defaultdict(int)
		for i in range(n):
			d[s[i]] += 1
			if check2(d, s2, occ):
				s1 = s[:i + 1]
				break
		S = s1
		idx = i
		for i in s2:
			s1 = s1.replace(i, '')
			S += s1
		if S == s:
			print(s[:idx + 1], s2)
		else:
			print(-1)
	else:
		print(-1)
for _ in range(*maps()):
	main()


def filter(list, ban):
	a = []
	for i in list:
		if i != ban:
			a.append(i)
	return a
t = int(input())
for j in range(t):
	s = list(input())
	ss = s.copy()
	win = 1
	a = [0] * 26
	for i in s:
		a[ord(i) - ord('a')] = 1
	cnt = 0
	for i in a:
		cnt += i
	q = [0] * 26
	ans = ''
	while len(s) > 0:
		last = s[-1]
		if s.count(last) % cnt == 0:
			ans += last
			q[ord(last) - ord('a')] = s.count(last) // cnt
			s = filter(s, last)
			cnt -= 1
			continue
		else:
			win = 0
			break
	if win == 0:
		print(-1)
		continue
	for i in range(len(ss)):
		q[ord(ss[i]) - ord('a')] -= 1
		if q[ord(ss[i]) - ord('a')] < 0:
			print(-1)
			win = 0
			break
		if sum(q) == 0:
			anss = ''.join(ss[:i + 1])
			ans = ans[::-1]
			break
	if win == 1:
		sss = ''
		ansss = anss
		for i in ans:
			sss += anss
			anss = ''.join(filter(anss, i))
		if list(sss) == ss:
			print(ansss, ans)
		else:
			print(-1)


for _ in range(int(input())):
	s = input()
	n = len(s)
	d = {}
	c = 0
	for i in s:
		if i in d:
			d[i] += 1
		else:
			c += 1
			d[i] = 1
	f = {}
	lf = d[s[-1]] // c
	lc = s[-1]
	f[lc] = lf
	out = lc
	found = 0
	t = c
	r = 1
	for i in range(n - 1, -1, -1):
		if s[i] == lc:
			if found < lf:
				found += 1
		elif s[i] not in f:
			lc = s[i]
			out += lc
			t -= 1
			lf = d[lc] // t
			r += 1
			f[s[i]] = lf
	total = sum(f.values())
	flag = 0
	expected = s[:total]
	j = 0
	curr = {}
	m = total
	out = out[::-1]
	k = 0
	lout = len(out)
	i = 0
	while i < n:
		if j < m and expected[j] in curr:
			j += 1
			continue
		if j < m and expected[j] == s[i] and (expected[j] not in curr):
			j += 1
			i += 1
		elif k < lout and j == m:
			curr[out[k]] = 1
			k += 1
			j = 0
			continue
		else:
			flag = 1
			break
	if k != lout - 1:
		flag = 1
	if flag == 0:
		print(expected, out)
	else:
		print(-1)


def solution():
	s = input()
	check = {}
	seq = []
	for i in s[::-1]:
		item = check.get(i)
		if item is None:
			seq.append(i)
			check[i] = 1
		else:
			check[i] = item + 1
	ln = len(seq)
	main_ln = 0
	for i in range(ln):
		item = check[seq[i]]
		if item % (ln - i):
			print('-1')
			return
		item = item // (ln - i)
		main_ln += item
	main_str = s[:main_ln]
	gen_str = main_str
	seq = seq[::-1]
	for char in seq:
		main_str = main_str.replace(char, '')
		gen_str += main_str
	if gen_str == s:
		print(s[:main_ln], ''.join(seq))
	else:
		print('-1')

def main():
	n = int(input())
	for i in range(n):
		solution()
main()


from collections import defaultdict
from sys import *
input = stdin.readline
for _ in range(int(input())):
	d = defaultdict(int)
	t = input().strip()
	occur = dict()
	order = ''
	for (j, i) in enumerate(t):
		d[i] += 1
		occur[i] = j
	ans = 0
	(leng, chrs) = (0, 1)
	for (i, j) in sorted(occur.items(), key=lambda x: x[1]):
		order += i
		if d[i] % chrs:
			ans = -1
			break
		leng += d[i] // chrs
		chrs += 1
	if ans == -1:
		print(ans)
	else:
		ans = t[:leng]
		ini = ans
		prev = ans
		for i in order:
			curr = ''
			for j in prev:
				if j != i:
					curr += j
			ans += curr
			prev = curr
		if ans == t:
			print(t[:leng], order)
		else:
			print(-1)


import math, os, io
from sys import stdin, stdout
from collections import Counter, deque, defaultdict
from itertools import product

def getList(method=int):
	return list(map(method, input().split()))

def getInt():
	return int(input())

def solve():
	s = input()
	(c, lst) = (Counter(s), dict())
	for (i, char) in enumerate(s):
		lst[char] = i
	arr = sorted(((i, char) for (char, i) in lst.items()))
	n = 0
	for (i, v) in enumerate(arr):
		v = v[1]
		if c[v] % (i + 1):
			print(-1)
			return
		n += c[v] // (i + 1)
	(ans, nxt, seq) = ('', s[:n], ''.join((v[1] for v in arr)))
	for c in seq:
		ans += nxt
		nxt = ''.join((v for v in nxt if v != c))
	if ans != s:
		print(-1)
	else:
		print(s[:n], seq)
for _ in range(getInt()):
	solve()


def check(word, input_string, order):
	if order == '':
		if input_string == '' and word == '':
			return True
		return False
	if word == '' or input_string == '':
		return False
	if word != input_string[:len(word)]:
		return False
	return check(word.replace(order[0], ''), input_string[len(word):], order[1:])

def func():
	input_string = str(input())
	freq = dict()
	s = input_string[::-1]
	order = ''
	while s != '':
		order += s[0]
		s = s.replace(s[0], '')
	order = order[::-1]
	i = 1
	length = 0
	for c in order:
		temp = input_string.count(c) / i
		if not temp == int(temp):
			return print(-1)
		freq[c] = (int(temp * i), int(temp))
		length += int(temp)
		i += 1
	word = input_string[:length]
	if check(word, input_string, order):
		print(word, order)
	else:
		print(-1)
t = int(input())
for _ in range(t):
	func()


def cf_739E(string: str):
	chars = {}
	removed = ''
	totalChars = {}
	for c in string:
		totalChars[c] = totalChars.get(c, 0) + 1
	total = len(totalChars)
	for c in reversed(string):
		if c not in chars:
			chars[c] = totalChars[c] // total
			total -= 1
			removed += c
	removed = removed[::-1]
	i = 0
	answer = ''
	while len(chars):
		c = string[i]
		chars[c] -= 1
		if not chars[c]:
			del chars[c]
		answer += c
		i += 1
	currRemoved = set()
	i = 0
	for r in removed:
		for c in answer:
			if c not in currRemoved:
				if string[i] == c:
					i += 1
				else:
					return -1
		currRemoved.add(r)
	if i != len(string):
		return -1
	return (answer, removed)
for _ in range(int(input())):
	try:
		print(*cf_739E(input()))
	except Exception as e:
		print(-1)


import sys
input = sys.stdin.readline
from collections import Counter
t = int(input())
for tests in range(t):
	y = input().strip()
	X = []
	for s in y[::-1]:
		if s in X:
			continue
		X.append(s)
	D = {X[i]: i for i in range(len(X))}
	C = Counter(y)
	ANS = [0] * len(X)
	for i in range(len(X)):
		x = X[i]
		ANS[i] = C[x] // (len(X) - i)
	COUNT = [0] * len(X)
	x = ''
	for i in range(len(y)):
		COUNT[D[y[i]]] += 1
		if ANS == COUNT:
			x = y[:i + 1]
			break
	X = X[::-1]
	fuku = x
	ansx = x
	for t in X:
		nx = ''
		for u in x:
			if t == u:
				continue
			nx += u
		x = nx
		fuku += nx
	if fuku == y:
		print(ansx, ''.join(X))
	else:
		print(-1)


def construct(s, order):
	t = ''
	for x in order:
		t += s
		s = s.replace(x, '')
	return t
for _ in range(int(input())):
	t = input()
	order = sorted(set(t), key=t.rindex)
	s = t[:sum((t.count(x) // i for (i, x) in enumerate(order, 1)))]
	if construct(s, order) == t:
		print(s, ''.join(order))
	else:
		print(-1)


import collections

def construct(s, order):
	t = ''
	for x in order:
		t += s
		s = s.replace(x, '')
	return t

def solve(t):
	letters = set()
	order = ''
	for x in reversed(t):
		if x not in letters:
			letters.add(x)
			order = x + order
	counter = collections.Counter(t)
	s = t[:sum((counter[x] // i for (i, x) in enumerate(order, 1)))]
	if construct(s, order) == t:
		print(s, order)
	else:
		print(-1)
for _ in range(int(input())):
	solve(input())


from sys import stdin, stdout
input = stdin.readline
print = stdout.write
for _ in range(int(input())):
	s = input().strip()
	freq = {}
	process = ''
	for char in s[::-1]:
		if char in freq:
			freq[char] += 1
		else:
			process = char + process
			freq[char] = 1
	possible = True
	for i in range(len(process)):
		(q, r) = divmod(freq[process[i]], i + 1)
		if r:
			possible = False
			break
		freq[process[i]] = q
	if not possible:
		print('-1\n')
		continue
	ln = sum(freq.values())
	word = s[:ln]
	hasf = {}
	for char in word:
		hasf[char] = hasf.get(char, 0) + 1
	if freq != hasf:
		print('-1\n')
	else:
		ans = word
		new = word
		start = i = 0
		while ln:
			if s[start:start + ln] != new:
				possible = False
				break
			start += ln
			count = 0
			word = new
			new = ''
			for char in word:
				if char == process[i]:
					count += 1
				else:
					new += char
			ln -= count
			i += 1
		if possible:
			print(ans + ' ' + process + '\n')
		else:
			print('-1\n')


import bisect
import os
import io
TC = int(input())
for tc in range(TC):
	S = input()
	O = []
	OS = {}
	for i in range(len(S) - 1, -1, -1):
		if S[i] in OS:
			OS[S[i]] += 1
		else:
			O.append(S[i])
			OS[S[i]] = 1
	O.reverse()
	found = True
	r_len = 0
	for (i, c) in enumerate(O):
		(d, r) = divmod(OS[c], i + 1)
		if r != 0:
			found = False
			break
		OS[c] = d
		r_len += d
	if not found:
		print(-1)
		continue
	R = S[:r_len]
	V = R
	pos = r_len
	for l in O:
		T = []
		for v in V:
			if v != l:
				T.append(v)
				if S[pos] != v:
					found = False
					break
				pos += 1
		if not found:
			break
		V = T
	if found:
		print(R, ''.join(O))
	else:
		print(-1)


for _ in range(int(input())):
	t = input()
	snew = list(set(t))
	order = ''
	d = {}
	for (i, v) in enumerate(t):
		d[v] = i
	order = sorted(d.items(), key=lambda kv: (kv[1], kv[0]))
	ans = ''
	for i in order:
		ans += i[0]
	length_original = 0
	j = 1
	for i in ans:
		length_original += t.count(i) // j
		j += 1
	ans1 = t[:length_original]
	check = ''
	tp = ans1
	p = 0
	while tp != '':
		check += tp
		tp = tp.replace(ans[p], '')
		p += 1
	if check == t:
		print(ans1, ans)
	else:
		print(-1)


import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
input = lambda : sys.stdin.readline().rstrip()
import bisect, string, math, time, functools, random, fractions
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
from itertools import permutations, combinations, groupby
rep = range
R = range

def I():
	return int(input())

def LI():
	return [int(i) for i in input().split()]

def LI_():
	return [int(i) - 1 for i in input().split()]

def S_():
	return input()

def IS():
	return input().split()

def LS():
	return [i for i in input().split()]

def NI(n):
	return [int(input()) for i in range(n)]

def NI_(n):
	return [int(input()) - 1 for i in range(n)]

def NLI(n):
	return [[int(i) for i in input().split()] for i in range(n)]

def NLI_(n):
	return [[int(i) - 1 for i in input().split()] for i in range(n)]

def StoLI():
	return [ord(i) - 97 for i in input()]

def ItoS(n):
	return chr(n + 97)

def LtoS(ls):
	return ''.join([chr(i + 97) for i in ls])

def RLI(n=8, a=1, b=10):
	return [random.randint(a, b) for i in range(n)]

def RI(a=1, b=10):
	return random.randint(a, b)

def INP():
	N = 9
	n = random.randint(1, N)
	A = [random.randint(1, n) for i in range(m)]
	return (n, A)

def Rtest(T):
	(case, err) = (0, 0)
	for i in range(T):
		inp = INP()
		a1 = naive(*inp)
		a2 = solve(*inp)
		if a1 != a2:
			print(inp)
			print('naive', a1)
			print('solve', a2)
			err += 1
		case += 1
	print('Tested', case, 'case with', err, 'errors')

def GI(V, E, ls=None, Directed=False, index=1):
	org_inp = []
	g = [[] for i in range(V)]
	FromStdin = True if ls == None else False
	for i in range(E):
		if FromStdin:
			inp = LI()
			org_inp.append(inp)
		else:
			inp = ls[i]
		if len(inp) == 2:
			(a, b) = inp
			c = 1
		else:
			(a, b, c) = inp
		if index == 1:
			a -= 1
			b -= 1
		aa = (a, c)
		bb = (b, c)
		g[a].append(bb)
		if not Directed:
			g[b].append(aa)
	return (g, org_inp)

def GGI(h, w, search=None, replacement_of_found='.', mp_def={'#': 1, '.': 0}, boundary=1):
	mp = [boundary] * (w + 2)
	found = {}
	for i in R(h):
		s = input()
		for char in search:
			if char in s:
				found[char] = (i + 1) * (w + 2) + s.index(char) + 1
				mp_def[char] = mp_def[replacement_of_found]
		mp += [boundary] + [mp_def[j] for j in s] + [boundary]
	mp += [boundary] * (w + 2)
	return (h + 2, w + 2, mp, found)

def TI(n):
	return GI(n, n - 1)

def accum(ls):
	rt = [0]
	for i in ls:
		rt += [rt[-1] + i]
	return rt

def bit_combination(n, base=2):
	rt = []
	for tb in R(base ** n):
		s = [tb // base ** bt % base for bt in R(n)]
		rt += [s]
	return rt

def gcd(x, y):
	if y == 0:
		return x
	if x % y == 0:
		return y
	while x % y != 0:
		(x, y) = (y, x % y)
	return y

def YN(x):
	print(['NO', 'YES'][x])

def Yn(x):
	print(['No', 'Yes'][x])

def show(*inp, end='\n'):
	if show_flg:
		print(*inp, end=end)
mo = 10 ** 9 + 7
inf = 1 << 63
FourNb = [(-1, 0), (1, 0), (0, 1), (0, -1)]
EightNb = [(-1, 0), (1, 0), (0, 1), (0, -1), (1, 1), (-1, -1), (1, -1), (-1, 1)]
compas = dict(zip('WENS', FourNb))
cursol = dict(zip('LRUD', FourNb))
alp = [chr(ord('a') + i) for i in range(26)]
show_flg = False
show_flg = True
ans = 0
for _ in range(I()):
	s = [ord(i) - 97 for i in input()]
	x = []
	c = [0] * 26
	for i in s[::-1]:
		c[i] += 1
		if i not in x:
			x += (i,)
	m = 0
	for (i, z) in enumerate(x[::-1]):
		k = i + 1
		m += c[z] // k
	a = s[:m]
	t = a[:]
	for r in x[::-1]:
		nx = []
		for i in a:
			if i != r:
				nx += (i,)
		t += nx[:]
		a = nx[:]
	if s == t:
		print(LtoS(s[:m]), LtoS(x[::-1]))
	else:
		print(-1)


T = int(input())

def update_dic(dic, l, n):
	if l not in dic:
		dic[l] = 1
		n += 1
	else:
		dic[l] += 1
	return (dic, n)

def restore(b, k):
	t = ''
	for i in k:
		t += b
		b_new = ''
		for j in b:
			if j != i:
				b_new += j
		b = b_new
	return t

def check(dic_d, dic_t, n):
	a = []
	b = {}
	k = ''
	for i in dic_d.keys():
		if dic_d[i] % dic_t[i] == 0:
			a.append(dic_d[i] // dic_t[i])
			b[dic_d[i] // dic_t[i]] = i
		else:
			return (False, k)
	for i in range(1, n + 1):
		if i not in a:
			return (False, k)
	for i in range(1, n + 1):
		k += b[i]
	return (True, k)
for _ in range(T):
	s = input()
	d = {}
	n = 0
	t = {}
	m = 0
	b = ''
	k = ''
	final_b = s
	for l in s:
		(d, n) = update_dic(d, l, n)
	if n == 1:
		print(s, s[0])
	else:
		for l in s:
			b += l
			(t, m) = update_dic(t, l, m)
			if m == n:
				(o, k) = check(d, t, n)
				if o and restore(b, k) == s:
					final_b = b
					break
		if final_b == s:
			print(-1)
		else:
			print(final_b, ' ', k)


def binarysearch(array, item):
	if array == []:
		return False
	i = 0
	j = len(array) - 1
	while i < j:
		mid = (i + j) // 2
		if array[mid] == item:
			return True
		elif array[mid] > item:
			j = mid
		else:
			i = mid + 1
	else:
		return True if array[i] == item else False

def delet(list, item):
	list2 = []
	for i in list:
		if i != item:
			list2.append(i)
	return list2

def first(arr, x):
	low = 0
	high = len(arr) - 1
	res = -1
	while low <= high:
		mid = (low + high) // 2
		if arr[mid] > x:
			high = mid - 1
		elif arr[mid] < x:
			low = mid + 1
		else:
			res = mid
			high = mid - 1
	return res
t = int(input())
for test in range(t):
	strin = input()
	d = len(strin)
	array = []
	for item in strin:
		array.append(item)
	order = []
	search = []
	array.reverse()
	for item in array:
		if not binarysearch(search, item):
			order.append(item)
			search.append(item)
			search.sort()
	order.reverse()
	array2 = sorted(array)
	l = 0
	for i in range(len(order)):
		x = first(array2, order[i])
		s = 0
		possible = 0
		while x + s < d and array2[x + s] == order[i]:
			s += 1
		else:
			if s % (i + 1) > 0:
				possible = -1
			else:
				l += s // (i + 1)
		if possible == -1:
			print(-1)
			break
	else:
		array.reverse()
		init = array[:l]
		smple = array[:l]
		for i in range(len(order) - 1):
			smple = delet(smple, order[i])
			init += smple
		if init == array:
			ar = array[:l]
			s = ''
			for item in ar:
				s += str(item)
			s1 = ''
			for item in order:
				s1 += str(item)
			ans = [s, s1]
			print(' '.join(map(str, ans)))
		else:
			print(-1)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	a = list(input())
	order = []
	s = set()
	n = len(a) - 1
	a = a[:-1]
	for i in range(n - 1, -1, -1):
		if a[i] not in s:
			order += [a[i]]
			s.add(a[i])
	tot = [0 for i in range(26)]
	fl = 1
	for i in range(len(order)):
		c = a.count(order[i])
		c = c / (len(order) - i)
		if int(c) != c:
			fl = -1
		tot[ord(order[i]) - 97] += c
	if fl == -1:
		print(-1)
		continue
	now = [0 for i in range(26)]
	for i in range(n):
		now[ord(a[i]) - 97] += 1
		if now == tot:
			ans = ''
			for j in range(i + 1):
				ans += a[j]
			order = order[::-1]
			f = ''
			for j in order:
				f += j
	t = ''
	s = ans[:]
	k = 0
	while len(t) < n and k < len(order) and (len(s) > 0):
		t += s
		now = ''
		for i in range(len(s)):
			if s[i] != order[k]:
				now += s[i]
		k += 1
		s = now[:]
	t = list(t)
	if a == t:
		print(ans, f)
	else:
		print(-1)


import sys
input = lambda : sys.stdin.readline().strip()
T = int(input())
while T:
	T -= 1
	t = input()
	n = len(t)
	last = [-1] * 26
	cnt = [0] * 26
	for (i, ti) in enumerate(t):
		last[ord(ti) - ord('a')] = i
		cnt[ord(ti) - ord('a')] += 1
	seq = [(last[i], i) for i in range(26) if last[i] != -1]
	seq.sort()
	final_seq = []
	length_of_s = 0
	ok = True
	for (ind, (i, ch)) in enumerate(seq):
		ch1 = chr(ord('a') + ch)
		if cnt[ch] % (ind + 1) != 0:
			ok = False
			break
		length_of_s += cnt[ch] // (ind + 1)
		final_seq.append(ch1)
	if not ok:
		print(-1)
		continue
	t_new = []
	s = t[:length_of_s]
	i = 0
	while s:
		t_new.append(s)
		s = s.replace(final_seq[i], '')
		i += 1
	t_new = ''.join(t_new)
	if t_new == t:
		print(t[:length_of_s], ''.join(final_seq))
	else:
		print(-1)


def nonZero(d):
	for c in d:
		if d[c] > 0:
			return True
	return False

def check(s, t, sq):
	t1 = ''
	i = 0
	while s != '' and i < len(sq):
		t1 = t1 + s
		s = s.replace(sq[i], '')
		i = i + 1
	if i == len(sq) and t == t1:
		return True
	else:
		return False
t = int(input())
for k in range(0, t):
	s = input()
	d = {}
	for a in s:
		if a in d:
			d[a] = d[a] + 1
		else:
			d[a] = 1
	sq = ''
	t = {}
	for i in range(len(s) - 1, -1, -1):
		if s[i] in t:
			continue
		else:
			sq = sq + s[i]
			t[s[i]] = True
	l = len(sq)
	j = l
	exit = False
	for i in range(l):
		c = sq[i]
		d[c] = d[c] // j
		j = j - 1
	i = 0
	while nonZero(d):
		c = s[i]
		d[c] = d[c] - 1
		i = i + 1
	if check(s[:i], s, sq[::-1]):
		print(s[:i] + ' ' + sq[::-1])
	else:
		print(-1)


import sys
from bisect import bisect_right as lb
from collections import deque
from queue import PriorityQueue as pq
input_ = lambda : sys.stdin.readline().strip('\r\n')
ii = lambda : int(input_())
il = lambda : list(map(int, input_().split()))
ilf = lambda : list(map(float, input_().split()))
ip = lambda : input_()
fi = lambda : float(input_())
ap = lambda ab, bc, cd: ab[bc].append(cd)
li = lambda : list(input_())
pr = lambda x: print(x)
prinT = lambda x: print(x)
f = lambda : sys.stdout.flush()
inv = lambda x: pow(x, mod - 2, mod)
mod = 10 ** 9 + 7
for _ in range(ii()):
	a = list(ip())
	d = {}
	n = len(a)
	for i in a:
		d[i] = d.get(i, 0) + 1
	step = []
	d1 = {}
	for i in range(n - 1, -1, -1):
		if d1.get(a[i]):
			continue
		d1[a[i]] = i
		step.append(a[i])
	fl = 1
	x = len(step)
	length = 0
	for i in range(len(step)):
		if d[step[i]] % x != 0:
			fl = 0
			break
		length += d[step[i]] // x
		x -= 1
	if fl == 0:
		print(-1)
		continue
	ans = a[:length]
	x = ans.copy()
	temp = []
	step = step[::-1]
	t = 0
	for i in range(len(step)):
		for j in range(len(ans)):
			if x[j] != '$':
				temp.append(x[j])
		for j in range(len(ans)):
			if x[j] == step[t]:
				x[j] = '$'
		t += 1
	if ''.join(temp) != ''.join(a):
		prinT(-1)
		continue
	print(''.join(ans), ''.join(step))


def func():
	t = input()
	s = ''
	n = len(t)
	m = 0
	sc = [0 for i in range(26)]
	tc = [0 for i in range(26)]
	for i in range(n):
		temp = ord(t[i])
		tc[temp - 97] += 1
	for i in range(26):
		if tc[i] != 0:
			m += 1
	count = m
	j = n - 1
	temp = []
	for m in range(count, 0, -1):
		i = j
		while i > 0 and t[i] in temp:
			i -= 1
		temp.append(t[i])
		an = ord(t[i]) - 97
		if tc[an] % m:
			print(-1)
			return
		sc[an] = tc[an] / m
		j = i
	ansl = 0
	for i in range(26):
		if sc[i]:
			ansl += sc[i]
	ans = ''
	s = t[0:int(ansl)]
	ans += s
	temp = temp[::-1]
	ans2 = ''.join(temp)
	for i in range(len(temp)):
		c = str(ans2[i])
		s = s.replace(c, '')
		ans += s
	if ans != t:
		print(-1)
		return
	print(t[0:int(ansl)], ans2)
t = int(input())
for _ in range(t):
	func()


def get_id(ch):
	return ord(ch) - ord('a')

def simulate(s, remove_order):
	ans = ''
	for ch in reversed(remove_order):
		ans = ans + s
		s = s.replace(ch, '')
	return ans
for _ in range(int(input())):
	t = input()
	fr = [0] * 26
	for ch in t:
		fr[get_id(ch)] += 1
	remove_order = []
	vis = set()
	for ch in reversed(t):
		if ch not in vis:
			remove_order.append(ch)
			vis.add(ch)
	ok = True
	num_ap = [0] * 26
	i = len([x for x in fr if x != 0])
	for ch in remove_order:
		if fr[get_id(ch)] % i != 0:
			ok = False
		num_ap[get_id(ch)] = fr[get_id(ch)] // i
		i -= 1
	if not simulate(t[:sum(num_ap)], remove_order) == t:
		ok = False
	if ok:
		print(t[:sum(num_ap)], ''.join(reversed(remove_order)))
	else:
		print(-1)


from __future__ import division, print_function
import os, math, threading
import sys
from io import BytesIO, IOBase
from typing import DefaultDict
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
from types import GeneratorType

def main():
	for _ in range(int(input())):
		t = list(input())
		(ans2, s2, s1) = ([], dict(), dict())
		l = 0
		for i in range(len(t) - 1, -1, -1):
			if t[i] not in s2:
				s2[t[i]] = i
				s1[i] = t[i]
				ans2.append(t[i])
		f = False
		x = 1
		count = dict()
		ans = []
		for i in range(len(t)):
			if t[i] not in count:
				count[t[i]] = 1
			else:
				count[t[i]] += 1
			if i in s1 and count[t[i]] % x == 0:
				l += count[t[i]] // x
				x += 1
			elif i in s1 and count[t[i]] % x != 0:
				print(-1)
				break
		else:
			k = 0
			ans = t[:l]
			fans = list(ans)
			fans1 = list(ans2)
			for i in range(len(t)):
				if k == len(ans):
					x = ans2.pop()
					temp = []
					for j in ans:
						if x != j:
							temp.append(j)
					ans = temp
					k = 0
				if t[i] == ans[k]:
					k += 1
				else:
					print(-1)
					break
			else:
				print(''.join(fans), ''.join(fans1[::-1]))
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


def solve(arr):
	n = len(arr)
	freq = {}
	order = []
	count = 0
	for x in range(n - 1, -1, -1):
		if arr[x] not in freq:
			freq[arr[x]] = 1
			order.append(arr[x])
			count += 1
		else:
			freq[arr[x]] += 1
	to_go = 0
	num_of_oc = 1
	order.reverse()
	for x in order:
		if freq[x] % num_of_oc:
			print(-1)
			return
		to_go += freq[x] // num_of_oc
		num_of_oc += 1
	result = arr[:to_go]
	copy = result
	idx = to_go
	length = to_go
	count = 1
	for key in order:
		copy = [i for i in copy if i != key]
		length -= freq[key] // count
		if arr[idx:idx + length] != copy:
			print(-1)
			return
		idx += length
		count += 1
	print(*result, sep='', end=' ')
	print(*order, sep='')
for _ in range(int(input())):
	arr = []
	arr[:0] = input()
	solve(arr)


from _collections import defaultdict
import sys
input = sys.stdin.readline
T = int(input())
for iiii in range(T):
	s = list(input()[:-1])
	n = len(s)
	use = set()
	num = []
	for i in range(n - 1, -1, -1):
		if s[i] not in use:
			num.append(s[i])
			use.add(s[i])
	num.reverse()
	m = len(num)
	cnt = defaultdict(int)
	ind = -1
	for i in range(n):
		cnt[s[i]] += 1
		x = 0
		for j in range(m):
			x += cnt[num[j]] * (j + 1)
		if x == n:
			ind = i
			break
	if ind == -1:
		print(-1)
		continue
	ans = s[:ind + 1]
	x = ans[:]
	y = []
	for al in num:
		y += x
		x = [nod for nod in x if nod != al]
	if y != s:
		print(-1)
		continue
	print(''.join(ans), ''.join(num))


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	s = [ord(i) - 97 for i in input().strip()]
	cnt = [0] * 26
	for i in s:
		cnt[i] += 1
	curr = [0] * 26
	removed = [0] * 26
	order = []
	total = len(set(s))
	temp = 1
	for i in s:
		curr[i] += 1
		if curr[i] == cnt[i]:
			removed[i] = temp
			temp += 1
			order.append(chr(i + 97))
	ans = []
	curr = [0] * 26
	for i in s:
		flag = 0
		curr[i] += 1
		ans.append(chr(i + 97))
		for j in range(26):
			if removed[j] == 0:
				continue
			if curr[j] < cnt[j] // removed[j]:
				flag = 1
		if not flag:
			break
	final = []
	for i in range(total):
		for j in ans:
			if removed[ord(j) - 97] <= i:
				continue
			final.append(ord(j) - 97)
	if final != s:
		print(-1)
	else:
		print(''.join(ans), ''.join(order))


from __future__ import print_function
from math import *
from collections import deque
import os
import sys
from io import BytesIO, IOBase

def main():
	pass
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
mod = 10 ** 9 + 7

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s)])

def invr():
	return map(int, input().split())
for _ in range(inp()):
	l = insr()
	n = len(l)
	out = []
	s = {}
	ck = 0
	for i in range(n):
		if l[n - i - 1] not in s:
			s[l[n - 1 - i]] = 1
			ck += 1
			out.append(l[n - i - 1])
		else:
			s[l[n - i - 1]] += 1
	out.reverse()
	d = {}
	c = 0
	p = 0
	f = 1
	for i in range(len(out)):
		if s[out[i]] % (i + 1) != 0:
			f = 0
			break
		else:
			d[out[i]] = s[out[i]] // (i + 1)
	if not f:
		print(-1)
		continue
	t = []
	for i in range(n):
		if d[l[i]] == 0:
			for j in out:
				if d[j] != 0:
					f = 0
			break
		else:
			d[l[i]] -= 1
			t.append(l[i])
	if not f:
		print(-1)
		continue
	s = set()
	p = 0
	for i in out:
		for j in range(len(t)):
			if t[j] not in s:
				if t[j] == l[p] and p < n:
					p += 1
				else:
					f = 0
					break
		s.add(i)
	if not f or p != n:
		print(-1)
	else:
		print(''.join((i for i in t)), ''.join((i for i in out)))


from heapq import heapify, heappush, heappop, heappushpop
from collections import defaultdict as dd, deque as dq, Counter as C
from math import factorial as f, ceil, gcd, sqrt, log
from bisect import bisect_left as bl, bisect_right as br
from itertools import combinations as c, permutations as p
from math import factorial as f, ceil, gcd, sqrt, log
from sys import stdin, stdout
input = stdin.readline
mp = lambda : map(int, input().split())
it = lambda : int(input())
ls = lambda : list(input().strip())
mt = lambda r: [ls() for _ in range(r)]
lcm = lambda a, b: a * b // gcd(a, b)
for _ in range(it()):
	a = input().strip()
	s = set()
	ans = []
	for i in a[::-1]:
		if i in s:
			continue
		s.add(i)
		ans.append(i)
	cnt = len(ans)
	ans = ans[::-1]
	k = C(a)
	cn = {}
	for i in ans[::-1]:
		cn[i] = k[i] / cnt
		cnt -= 1
	count = 0
	ans1 = 1
	for i in cn:
		if cn[i] != int(cn[i]):
			ans1 = -1
		else:
			count += int(cn[i])
	if ans1 == -1:
		print(-1)
	else:
		main = a[:count]
		s1 = set()
		cur = []
		for i in ans:
			for j in main:
				if j in s1:
					continue
				else:
					cur.append(j)
			s1.add(i)
		if ''.join(cur) == a:
			print(main, ''.join(ans))
		else:
			print(-1)


for i in range(int(input())):
	a = input()
	z = [[-1, i] for i in range(26)]
	b = [0] * 26
	for i in range(len(a)):
		z[ord(a[i]) - 97][0] = max(z[ord(a[i]) - 97][0], i)
		b[ord(a[i]) - 97] += 1
	c = ''
	z.sort()
	for i in range(25, -1, -1):
		if z[i][0] == -1:
			break
		c += 'abcdefghijklmnopqrstuvwxyz'[z[i][1]]
	n = 0
	c = c[::-1]
	for i in range(len(c)):
		n += b[ord(c[i]) - 97] // (i + 1)
	else:
		d = a[:n]
		e = ''
		for i in c:
			e += d
			d1 = ''
			for j in d:
				if j != i:
					d1 += j
			d = d1
		if e == a:
			print(a[:n], c)
		else:
			print(-1)


import sys

def counts(idx):
	temp = 0
	for item in ch.keys():
		temp += ch[item] // idx
		if ch[item] % idx != 0:
			return -1
		idx -= 1
	return temp

def check():
	(temp_ans, removed) = (data[:ret], list(ch.keys())[::-1])
	(t_len, already_remove) = (0, set())
	for item in removed:
		for char in temp_ans:
			if char in already_remove:
				continue
			if t_len >= len(data) or char != data[t_len]:
				return -1
			t_len += 1
		already_remove.add(item)
	return 1
for _ in range(int(sys.stdin.readline())):
	data = sys.stdin.readline().rstrip()
	(ch, possible) = (dict(), 1)
	for item in data[::-1]:
		if item not in ch:
			ch[item] = 1
		else:
			ch[item] += 1
	ret = counts(len(list(ch.keys())))
	if ret == -1:
		print(-1)
		continue
	if check() == -1:
		print(-1)
	else:
		ans = ''.join(list(ch.keys())[::-1])
		print(f'{data[:ret]} {ans}')


t = int(input())
for test in range(t):
	s = input()
	x = ''
	for c in s[::-1]:
		if c not in x:
			x = c + x
	k = 1
	count = 0
	bool = True
	for c in x:
		z = s.count(c) / k
		if s.count(c) % k != 0:
			print(-1)
			bool = False
			break
		else:
			count += z
		k += 1
	if bool is True:
		count = int(count)
		z = s[0:count]
		t = ''
		for c in x:
			t += z
			while c in z:
				z = z.replace(c, '')
		z = s[0:count]
		if s == t:
			print(s[0:count], x)
		else:
			print(-1)


from collections import defaultdict
alpha = [chr(i) for i in range(97, 123)]

def solve(t):
	d = dict()
	cnts = defaultdict(int)
	i = 1
	for k in t[::-1]:
		if k not in d:
			d[k] = i
			i += 1
		cnts[k] += 1
	l = len(d.keys())
	order = [' '] * l
	for (k, v) in d.items():
		if cnts[k] % (l - v + 1) != 0:
			return -1
		cnts[k] = cnts[k] // (l - v + 1)
		order[l - v] = k
	total_count = sum(cnts.values())
	s = t[:total_count]
	p = s
	t_ = ''
	for i in order:
		t_ += p
		p = ''.join([j for j in p if j != i])
	if t != t_:
		return -1
	return f"{s} {''.join(order)}"

def main():
	T = int(input())
	ans = []
	for i in range(T):
		t = input()
		ans.append(solve(t))
	for a in ans:
		print(a)
main()


from sys import stdin, stdout, setrecursionlimit
from bisect import bisect_left, bisect_right
from math import ceil, floor, log, gcd
from collections import Counter, deque
from heapq import heappush, heappop, heapify
from operator import mul
from functools import reduce

def re():
	return stdin.readline().rstrip()

def ints():
	return map(int, stdin.readline().split())

def test(cases):
	for _ in range(cases):
		solve()
mod = 1000000007

def ncr(n, r):
	r = min(r, n - r)
	numer = reduce(mul, range(n, n - r, -1), 1)
	denom = reduce(mul, range(1, r + 1), 1)
	return numer // denom

class Dsu:

	def __init__(self, n):
		self.parent = list(range(n))
		self.rank = [1] * n

	def find(self, x):
		while x != self.parent[x]:
			self.parent[x] = self.parent[self.parent[x]]
			x = self.parent[x]
		return x

	def union(self, x, y):
		(px, py) = (self.find(x), self.find(y))
		if px == py:
			return 0
		if self.rank[py] > self.rank[px]:
			(px, py) = (py, px)
		self.parent[py] = px
		self.rank[px] += self.rank[py]
		return 1

	def get_size(self, x):
		return self.rank[self.find(x)]

def solve():
	s = re()
	n = len(s)
	miku = []
	seen = set()
	cntr = Counter()
	for i in range(len(s) - 1, -1, -1):
		if s[i] not in seen:
			seen.add(s[i])
			miku.append(s[i])
		cntr[s[i]] += 1
	miku.reverse()
	nino = 0
	for i in range(len(miku)):
		if cntr[miku[i]] % (i + 1) != 0:
			print(-1)
			return
		nino += cntr[miku[i]] // (i + 1)
	cur = 0
	res = ''
	nxt = s[:nino]
	while nxt:
		res += nxt
		nxt = nxt.replace(miku[cur], '')
		cur += 1
	if res == s:
		print(s[:nino], ' ', *miku, sep='')
	else:
		print(-1)
	return
test(int(re()))


for t in range(int(input())):
	s = input()
	s2 = ''
	c = 0
	res = 0
	d = {}
	d2 = {}
	for i in s:
		try:
			d[i] += 1
		except:
			d[i] = 1
			d2[i] = True
			c += 1
	for i in s[::-1]:
		if d2[i] and res != -1:
			if d[i] % c == 0:
				res += d[i] // c
				d2[i] = False
				c -= 1
				s2 += i
			else:
				res = -1
	if res != -1:
		s4 = s[0:res]
		s3 = s[0:res]
		for i in s2[::-1]:
			s3 += s4.replace(i, '')
			s4 = s4.replace(i, '')
		if s3 != s:
			res = -1
	if res == -1:
		print(res)
	else:
		print(s[0:res], s2[::-1])


ans = []
for _ in range(int(input())):
	s = list(input())
	n = len(s)
	lt = []
	d = []
	for i in range(n - 1, -1, -1):
		if s[i] not in lt:
			lt.append(s[i])
			d.append(1)
		else:
			ind = lt.index(s[i])
			d[ind] += 1
	lt.reverse()
	d.reverse()
	for i in range(len(lt)):
		if d[i] % (i + 1) != 0:
			ans.append(-1)
			break
		d[i] //= i + 1
	else:
		a = ''.join(s[:sum(d)])
		a0 = a
		b = ''.join(lt)
		ind = len(a)
		s = ''.join(s)
		for i in range(len(lt)):
			c = []
			for j in range(len(a)):
				if a[j] == lt[i]:
					continue
				c.append(a[j])
			if len(s) < ind + len(c) or s[ind:ind + len(c)] != ''.join(c):
				ans.append(-1)
				break
			a = c[:]
			ind += len(a)
		else:
			ans.append(a0 + ' ' + b)
print('\n'.join(map(str, ans)))


import sys
import io
import math
import collections
import decimal
import itertools
import bisect
import heapq

def input():
	return sys.stdin.readline()[:-1]
INF = 10 ** 10

def solve(S):
	count = collections.defaultdict(int)
	delete_seq = []
	for c in reversed(S):
		if count[c] == 0:
			delete_seq.append(c)
		count[c] += 1
	delete_seq.reverse()
	original_count = collections.defaultdict(int)
	for (i, c) in enumerate(delete_seq):
		original_count[c] = count[c] // (i + 1)
	n1 = sum(original_count.values())
	original_S = S[:n1]
	S1 = list(original_S)
	T1 = []
	for c_del in delete_seq:
		T1 = T1 + S1
		S2 = []
		for c in S1:
			if c != c_del:
				S2.append(c)
		S1 = S2
	if S == ''.join(T1):
		return [original_S, ''.join(delete_seq)]
	else:
		return [-1]
T0 = int(input())
for _ in range(T0):
	S = input()
	print(*solve(S))


t = int(input())
for _ in range(t):
	c = input()
	n = len(c)
	d = {}
	for item in c:
		d[item] = d.get(item, 0) + 1
	l = []
	for i in range(n - 1, -1, -1):
		if not c[i] in l:
			l.insert(0, c[i])
	b = ''.join(l)
	nl = 0
	for i in range(len(l)):
		nl += d[l[i]] // (i + 1)
	a = c[:nl]
	tmpc = a
	tmpa = a
	for item in l:
		tmpa = ''.join(tmpa.split(item))
		tmpc = tmpc + tmpa
	if tmpc != c:
		print(-1)
	else:
		print(a, b)


from collections import *
import sys
input = sys.stdin.readline

def inp():
	return int(input())

def st():
	return input().rstrip('\n')

def lis():
	return list(map(int, input().split()))

def ma():
	return map(int, input().split())
t = inp()
while t:
	t -= 1
	s = st()
	n = len(s)
	rem = ''
	vis = set()
	for i in range(len(s) - 1, -1, -1):
		if s[i] not in vis:
			rem += s[i]
			vis.add(s[i])
	rem = rem[::-1]
	f = Counter(s)
	flag = 0
	should = [0 for i in range(26)]
	for i in range(len(rem)):
		z = f[rem[i]]
		if z % (i + 1):
			flag = 1
			break
		should[ord(rem[i]) - 97] = z // (i + 1)
	if flag:
		print(-1)
		continue
	have = [0 for i in range(26)]
	put = set(rem)
	cur = ''
	for i in s:
		if len(put) == 0:
			break
		cur += i
		z = ord(i) - 97
		have[z] += 1
		if have[z] == should[z]:
			put.remove(i)
		if have[z] > should[z]:
			flag = 1
			break
	if flag or len(put):
		print(-1)
		continue
	final = set()
	lflag = 0
	cur1 = cur[:]
	for i in range(len(rem)):
		final.add(rem[i])
		for k in cur1:
			if k not in final:
				cur += k
				if len(cur) > n:
					lflag = 1
					break
		if lflag:
			break
	if cur == s:
		print(cur1, rem)
	else:
		print(-1)


import sys
from collections import Counter
input = sys.stdin.readline

def solve():
	t = input().strip()
	ctr = Counter(t)
	sz = len(ctr)
	n = len(t)
	seen = set()
	order = []
	ssz = 0
	for i in range(n - 1, -1, -1):
		if t[i] in seen:
			continue
		seen.add(t[i])
		order.append(t[i])
		if ctr[t[i]] % sz:
			print(-1)
			return
		ssz += ctr[t[i]] // sz
		sz -= 1
	s = t[:ssz]
	order = order[::-1]
	q = s
	j = 0
	for char in order:
		nq = ''
		for char0 in q:
			if j >= n or char0 != t[j]:
				print(-1)
				return
			if char0 != char:
				nq += char0
			j += 1
		q = nq
	print(s, ''.join(order))
for nt in range(int(input())):
	solve()


from collections import Counter
t = int(input())
for _ in range(t):
	s = input()
	n = len(s)
	used = set()
	t = []
	c = Counter()
	for i in range(n - 1, -1, -1):
		c[s[i]] += 1
		if s[i] not in used:
			used.add(s[i])
			t.append(s[i])
	t = t[::-1]
	cnt = 0
	flag = True
	for (i, a) in enumerate(t):
		if c[a] % (i + 1) != 0:
			flag = False
			break
		cnt += c[a] // (i + 1)
	new = [s[:cnt]]
	ss = s[:cnt]
	sss = []
	for a in t:
		for b in ss:
			if b != a:
				new.append(b)
				sss.append(b)
		ss = sss
		sss = []
	if ''.join(new) != s:
		flag = False
	if flag:
		print(s[:cnt], ''.join(t))
	else:
		print(-1)


from os import path
from io import BytesIO, IOBase
import sys
from heapq import heappush, heappop
from functools import cmp_to_key as ctk
from collections import deque, Counter, defaultdict as dd
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from itertools import permutations
from datetime import datetime
from math import ceil, sqrt, log, gcd

def ii():
	return int(input())

def si():
	return input().rstrip()

def mi():
	return map(int, input().split())

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def bo(i):
	return ord(i) - ord('a')
file = 1

def ceil(a, b):
	return (a + b - 1) // b

def solve():
	for _ in range(1, ii() + 1):
		s = si()
		n = len(s)
		freq = [0] * 26
		for i in s:
			freq[bo(i)] += 1
		st = []
		for i in range(n - 1, -1, -1):
			if s[i] not in st:
				st.append(s[i])
		r = len(st)
		ok = True
		cnt = 0
		for i in st:
			if freq[bo(i)] % r:
				ok = False
				break
			freq[bo(i)] //= r
			cnt += freq[bo(i)]
			r -= 1
		if ok == False:
			print(-1)
			continue
		st.reverse()
		s1 = s[:cnt]
		(l, r) = (0, cnt)
		for i in st:
			cnt -= freq[bo(i)]
			for j in range(r, r + cnt):
				while l < n and s[l] == i:
					l += 1
				if l >= n or s[l] != s[j]:
					ok = False
					break
				l += 1
			r += cnt
			while l < n and s[l] == i:
				l += 1
		if ok == False:
			print(-1)
		else:
			print(s1, ''.join(st))
if file:
	if path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	else:
		input = sys.stdin.readline
solve()


import traceback
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
sys.stdin = IOWrapper(sys.stdin)
input = lambda : sys.stdin.readline().rstrip('\r\n')
import math
from collections import defaultdict as dfd, Counter, deque
from functools import lru_cache
from itertools import accumulate

def geti():
	return int(input())

def gets():
	return input()

def getil():
	return list(map(int, input().split()))

def getsl():
	return input().split()

def getinps(s):
	inps = s.split()
	m = {'i': geti, 's': gets, 'il': getil, 'sl': getsl}
	if len(inps) == 1:
		return m[s]()
	return [m[k]() for k in inps]

def get2d(nrows, ncols, n=0):
	return [[n] * ncols for r in range(nrows)]

def get_acc(a):
	return list(accumulate(a))

def get_ncr(n, r, mod=10 ** 9 + 7):
	num = den = 1
	r = min(r, n - r)
	for i in range(r):
		num = num * (n - i) % mod
		den = den * (i + 1) % mod
	return num * pow(den, mod - 2, mod) % mod

def get_nc2(n):
	return n * (n - 1) // 2

def get_npr(n, r):
	if n < r:
		return 0
	return math.factorial(n) // math.factorial(r)

def put(a):
	return ' '.join(map(str, a))
inf = float('inf')
mod = 10 ** 9 + 7

def main():
	s = gets()
	cnts = Counter(s)
	seq = []
	seen = set()
	d = len(set(s))
	ln = 0
	for c in s[::-1]:
		if c in seen:
			continue
		if cnts[c] % d != 0:
			return -1
		ln += cnts[c] // d
		seq.append(c)
		d -= 1
		seen.add(c)
	orig = s[:ln]
	seq.reverse()
	t = list(orig)
	z = []
	for c in seq:
		z.extend(t)
		t = [i for i in t if i != c]
	z = ''.join(z)
	seq = ''.join(seq)
	if z == s:
		return orig + ' ' + seq
	else:
		return -1
try:
	Test = geti()
	answers = []
	for _ in range(Test):
		ans = main()
		ans = str(ans)
		answers.append(ans)
	print('\n'.join(answers))
except Exception as e:
	print(e)
	traceback.print_exc()


import sys
input = sys.stdin.readline
from collections import Counter
for i in range(int(input())):
	s = input().strip()
	if len(set(s)) == 1:
		print(s, s[0])
	else:
		l = Counter(s)
		dd = ''
		kin = []
		ll = 0
		rr = 0
		for x in range(len(s)):
			l[s[x]] -= 1
			for i in l:
				if l[i] == 0:
					dd += i
					if len(dd) == 1:
						ll = x
					kin.append(i)
			for i in kin:
				del l[i]
			kin = []
		ss2 = 0
		sp = s[ll + 1:]
		ss1 = s[:ll].replace(dd[0], '')
		for i in range(ll, len(s)):
			ss1 += [s[i], ''][s[i] == dd[0]]
			if sp[:len(ss1)] == ss1 and ss1 != '' and (sp[len(ss1):].find(dd[1]) == -1):
				ss2 = s[:i + 1]
				s = s[i + 1:]
				break
			sp = sp[1:]
		ss1 = ss2
		if ss2 != 0:
			for i in dd:
				ss1 = ss1.replace(i, '')
				if s[:len(ss1)] == ss1:
					s = s[len(ss1):]
				else:
					s += ' '
					break
		if len(s) == 0 and ss2 != 0:
			print(ss2, dd)
		else:
			print(-1)


def nooftimes(s):
	dic = {}
	for i in s:
		if i in dic.keys():
			dic[i] += 1
		else:
			dic[i] = 1
	return dic
t = int(input())
for _ in range(t):
	removed = ''
	s = str(input().rstrip())
	lenin = 0
	dic = nooftimes(s)
	for i in range(len(s) - 1, -1, -1):
		if s[i] not in removed:
			removed = s[i] + removed
	for i in range(len(removed)):
		j = i + 1
		if dic[removed[i]] % j != 0:
			j = -1
			break
		else:
			lenin += int(dic[removed[i]] / j)
	if j != -1:
		r = s[0:lenin]
		l = len(r)
		for i in removed:
			ss = r.replace(i, '')
			sslen = len(ss)
			if ss != s[l:l + sslen]:
				j = -1
				break
			l += sslen
			r = ss
	if j == -1:
		print(j)
	else:
		print(s[0:lenin], removed)


import sys, math
from collections import deque, defaultdict
import operator as op
from functools import reduce
from itertools import permutations
import heapq
I = sys.stdin.readline
alpha = 'abcdefghijklmnopqrstuvwxyz'
mod = 10 ** 9 + 7

def ii():
	return int(I().strip())

def li():
	return list(map(int, I().strip().split()))

def mi():
	return map(int, I().strip().split())

def ncr(n, r):
	r = min(r, n - r)
	numer = reduce(op.mul, range(n, n - r, -1), 1)
	denom = reduce(op.mul, range(1, r + 1), 1)
	return numer // denom

def isPrime(n):
	if n <= 1:
		return False
	elif n <= 2:
		return True
	else:
		for i in range(2, int(n ** 0.5) + 1):
			if n % i == 0:
				return False
		return True

def main():
	ans = ''
	for _ in range(ii()):
		t = I().strip()
		n = len(t)
		ft = defaultdict(int)
		for i in t:
			ft[i] += 1
		check = defaultdict(int)
		x = len(ft)
		rem = ''
		s = ''
		f = 1
		for i in range(n - 1, -1, -1):
			if check[t[i]] == 0:
				check[t[i]] = 1
				rem += t[i]
				if ft[t[i]] % x:
					f = 0
					break
				s += t[i] * (ft[t[i]] // x)
				x -= 1
		if f == 0:
			ans += '-1\n'
		else:
			curr = t[:len(s)]
			i = len(s)
			x = len(rem)
			rem = rem[::-1]
			for j in range(x - 1):
				tmp = ''
				for c in curr:
					if c != rem[j]:
						tmp += c
				if not (i + len(tmp) <= n and t[i:i + len(tmp)] == tmp):
					f = 0
					break
				curr = tmp
				i += len(tmp)
			if f == 0:
				ans += '-1\n'
			else:
				ans += t[:len(s)] + ' ' + rem + '\n'
	print(ans)
main()


import sys

def input():
	return sys.stdin.readline().rstrip('\r\n')

def maps():
	return [int(i) for i in input().split()]
from collections import defaultdict, Counter

def check(se, dic):
	for i in se:
		if not dic[i] and already[ord(i) - 97] == -1:
			already[ord(i) - 97] = 1
			return True
	return False

def check2(d, s2, occ):
	for i in range(len(s2)):
		if d[s2[i]] != occ[i]:
			return False
	return True

def main():
	s = input()
	n = len(s)
	unique = set(s)
	if len(unique) == 1:
		print(s, s[0])
		return
	dic = defaultdict(int)
	global already
	already = [0] * 26
	for i in unique:
		already[ord(i) - 97] = -1
	og = defaultdict(int)
	for i in s:
		dic[i] += 1
		og[i] += 1
	s2 = ''
	for i in range(n):
		dic[s[i]] -= 1
		if check(unique, dic):
			s2 += s[i]
	ok = True
	occ = []
	for i in range(len(s2)):
		if og[s2[i]] % (i + 1):
			ok = False
			break
		else:
			occ.append(og[s2[i]] // (i + 1))
	if ok:
		s1 = ''
		i = 0
		d = defaultdict(int)
		for i in range(n):
			d[s[i]] += 1
			if check2(d, s2, occ):
				s1 = s[:i + 1]
				break
		S = s1
		idx = i
		for i in s2:
			s1 = s1.replace(i, '')
			S += s1
		if S == s:
			print(s[:idx + 1], s2)
		else:
			print(-1)
	else:
		print(-1)
for _ in range(*maps()):
	main()


import sys
import time
input = sys.stdin.readline

def main():
	t = int(input())
	for _ in range(t):
		s = input().strip()
		d = {}
		rev = []
		for i in s:
			if i not in d:
				d[i] = 1
			else:
				d[i] += 1
		for i in s[::-1]:
			if i not in rev:
				rev.append(i)
		num = len(rev)
		first_count = [0] * num
		end = 0
		for i in range(len(rev)):
			if d[rev[i]] % (num - i) != 0:
				end = 1
			else:
				first_count[i] = d[rev[i]] // (num - i)
		if end:
			print(-1)
			continue
		guess = s[:sum(first_count)]
		letters = ''.join(rev)[::-1]
		check = guess
		temp = guess
		for i in letters:
			temp = temp.replace(i, '')
			check += temp
		if s == check:
			print(guess + ' ' + letters)
		else:
			print(-1)
main()


t = int(input())
for i in range(t):
	ttl = 0
	s = input()
	list1 = []
	list3 = []
	for j in range(len(s) - 1, -1, -1):
		if s[j] not in list1:
			list1.append(s[j])
	str1 = ''.join((str(e) for e in list1))
	str2 = str1[::-1]
	map = {}
	for i in str2:
		map[i] = s.count(i)
	index = 1
	for i in str2:
		map[i] = map[i] // index
		index += 1
		ttl += map[i]
	s3 = s[:ttl]
	list69 = []
	list69.append(s3)
	for x in range(0, len(str2)):
		s69 = ''
		for i in list69[x]:
			if i != str2[x]:
				s69 += i
		list69.append(s69)
	s420 = ''.join((str(e) for e in list69))
	if s420 == s:
		print(s3, str2)
	else:
		print(-1)


import sys
sys.setrecursionlimit(10000)

def check(s_str, t_str, my_order):
	t_fin = s_str
	for o in my_order:
		s_str = s_str.replace(o, '')
		t_fin += s_str
	if t_fin == t_str:
		return 0
	elif len(t_fin) == len(t_str):
		return 2
	elif len(t_fin) < len(t_str):
		return -1
	else:
		return 1

def binary_search_on_ans(all_x, t_str, my_order):
	low = 0
	high = len(all_x) - 1
	mid = 0
	while low <= high:
		mid = (high + low) // 2
		res = check(t_str[:all_x[mid]], t_str, my_order)
		if res == -1:
			low = mid + 1
		elif res == 1:
			high = mid - 1
		elif res == 0:
			return all_x[mid]
		else:
			return -1
	return -1
T = int(input())
for _ in range(T):
	t = input()
	order = []
	for x in t[::-1]:
		if x not in order:
			order.append(x)
	order.reverse()
	min_len = max([t.find(x) for x in order]) + 1
	possible_x = range(min_len, len(t) + 1)
	ans = binary_search_on_ans(possible_x, t, order)
	if ans == -1:
		print(-1)
	else:
		print(t[:ans], ''.join(order))


import os, sys
from io import BytesIO, IOBase
from collections import Counter

def main():
	for _ in range(int(input())):
		t = input().strip()
		x = Counter(t)
		left = Counter()
		total = len(x)
		for (idx, i) in enumerate(t):
			left[i] += 1
			tk = set(range(1, total + 1))
			for j in x:
				cou = left[j]
				if not cou or x[j] % cou or x[j] // cou not in tk:
					break
				tk.remove(x[j] // cou)
			else:
				string = t[:idx + 1]
				lst = [0] * len(left)
				for j in left:
					lst[x[j] // left[j] - 1] = j
				ans = [string]
				s1 = string
				for j in lst:
					s2 = s1.replace(j, '')
					ans.append(s2)
					s1 = s2
				if ''.join(ans) == t:
					print(string, ''.join(lst))
				else:
					print(-1)
				break
		else:
			print(-1)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


from collections import Counter, defaultdict, deque
import os, sys
input = lambda : sys.stdin.buffer.readline().rstrip(b'\r\n')

def dbp(*args, **kwargs):
	print(*args, file=sys.stderr, **kwargs)
a_str = lambda : input().decode('ascii')
get_int_list = lambda : [int(x) for x in input().split()]
join_str = lambda l, ch=' ': ch.join((str(x) for x in l))

def do_thing():
	s = a_str()
	n = len(s)
	seen = set()
	rev = []
	for c in s[::-1]:
		if c not in seen:
			rev.append(c)
			seen.add(c)
	order = ''.join(rev[::-1])

	def forward(sub, order):
		idx = 0
		for och in order:
			if och not in sub:
				return False
			idx += len(sub)
			sub = ''.join((c for c in sub if c != och))
			if sub != s[idx:idx + len(sub)]:
				return False
		return True if idx == n and sub == '' else False

	def slow_tries():
		for i in range(1, n + 1):
			sub = s[:i]
			res = forward(sub, order)
			if res:
				break
		else:
			return -1
		return join_str((s[:i], order))

	def backward():
		c = Counter(s)
		sc = Counter()
		for oidx in range(len(order), 0, -1):
			och = order[oidx - 1]
			(q, r) = divmod(c[och], oidx)
			if r != 0:
				return -1
			sc[och] = q
		sub = s[:sum(sc.values())]
		if forward(sub, order):
			return join_str((sub, order))
		else:
			return -1
	r = backward()
	return r

def multicase():
	maxcc = int(input().strip())
	for cc in range(maxcc):
		print(do_thing())
multicase()