You are given a string $s$ consisting only of lowercase Latin letters.

You can rearrange all letters of this string as you wish. Your task is to obtain a good string by rearranging the letters of the given string or report that it is impossible to do it.

Let's call a string good if it is not a palindrome. Palindrome is a string which is read from left to right the same as from right to left. For example, strings "abacaba", "aa" and "z" are palindromes and strings "bba", "xd" are not.

You have to answer $t$ independent queries.


-----Input-----

The first line of the input contains one integer $t$ ($1 \le t \le 100$) — number of queries.

Each of the next $t$ lines contains one string. The $i$-th line contains a string $s_i$ consisting only of lowercase Latin letter. It is guaranteed that the length of $s_i$ is from $1$ to $1000$ (inclusive).


-----Output-----

Print $t$ lines. In the $i$-th line print the answer to the $i$-th query: -1 if it is impossible to obtain a good string by rearranging the letters of $s_i$ and any good string which can be obtained from the given one (by rearranging the letters) otherwise.


-----Example-----
Input
3
aa
abacaba
xdd

Output
-1
abaacba
xdd


-----Note-----

In the first query we cannot rearrange letters to obtain a good string.

Other examples (not all) of correct answers to the second query: "ababaca", "abcabaa", "baacaba".

In the third query we can do nothing to obtain a good string.

Source: codeforces | Difficulty: EASY
Tags: Greedy algorithms

String algorithms

Sorting

Constructive algorithms


Solutions:
from collections import defaultdict
for _ in range(int(input())):
	s = input()
	n = len(s)
	if s.count(s[0]) == n:
		print(-1)
	elif s != s[::-1]:
		print(s)
	else:
		d = defaultdict(lambda : 0)
		for c in s:
			d[c] += 1
		for c in d:
			for _ in range(d[c]):
				print(c, end='')
		print()


n = int(input())
for i in range(n):
	s = list(input())
	s.sort()
	b = 0
	x = s[0]
	for i in s:
		if i != x:
			b = 1
			break
	if not b:
		print(-1)
	else:
		for i in s:
			print(i, end='')
		print()


def palindrome(x):
	if x[len(x)::-1] == x[0:len(x)]:
		return True
	else:
		return False

def count(x):
	count = 0
	for k in range(1, len(x)):
		if x[k - 1] == x[k]:
			count += 1
	return count + 1

def change(x):
	for k in range(1, len(x)):
		if x[k - 1] != x[k]:
			index = k
			break
	return x[0:k] + x[k + 1:] + x[k]
x = int(input())
for l in range(x):
	y = input().strip()
	if palindrome(y) == True:
		if len(y) == 2:
			print('-1')
		elif count(y) == len(y):
			print('-1')
		else:
			print(change(y))
	else:
		print(y)


t = int(input())
for u in range(t):
	S = input()
	S = sorted(S)
	print([-1, ''.join(S)][S[0] != S[-1]])


n = int(input())
for i in range(n):
	s = input()
	s = sorted(s)
	s = ''.join(s)
	if s[0:] == s[::-1]:
		print(-1)
	else:
		print(s)


for j in range(int(input())):
	s = list(input())
	if s != s[::-1]:
		print(''.join(s))
	elif len(list(set(s))) == 1:
		print(-1)
	else:
		i = 0
		while s == s[::-1]:
			(s[i], s[i + 1]) = (s[i + 1], s[i])
			i += 1
		print(''.join(s))


n = int(input())
for i in range(n):
	ss = ''
	s = list(input())
	x = s[:]
	s.reverse()
	if len(set(s)) == 1:
		print(-1)
	else:
		s.sort()
		for j in s:
			ss += j
		print(ss)
		ss = ''


n = int(input())
l = list()
for i in range(n):
	l.append(input())

def f1(s):
	b = True
	for i in range(len(s)):
		if s[i] != s[-(i + 1)]:
			b = False
	return b

def f2(s):
	if len(s) == 1:
		return True
	elif s.count(s[0]) == len(s):
		return True
	else:
		return False

def f3(s):
	for i in s:
		for j in s:
			if i != j:
				s = s.replace(j, i, 1)
				s = s.replace(i, j, 1)
				return s
for i in l:
	if f1(i):
		if f2(i):
			print(-1)
		else:
			print(f3(i))
	else:
		print(i)


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

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

def si():
	return input()

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

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

def li():
	return list(mi())

def dmain():
	sys.setrecursionlimit(100000000)
	threading.stack_size(40960000)
	thread = threading.Thread(target=main)
	thread.start()
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'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}
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def getKey(item):
	return item[1]

def sort2(l):
	return sorted(l, key=getKey, reverse=True)

def d2(n, m, num):
	return [[num for x in range(m)] for y in range(n)]

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

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

def ntl(n):
	return [int(i) for i in str(n)]

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

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

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

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

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

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

def main():
	for _ in range(ii()):
		s = list(si())
		s.sort()
		n = len(s)
		if s == s[::-1]:
			print(-1)
		else:
			print(''.join(s))
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()


n = int(input())
for i in range(n):
	a = list(input())
	if len(set(a)) == 1:
		print(-1)
	else:
		b = sorted(a)
		print(''.join(b))


t = int(input())
arr = []
for i in range(t):
	arr.append(input())
help = []
for i in range(len(arr)):
	for j in range(len(arr[i])):
		if not arr[i][j] in help:
			help.append(arr[i][j])
	if len(help) == 1:
		print(-1)
	else:
		ex = help[0]
		y = 1
		while ex == help[y]:
			y += 1
		index1 = arr[i].index(help[y], 0, len(arr[i]))
		print(ex + ''.join(arr[i][1:index1]) + ''.join(arr[i][index1 + 1:]) + help[y])
	help[:] = []


t = int(input())
while t > 0:
	t = t - 1
	s = [i for i in input()]
	if len(set(s)) == 1:
		print(-1)
	else:
		f = [0] * 26
		for i in s:
			f[ord(i) - ord('a')] += 1
		p = ''
		for i in range(26):
			if f[i] > 0:
				p += chr(i + ord('a'))
				f[i] -= 1
		for i in range(26):
			while f[i] > 0:
				p += chr(i + ord('a'))
				f[i] -= 1
		f1 = 0
		for i in range(len(s) // 2):
			if p[i] != p[len(s) - i - 1]:
				f1 = 1
				break
		if f1:
			print(p)
		else:
			p = [i for i in p]
			(p[0], p[1]) = (p[1], p[0])
			print(''.join(p))


t = int(input())
for _ in range(t):
	a = str(input())
	b = [i for i in a]
	for i in range(len(b) - 1):
		g = b[i]
		if g != b[i + 1]:
			if a[:] == a[::-1]:
				print(a[1:] + a[0])
				break
			elif a[:] != a[::-1]:
				print(a)
				break
	else:
		print(-1)


t = int(input())
for j in range(t):
	s = input()
	if s != s[::-1]:
		print(s)
	else:
		lenght = len(s)
		s = list(s)
		letters = set(s)
		if len(letters) == 1:
			print(-1)
		else:
			while s == s[::-1]:
				for i in range(lenght - 1):
					(s[i], s[i + 1]) = (s[i + 1], s[i])
			s = ''.join(s)
			print(s)


t = int(input())
for i in range(t):
	stringz = input()
	if len(stringz) == 1:
		print(-1)
	else:
		for i in range(len(stringz) - 1, -1, -1):
			flag = 0
			if stringz[i] != stringz[0]:
				flag = 1
				if i != len(stringz):
					print(stringz[i] + stringz[1:i] + stringz[0] + stringz[i + 1:])
				else:
					print(i + stringz[1:i] + stringz[0])
				break
		if flag == 0:
			print(-1)


def isHS(s):
	c = s[0]
	l = len(s)
	return c * l == s

def palindrome(s):
	l = len(s)
	for i in range(0, l):
		if s[i] == s[l - 1 - i]:
			pass
		else:
			return False
	return True
t = int(input())
tcases = []
for p in range(0, t):
	tcases.append(input())
for tcase in tcases:
	if isHS(tcase):
		print('-1')
	elif palindrome(tcase):
		l = len(tcase)
		l_s = list(tcase)
		a = -1
		b = -2
		for i in range(0, len(l_s) // 2):
			if l_s[i] == l_s[i + 1]:
				pass
			else:
				a = i
				b = i + 1
				break
		temp = l_s[a]
		l_s[a] = l_s[b]
		l_s[b] = temp
		print(''.join(l_s))
	else:
		print(tcase)


t = int(input())
for i in range(t):
	s = input()
	l = list(s)
	l.sort()
	if l[0] == l[len(l) - 1]:
		print(-1)
	else:
		s = ''.join(l)
		print(s)


T = int(input())
for q in range(T):
	s = input()
	s1 = sorted(s)
	s2 = sorted(s, reverse=True)
	if s1 == s2:
		print(-1)
	else:
		print(''.join(s1))


a = int(input())
for i in range(a):
	c = 1
	b = input()
	d = len(b)
	for j in range(1, d):
		if b[j] != b[j - 1]:
			c = 0
			x = j - 1
			y = j
			break
	if c == 1:
		print('-1')
		continue
	for j in range(d // 2 + 1):
		if b[j] != b[d - j - 1]:
			print(b)
			break
	else:
		print(b[:x] + b[y] + b[x] + b[y + 1:])


def solve(s):
	s = ''.join(sorted(s))
	if s == s[::-1]:
		return -1
	else:
		return s
t = int(input())
for _ in range(t):
	x = input()
	print(solve(x))


t = int(input())
good = False
for case in range(t):
	s = input()
	r = s[::-1]
	if len(s) == 1:
		print(-1)
	elif len(s) == 2:
		if s[0] == s[1]:
			print(-1)
		else:
			print(s[1] + s[0])
	elif s == r:
		for i in range(1, len(s)):
			if s[i] != s[i - 1]:
				s = s[:i - 1] + s[i] + s[i - 1] + s[i + 1:]
				print(s)
				good = True
				break
		if not good:
			print(-1)
		good = False
	else:
		print(s)


def isPalindrome(string):
	return string == string[::-1]
testcases = int(input())
for _ in range(testcases):
	string = input()
	if not isPalindrome(string):
		print(string)
	elif len(set(string)) == 1:
		print('-1')
	else:
		string = list(string)
		for i in range(0, len(string) // 2):
			if string[i] != string[i + 1]:
				(string[i], string[i + 1]) = (string[i + 1], string[i])
				break
		print(''.join(string))


t = int(input())
for q in range(t):
	s = sorted(list(input()))
	if s[0] == s[-1]:
		print(-1)
	else:
		print(*s, sep='')


import sys
for s in sys.stdin.read().splitlines()[1:]:
	print(-1 if len(set(s)) == 1 else ''.join(sorted(s)))


def good(word):
	temp = word[::-1]
	if temp != word:
		return word
	k = word[0]
	num = 0
	for i in range(len(word)):
		if k == word[i]:
			num += 1
		else:
			word1 = ''
			for j in range(len(word)):
				if j == 0:
					word1 += word[i]
				elif j == i:
					word1 += k
				else:
					word1 += word[j]
			break
	if num == len(word):
		return -1
	return word1
t = int(input())
strings = []
for i in range(t):
	word = input()
	strings.append(good(word))
for i in range(t):
	print(strings[i])


u = int(input())
for _ in range(u):
	a = input()
	a = list(a)
	a.sort()
	if a[0] == a[-1]:
		print(-1)
	else:
		print(''.join(a))


MOD = 10 ** 9 + 7
I = lambda : list(map(int, input().split()))
from collections import Counter as C
(t,) = I()
while t:
	t -= 1
	s = input()
	d = C(s)
	if len(d) == 1:
		print(-1)
	else:
		for i in d:
			print(i * d[i], end='')
		print()


t = int(input())
for i in range(t):
	s = input()
	flag = False
	for i in range(len(s)):
		if s[0] != s[i]:
			ans = s[:i] + s[i + 1:] + s[i]
			print(ans)
			flag = True
			break
	if not flag:
		print(-1)


def good_string(s: str) -> str:
	chars = [c for c in s]
	chars.sort()
	forward_s = ''.join(chars)
	chars.sort(reverse=True)
	reversed_s = ''.join(chars)
	return '-1' if forward_s == reversed_s else forward_s

def main():
	for _ in range(int(input())):
		print(good_string(input()))
main()


def isGoodString(data):
	srt = sorted(data)
	if srt[0] == srt[-1]:
		print(-1)
	else:
		data = ''
		data = data.join(srt)
		print(data)
count = int(input())
for i in range(count):
	isGoodString(input())


n = int(input())
for _ in range(n):
	s = sorted(input())
	if s == s[::-1]:
		print(-1)
	else:
		print(*s, sep='')


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
import random
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def main():
	n = I()
	aa = [S() for _ in range(n)]
	rr = []
	for s in aa:
		c = collections.Counter(s)
		if len(c) == 1:
			rr.append(-1)
		else:
			rr.append(''.join(sorted([c for c in s])))
	return '\n'.join(map(str, rr))
print(main())


n = int(input())

def palindrome(n):
	if n[::-1] == n:
		return True
	return False
for l in range(n):
	m = input()
	s = m[0]
	true = True
	for i in m:
		if i != s:
			true = False
	if true:
		print(-1, end='')
	elif palindrome(m):
		h = m
		m = []
		for i in h:
			m += [i]
		if len(m) % 2 == 1:
			s = len(m) // 2
			for i in range(s):
				if m[s] != m[i]:
					(m[i], m[s]) = (m[s], m[i])
					break
		else:
			true = False
			for i in range(len(m) // 2):
				for j in range(i, len(m) // 2 + 1):
					if m[i] != m[j]:
						(m[i], m[j]) = (m[j], m[i])
						true = True
					if true:
						break
				if true:
					break
		for i in m:
			print(i, end='')
	else:
		print(m, end='')
	print()


for i in range(int(input())):
	s = input()
	if len(set(s)) == 1:
		print(-1)
	elif s != s[::-1]:
		print(s)
	else:
		print(s[0] + s[2:] + s[1])


t = int(input())
while t > 0:
	s = input()
	news = ''
	flag = 0
	flag2 = 0
	if len(s) == 1:
		print(-1)
	elif s != s[::-1]:
		print(s)
	else:
		for i in range(0, len(s)):
			if flag == 0 and s[i] != 'a':
				if i != len(s) - 1 and s[i + 1] != s[i]:
					ch = s[i]
					news = news + s[i + 1]
					news += ch
					flag = 1
					flag2 = 1
				else:
					news += s[i]
			else:
				if flag2 == 0:
					news += s[i]
				flag2 = 0
		if news == s:
			print(-1)
		else:
			print(news)
	t -= 1


t = int(input())
for i in range(t):
	s = list(str(input()))
	if len(list(set(s))) == 1:
		print(-1)
	else:
		s.sort()
		print(''.join(s))


def palindrome(l):
	d = {}
	for i in l:
		if i in d.keys():
			d[i] += 1
		else:
			d[i] = 1
	if len(d) == 1:
		return -1
	else:
		s = ''
		for (key, value) in d.items():
			for i in range(value):
				s += key
		return s
n = int(input())
for i in range(n):
	l = list(input())
	print(palindrome(l))


def is_p(x):
	return x == ''.join(x[::-1])
t = int(input())
for _ in range(t):
	x = input()
	v = ''.join(sorted(x))
	if is_p(v):
		print(-1)
	else:
		print(v)


for _ in range(int(input().strip())):
	s = input().strip()
	if len(set(s)) == 1:
		print(-1)
		continue
	if s != s[::-1]:
		print(s)
		continue
	s = list(s)
	for i in range(len(s) - 1):
		if s[i] != s[i + 1]:
			(s[i], s[i + 1]) = (s[i + 1], s[i])
			break
	print(''.join(s))


t = int(input())
for i in range(t):
	word = input()
	L = []
	for letter in word:
		if letter not in L:
			L.append(letter)
	if len(L) < 2:
		print(-1)
	else:
		print(''.join(sorted(word)))


def palin(x):
	d = 0
	for i in range(len(x) // 2):
		if x[i] == x[-1 * (i + 1)]:
			d += 1
	return True if len(x) // 2 == d else False

def solve():
	s = input()
	if not palin(s):
		print(s)
	else:
		s = list(s)
		for j in range(len(s) - 1):
			if s[j] != s[j + 1]:
				c = s[j]
				s[j] = s[j + 1]
				s[j + 1] = c
				print(''.join(s))
				break
		else:
			print(-1)
for _ in range(int(input())):
	solve()


t = int(input())
for j in range(t):
	a = list(input())
	n = len(a)
	alpha = 0
	for i in range(n // 2):
		if a[i] == a[n - 1 - i]:
			alpha = 1
		else:
			alpha = 0
			break
	if alpha == 0 and n != 1:
		print(''.join(a))
	else:
		b = list(set(a))
		if len(b) == 1:
			print('-1')
		else:
			a.sort()
			print(''.join(a))


t = int(input())
for i in range(t):
	s = str(input())
	dif = 0
	for j in range(97, 123):
		if chr(j) in s:
			dif += 1
	if dif == 1:
		print(-1)
		continue
	if s[0:len(s) // 2 + 1] == ''.join(reversed(s[len(s) // 2:])) and len(s) % 2 == 1:
		print(''.join(sorted(s)))
		continue
	if s[0:len(s) // 2] == ''.join(reversed(s[len(s) // 2:])) and len(s) % 2 == 0:
		print(''.join(sorted(s)))
		continue
	print(s)


for _ in range(int(input())):
	l = list(input())
	s = set(l)
	if len(s) == 1:
		print(-1)
	else:
		l.sort()
		print(''.join(l))


t = int(input())
for l in range(t):
	s = str(input())
	count = {}
	for i in s:
		if i in count:
			count[i] += 1
		else:
			count[i] = 1
	revs = s[::-1]
	if revs == s:
		if len(count) == 1:
			print(-1)
		else:
			print(''.join(sorted(s)))
	else:
		print(s)


t = int(input())
for i in range(t):
	s = ''.join(sorted(input()))
	if s == s[::-1]:
		print(-1)
	else:
		print(s)


x = int(input())
for i in range(x):
	string = list(map(str, input()))
	if string.count(string[0]) == len(string):
		print(-1)
		continue
	counter = 0
	while string == string[::-1]:
		while string[counter] == string[counter + 1] and counter < len(string):
			counter += 1
		(string[counter], string[counter + 1]) = (string[counter + 1], string[counter])
	for i in string:
		print(i, end='')
	print()


A = []
T = int(input())
for i in range(T):
	A.append(input())
for X in A:
	X = sorted(X)
	print(-1 if len(set(X)) == 1 else ''.join(X))


l = []
k = []
b = []
a = int(input())
for i in range(a):
	c = input()
	l.append(c)
for i in range(a):
	k = []
	check = len(set(l[i])) == 1
	if check == True:
		print('-1')
	else:
		b = list(l[i])
		b.sort()
		str1 = ''.join(b)
		print(str1)


def ispal(x):
	return x == x[::-1]
T = int(input())
for t in range(0, T):
	s = input()
	ss = ''.join(sorted(s))
	if ispal(ss):
		print(-1)
	else:
		print(ss)


for cas in range(int(input())):
	s = input()
	s = list(s)
	ln = len(s)
	s.sort()
	if s[0] == s[-1]:
		print(-1)
	else:
		print(''.join(s))


for _ in range(int(input())):
	s = input()
	if len(set(s)) == 1:
		print(-1)
	else:
		r = ''.join(sorted(s))
		print(str(r))


t = int(input())
for k in range(t):
	a = str(input())
	n = len(a)
	p = 0
	if n % 2 == 0:
		m = n // 2
	else:
		m = n // 2 + 1
	for i in range(m):
		if a[i] != a[n - i - 1]:
			p = 1
	if p == 0:
		if a.count(a[0]) != len(a):
			b = []
			b.append(a[n - 1])
			for i in range(0, n - 1):
				b.append(a[i])
			for i in range(0, n):
				print(b[i], end='')
			print()
		else:
			print(-1)
	else:
		print(a)


t = int(input())
for i in range(t):
	ind = list()
	s = input()
	for j in s:
		ind.append(ord(j))
	ind.sort()
	if ind[0] == ind[-1]:
		print(-1)
	else:
		s = str()
		for i in ind:
			s += chr(i)
		print(s)


def pal(s):
	for i in range(0, len(s)):
		if s[i] != s[len(s) - 1 - i]:
			return False
	return True

def applicable(s):
	char = s[0]
	for c in s:
		if c != char:
			return True
	return False

def swap(s, i):
	ch = list(s)
	(ch[0], ch[i]) = (ch[i], ch[0])
	return ''.join(ch)

def unpal(s):
	return s[1:] + s[0]
n = int(input())
for i in range(n):
	s = input()
	if not pal(s):
		print(s)
	elif not applicable(s):
		print(-1)
	else:
		print(unpal(s))


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

def similar(s, p):
	for i in range(1, p):
		if s[i] != s[i - 1]:
			return i
	return 0
t = int(input())
for i in range(t):
	S = input()
	n = len(S)
	if n == 1:
		print('-1')
	else:
		x = palindrome(S, n)
		if x == True:
			y = similar(S, n)
			if y == 0:
				print('-1')
			else:
				P = list(S)
				z = P[y]
				P[y] = P[y - 1]
				P[y - 1] = z
				Q = ''
				for i in range(n):
					Q = Q + P[i]
				print(Q)
		else:
			print(S)


for t in range(int(input())):
	s = input()
	l = list(s)
	n = len(l)
	flag = True
	for (i, j) in zip(range(n), range(n - 1, -1, -1)):
		if i >= j:
			break
		if l[i] != l[j]:
			flag = False
			break
	if flag == False:
		print(s)
	else:
		flag = True
		for i in range(n - 1):
			if l[i] != l[i + 1]:
				temp = l[i]
				l[i] = l[i + 1]
				l[i + 1] = temp
				flag = False
				break
		if flag:
			print('-1')
		else:
			ans = ''
			for i in range(n):
				ans += l[i]
			print(ans)


from collections import Counter

def isPalindrome(word):
	if len(word) % 2 == 0:
		return word[:len(word) // 2] == word[len(word) // 2:][::-1]
	else:
		return word[:len(word) // 2] == word[len(word) // 2 + 1:][::-1]

def rearrange(word):
	rearranged_string = ''
	freq = Counter(word)
	for letter in set(word):
		rearranged_string += letter * freq[letter]
	return rearranged_string
for _ in range(int(input())):
	word = input()
	if not isPalindrome(word):
		print(word)
	elif len(set(word)) == 1:
		print(-1)
	else:
		print(rearrange(word))


for i in range(int(input())):
	s = input()
	s1 = s[::-1]
	if s != s1:
		print(s)
	elif len(set(s)) == 1:
		print(-1)
	else:
		a = len(s) // 2
		while a != len(s):
			if s[a] == s[a + 1]:
				a += 1
			else:
				print(s[:a] + s[a + 1] + s[a] + s[a + 2:])
				break


for i in range(int(input())):
	palavra = input()
	h = 0
	for j in range(len(palavra)):
		if palavra != palavra[::-1]:
			h = 1
			print(palavra)
			break
		aux = palavra[0]
		palavra += aux
		palavra = palavra[1:]
	if h == 0:
		print(-1)


T = int(input())
for i in range(T):
	s = input()
	if s != s[::-1]:
		print(s)
	elif s == s[::-1]:
		if s.count(s[-1]) == len(s):
			print(-1)
		else:
			print(s[1:] + s[0])


def solve(st):
	s = list(st)
	ss = sorted(s)
	if len(set(s)) == 1:
		print(-1)
	else:
		print(''.join(ss))
for _ in range(int(input())):
	s = str(input())
	solve(s)


for t in range(int(input())):
	s1 = input()
	if s1.count(s1[0]) == len(s1):
		print(-1)
	elif s1 == s1[::-1]:
		set1 = set(s1)
		l1 = list(set1)
		i1 = s1.index(l1[0])
		i2 = s1.index(l1[1])
		if i1 < i2:
			s2 = s1[:i1] + s1[i2] + s1[i1 + 1:i2] + s1[i1] + s1[i2 + 1:]
			print(s2)
		elif i2 < i1:
			s2 = s1[:i2] + s1[i1] + s1[i2 + 1:i1] + s1[i2] + s1[i1 + 1:]
			print(s2)
	else:
		print(s1)


from collections import Counter
t = int(input())
while t != 0:
	string = input()
	cnt = dict(Counter(string))
	if len(cnt) == 1:
		print(-1)
	else:
		print(''.join(sorted(string)))
	t -= 1


n = int(input())
for i in range(n):
	s = input()
	lis = []
	if s != s[::-1]:
		print(s)
	else:
		for j in range(len(s)):
			lis.append(s[j])
		lis1 = set(lis)
		if len(lis1) == 1:
			print(-1)
		else:
			f = 0
			d = -1
			for j in range(0, len(s) - 1):
				if s[j] != s[j + 1] and f == 0:
					d = j
					f = 1
			print(s[0:d], end='')
			print(s[d + 1], end='')
			print(s[d], end='')
			print(s[d + 2:len(s)])


a = int(input())
for x in range(a):
	b = list(input())
	if len(set(b)) == 1:
		print(-1)
	else:
		for x in range(len(b) // 2):
			if b[x] == b[len(b) - 1 - x]:
				l = 1
			else:
				l = 0
				break
		if l == 0:
			m = ''.join(b)
			print(m)
		else:
			b.sort()
			n = ''.join(b)
			print(n)


read = lambda : [int(i) for i in input().split()]
t = int(input())
while t > 0:
	t -= 1
	s = input()
	s_sort = sorted(s)
	if s_sort[0] == s_sort[-1]:
		print(-1)
	else:
		print(''.join(s_sort))


for _ in range(int(input())):
	x = input()
	f = 1
	for i in range(1, len(x)):
		if x[i] != x[0]:
			f = 0
			break
	if f == 1:
		print('-1')
	else:
		a = sorted(list(x.strip()))
		for i in a:
			print(i, end='')
		print()


n = int(input())
for i in range(n):
	x = str(input())
	letters = set()
	for q in x:
		letters.add(q)
	if len(letters) == 1:
		print('-1')
	else:
		z = sorted(x)
		sp = ''
		for c in z:
			sp += c
		print(sp)


n = int(input())
for i in range(n):
	s = input()
	count = [0] * 26
	for i in range(len(s)):
		count[ord(s[i]) - 97] += 1
	cnt = 0
	for i in range(26):
		if count[i] != 0:
			cnt += 1
	s1 = ''
	if cnt > 1:
		for i in range(26):
			for j in range(count[i]):
				s1 = s1 + chr(i + 97)
		print(s1)
	else:
		print(-1)


t = int(input())
for I in range(t):
	s = input()
	b = list(s)
	b.sort()
	s = ''.join(b)
	s1 = s[::-1]
	if s == s1:
		print(-1)
	else:
		print(s1)


for i in range(int(input())):
	l = [i for i in str(input())]
	l.sort()
	if l[0] == l[-1]:
		print(-1)
	else:
		print(*l, sep='')


t = int(input())
for _ in range(t):
	s = input()
	set_s = set(s)
	if len(set_s) == 1:
		print(-1)
	else:
		a = -1
		b = -1
		arr = [i for i in s]
		ans = [0] * len(s)
		for i in range(len(arr)):
			if a == -1:
				a = arr[i]
				arr[i] = -1
			elif arr[i] != a and b == -1:
				b = arr[i]
				arr[i] = -1
				break
		ans[0] = a
		ans[-1] = b
		idx = 0
		for i in range(1, len(ans) - 1):
			while arr[idx] == -1:
				idx += 1
			ans[i] = arr[idx]
			idx += 1
		print(''.join(map(str, ans)))


t = int(input())
for i in range(t):
	s = input()
	rs = s[::-1]
	if s == rs:
		if len(s) <= 2:
			print(-1)
		else:
			x = int(len(s) / 2)
			y = 0
			for i in range(x, len(s)):
				if s[x] != s[i]:
					ch = s[x]
					mylist = list(s)
					mylist[x] = s[i]
					mylist[i] = ch
					makeitastring = ''.join(map(str, mylist))
					print(makeitastring)
					y = 1
					break
			if y == 0:
				print(-1)
	else:
		print(s)


t = int(input())
while t > 0:
	a = input()
	l = len(a)
	x = ''
	if l == 1:
		print(-1)
	elif l == 2:
		if a == a[0] * 2:
			print(-1)
		else:
			print(a)
	else:
		k = 0
		if a[0] != a[-1]:
			print(a)
		else:
			a = list(a)
			for i in range(l):
				if a[i] != a[0]:
					x = a[i]
					a[i] = a[0]
					a[0] = x
					k = 1
					break
			if k == 1:
				print(''.join(a))
			else:
				print(-1)
	t -= 1


def main():
	for _ in range(int(input())):
		s = input()
		s = sorted(s)
		if s == s[::-1]:
			print(-1)
		else:
			print(''.join(s))
	return 0
main()


n = int(input())
for item in range(n):
	l = input()
	if len(set(l)) == 1:
		print(-1)
	else:
		print(''.join(sorted(l)))


n = int(input())
strs = []

def isL(s, fisrt):
	ss = list(s)
	newss = []
	for i in range(len(ss)):
		newss.append(ss[len(ss) - i - 1])
	if str(ss) == str(newss) and fisrt == True:
		l = sorted(ss)
		return isL(''.join(l), False)
	if str(ss) == str(newss) and fisrt == False:
		return -1
	else:
		return s
result = []
for i in range(n):
	result.append(isL(input(), True))
for i in range(n):
	print(result[i])


t = int(input())
for _ in range(t):
	s = input()
	L = list(s)
	L.sort()
	if L[0] != L[len(L) - 1]:
		print(''.join(map(str, L)))
	else:
		print(-1)


n = int(input())
for i in range(n):
	s = input()
	if s != s[::-1]:
		print(s)
	elif len(s) == 1:
		print(-1)
	elif len(s) == 2 and s[0] == s[1]:
		print(-1)
	else:
		b = 0
		for i in range(len(s) - 2):
			a = s[:i] + s[i + 1] + s[i] + s[i + 2:]
			if a != s:
				print(a)
				break
			elif b == len(s) - 3:
				print(-1)
			elif a == s:
				b += 1


import math
import sys
import bisect
t = int(input())
for _ in range(t):
	s = input()
	d = {}
	for i in range(len(s)):
		if d.get(s[i], -1) == -1:
			d[s[i]] = []
		d[s[i]].append(i)
	ch = 0
	for i in d:
		if len(d[i]) == len(s):
			ch = 1
	if ch == 1:
		print(-1)
	else:
		for i in d:
			for j in range(len(d[i])):
				print(i, end='')
		print()


for _ in range(int(input())):
	s = input()
	sorted_s = sorted(s)
	if sorted_s[0] == sorted_s[-1]:
		print(-1)
	else:
		print(''.join(sorted_s))


for _ in range(int(input())):
	s = input()
	if len(set(list(s))) == 1:
		print(-1)
	elif s[::-1] != s:
		print(s)
	else:
		for i in range(1, len(s)):
			if s[i] != s[0]:
				print(s[i] + s[1:i] + s[0] + s[i + 1:])
				break


n = int(input())
for i in range(n):
	s = list(str(input()))
	success = False
	if s != s[::-1]:
		print(''.join(s))
		continue
	for i in range(1, len(s)):
		if s[i] != s[0]:
			(s[i], s[0]) = (s[0], s[i])
			print(''.join(s))
			success = True
			break
	if not success:
		print(-1)


n = int(input())
for i in range(n):
	s = input()
	flag = False
	for i in range(len(s)):
		if s[i] != s[0]:
			flag = True
			break
	if not flag:
		print(-1)
		continue
	flag = True
	for i in range(len(s) // 2):
		if s[i] != s[len(s) - i - 1]:
			flag = False
			break
	if not flag:
		print(s)
		continue
	for i in range(len(s)):
		if s[i] != s[0]:
			ans = s[i] + s[1:i] + s[0] + s[i + 1:]
			print(ans)
			break


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import *
from copy import *
from collections import deque
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
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))
from types import GeneratorType

def iterative(f, stack=[]):

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

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

def out(var):
	sys.stdout.write(str(var))

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

def stringlis():
	return list(map(str, inp().split()))

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

def strsep():
	return map(str, inp().split())

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def solve():
	s = inp()
	n = len(s)
	if s.count(s[0]) == n:
		print(-1)
	else:
		k = sorted(s)
		print(''.join(k))
testcase(int(inp()))


for _ in range(int(input())):
	l = list(input())
	if len(set(l)) == 1:
		print(-1)
	else:
		print(''.join(sorted(l)))


for _ in range(int(input())):
	s = input()
	first = s[0]
	l = len(s)
	if s == first * l:
		print(-1)
	elif s != s[::-1]:
		print(s)
	else:
		f = 0
		copy = list(s)
		for i in range(l - 1):
			if s[i] != s[i + 1]:
				f = 1
				(copy[i], copy[i + 1]) = (copy[i + 1], copy[i])
				break
		if f == 0:
			print(-1)
		else:
			print(''.join(copy))


def good(s):
	return s == s[::-1]
for _ in range(int(input())):
	s = str(input())
	t = False
	if good(s):
		for i in range(len(s)):
			if i + 1 != len(s) and s[i] != s[i + 1]:
				ans = s[:i] + s[i + 1] + s[i] + s[i + 2:]
				t = True
				break
		print(ans if t == True else -1)
	else:
		print(s)


def is_palindrom(word):
	n = int(len(word) / 2) + (len(word) + 1) % 2
	for i in range(0, n):
		if word[i] != word[-i - 1]:
			return False
	return True
t = input()
for i in range(0, int(t)):
	word = input()
	if not is_palindrom(word):
		print(word)
	elif word.count(word[0]) == len(word):
		print('-1')
	else:
		s = list(word)
		for j in range(1, len(s)):
			if s[0] != s[j]:
				s[0] = s[j]
				s[j] = s[-1]
				print(''.join(s))
				break


import re
import sys
exit = sys.exit
from bisect import bisect_left as bsl, bisect_right as bsr
from collections import Counter, defaultdict as ddict, deque
from functools import lru_cache
cache = lru_cache(None)
from heapq import *
from itertools import *
from math import inf
from pprint import pprint as pp
enum = enumerate
ri = lambda : int(rln())
ris = lambda : list(map(int, rfs()))
rln = sys.stdin.readline
rl = lambda : rln().rstrip('\n')
rfs = lambda : rln().split()
cat = ''.join
catn = '\n'.join
mod = 1000000007
d4 = [(0, -1), (1, 0), (0, 1), (-1, 0)]
d8 = [(-1, -1), (0, -1), (1, -1), (-1, 0), (1, 0), (-1, 1), (0, 1), (1, 1)]

def solve(s):
	n = len(s)
	for i in range(n // 2):
		if s[i] != s[~i]:
			return s
		for j in range(i + 1, n - i):
			if s[i] != s[j]:
				a = list(s)
				(a[i], a[j]) = (a[j], a[i])
				return cat(a)
		else:
			break
	return -1
t = ri()
for _ in range(t):
	s = rl()
	print(solve(s))


a = int(input())
for i in range(a):
	T = []
	TXT = input()
	if TXT == TXT[::-1]:
		T = [e for e in TXT if e != TXT[0]]
		if T == []:
			print(-1)
		else:
			txt = [e for e in TXT]
			for i in range(len(txt) - 1):
				z = txt[i + 1]
				txt[i + 1] = txt[i]
				txt[i] = z
			txt = ''.join(txt)
			print(txt)
	else:
		print(TXT)


from sys import stdin, stdout
for k in range(int(input())):
	x = stdin.readline().rstrip()
	if x != x[::-1]:
		stdout.write(x + '\n')
	else:
		flag = True
		b = 0
		for p in range(len(x)):
			if x[0] != x[p]:
				flag = False
				b = p
		if flag:
			print(-1)
		else:
			a = 0
			stdout.write(x[:a] + x[b] + x[a + 1:b] + x[a] + x[b + 1:] + '\n')


for j in range(int(input())):
	s = input()
	t = set(s)
	a = ''
	if len(t) == 1:
		print(-1)
	else:
		for i in t:
			a = a + i * s.count(i)
		print(a)


t = int(input())
for _ in range(t):
	s = input()
	n = len(s)
	if n == 1:
		print(-1)
		continue
	if len(set(list(s))) == 1:
		print(-1)
		continue
	s = sorted(s)
	print(''.join(s))


n = int(input())
a = []
ans = [0] * n
for i in range(n):
	a1 = input()
	a.append(list(a1))
for i in range(n):
	if len(set(a[i])) == 1:
		ans[i] == -1
		continue
	if a[i][0] != a[i][-1]:
		ans[i] = ''.join(map(str, a[i]))
	else:
		for j in range(len(a[i])):
			if a[i][j] != a[i][0]:
				(a[i][0], a[i][j]) = (a[i][j], a[i][0])
				break
		ans[i] = ''.join(map(str, a[i]))
for i in range(len(ans)):
	if ans[i] == 0:
		ans[i] = -1
	print(ans[i])


list = []
n = int(input())
for i in range(n):
	list.append(str(input()))
for i in range(n):
	k = sorted(list[i])
	if k[0] == k[-1]:
		print(-1)
	else:
		print(''.join(k))


import sys
import math
fileoperation = 0
if fileoperation:
	orig_stdout = sys.stdout
	orig_stdin = sys.stdin
	inputfile = open('W:/Competitive Programming/input.txt', 'r')
	outputfile = open('W:/Competitive Programming/output.txt', 'w')
	sys.stdin = inputfile
	sys.stdout = outputfile
mod = 1000000007
t = int(input())
for tt in range(t):
	s = str(input())
	s = list(s)
	s.sort()
	if s == s[::-1]:
		print(-1)
	else:
		b = ''
		for ss in s:
			b += ss
		print(b)
if fileoperation:
	sys.stdout = orig_stdout
	sys.stdin = orig_stdin
	inputfile.close()
	outputfile.close()


for i in range(int(input())):
	s = input()
	s1 = ''
	for j in set(s):
		s1 += j * s.count(j)
	print(-1 if len(set(s)) == 1 else s1)


from collections import deque
T = int(input())
xT = [deque(input()) for i in range(T)]
for i in range(T):
	if ''.join(xT[i]) == ''.join(reversed(xT[i])):
		tmp = xT[i].popleft()
		xT[i].append(tmp)
		if ''.join(xT[i]) != ''.join(reversed(xT[i])):
			print(''.join(xT[i]))
		else:
			print(-1)
	else:
		print(''.join(xT[i]))


for _ in range(int(input())):
	temp = input()
	tempset = []
	for i in temp:
		tempset.append(i)
	tempset = set(tempset)
	if len(tempset) == 1:
		print(-1)
	else:
		temp = sorted(temp)
		ans = ''
		for j in temp:
			ans += j
		print(ans)


def solve(cnt):
	if len(cnt) == 1:
		return -1
	s = ''
	for c in cnt:
		for i in range(cnt[c]):
			s += c
	return s
n = int(input())
for i in range(n):
	s = input()
	cnt = {}
	for c in s:
		if c not in cnt:
			cnt[c] = 1
		else:
			cnt[c] += 1
	print(solve(cnt))


n = int(input())
for i in range(n):
	s = input()
	p = True
	a = s[0]
	for c in range(len(s)):
		if s[c] != a:
			p = False
	if not p:
		l = []
		for c in s:
			l.append(c)
		l.sort()
		print(*l, sep='')
	else:
		print(-1)


def good(s):
	return not s == s[::-1]

def solve(s):
	if len(set(s)) == 1:
		return -1
	if good(s):
		return s
	return ''.join(sorted(s))
t = int(input())
for tc in range(t):
	s = input()
	print(solve(s))


for x in range(int(input())):
	s = input()
	if s.count(s[0]) == len(s):
		print(-1)
	else:
		print(''.join(sorted(s)))


def shuffle(letters):
	if len(list(set(list(letters)))) == 1:
		return -1
	letters = list(letters)
	for i in range(len(letters)):
		for x in range(len(letters)):
			if letters[i] != letters[x]:
				first = letters[i]
				second = letters[x]
				letters[x] = first
				letters[i] = second
				return ''.join(letters)
	return -1

def palindrome(letters):
	lets = letters
	while lets:
		if len(lets) == 1:
			return True
		if lets[0] == lets[-1]:
			lets = lets[1:-1]
		else:
			return False
	return True

def parse(letters):
	while palindrome(letters):
		letters = shuffle(letters)
		if letters == -1:
			return -1
	return letters
n = int(input())
for i in range(n):
	print(parse(input()))


for i in range(int(input())):
	a = input()
	if a == a[::-1]:
		if len(set(a)) == 1:
			print('-1')
		else:
			n = len(a)
			print(a[n // 2] + a[:n // 2] + a[n // 2 + 1:])
	else:
		print(a)


t = int(input())
for _ in range(t):
	s = input()
	if len(set(s)) < 2:
		print(-1)
	else:
		print(''.join(sorted(s)))


from collections import Counter
t = int(input())
for _ in range(t):
	s = input()
	n = len(s)
	a = Counter(s)
	for val in a:
		temp = val
	if s.index(temp) == n - 1:
		s = s[-1] + s[:-1]
	elif s.index(temp) == 0:
		s = s[1:] + s[0]
	else:
		s = s[:s.index(temp)] + s[s.index(temp) + 1:] + temp
	if s == s[::-1]:
		print(-1)
	else:
		print(s)


import math
import sys

def isPal(s):
	(lo, hi) = (0, len(s) - 1)
	while lo <= hi:
		if s[lo] != s[hi]:
			return False
		lo += 1
		hi -= 1
	return True
for _ in range(int(input())):
	s = list(input())
	st = list(set(s))
	if len(s) == 1 or len(st) == 1:
		print('-1')
	else:
		if not isPal(s):
			print(''.join(s))
			continue
		(id1, id2) = (s.index(st[0]), s.index(st[1]))
		(s[id1], s[id2]) = (s[id2], s[id1])
		print(''.join(s))


for k in range(int(input())):
	s = list(input())
	if len(set(s)) == 1:
		print(-1)
		continue
	f = 0
	for i in range(len(s)):
		if s[i] != s[len(s) - i - 1]:
			f = 1
			break
	if f:
		print(''.join(s))
		continue
	i = 0
	while s[i] == s[0]:
		i += 1
	(s[0], s[i]) = (s[i], s[0])
	print(''.join(s))


n = int(input())
for i in range(n):
	s = input()
	ss = ''.join(sorted(list(s)))
	if ss == ss[::-1]:
		print(-1)
	else:
		print(ss)


for _ in range(int(input())):
	s = input()
	c = []
	a = list(set(s))
	for i in range(len(a)):
		c.append(s.count(a[i]))
	count = 0
	for i in range(len(c)):
		if c[i] % 2 != 0:
			count += 1
	if len(c) == 1:
		print(-1)
	else:
		for i in range(len(a)):
			for j in range(c[i]):
				print(a[i], end='')
		print()


import random

def checkPal(s):
	sets = set(s)
	l = len(s)
	if len(sets) == 1:
		print(-1)
		return
	s = list(s)
	for i in range(int(l / 2)):
		if s[i] != s[l - i - 1]:
			print(''.join(s))
			return
	random.shuffle(s)
	checkPal(s)
t = int(input())
for i in range(t):
	s = input()
	checkPal(s)


import math
import os
import random
import re
import math
import os
import random
import re
import sys
TC = int(input())
for i in range(0, TC):
	list2 = list(input().strip())
	list1 = sorted(list2)
	n = len(list1)
	p1 = 0
	p2 = n - 1
	flag = 0
	if n > 1:
		while p1 < n and p2 > 0 and (p1 < p2) and (p1 < n + 1):
			if list1[p1] == list1[p2]:
				p1 = p1 + 1
				p2 = p2 - 1
				flag = 2
			else:
				flag = 1
				break
	else:
		flag = 2
	str1 = ''
	if flag == 1:
		print(str1.join(list1))
	elif flag == 2:
		print(-1)


for i in range(int(input())):
	s = input()
	if len(list(set(s))) == 1:
		print(-1)
	else:
		print(''.join(sorted(s)))


for _ in range(int(input())):
	s = input()
	l = ''.join(sorted(list(s)))
	if l == l[::-1]:
		print(-1)
	else:
		print(l)


for _ in range(int(input())):
	s = input()
	f = sorted(s)
	if f == f[::-1]:
		print(-1)
	else:
		print(''.join(f))


a = int(input())
c = [[] for i in range(a)]
e = []
g = 0
h = []
for i in range(a):
	b = input()
	e.append(b)
	for j in b:
		c[i].append(j)
for i in range(len(c)):
	for r in range(len(c[i])):
		h.append(c[i][0 - r - 1])
	f = c[i][0]
	for q in e[i]:
		if q == f:
			g += 1
	if g != len(e[i]):
		for j in range(len(c[i]) - 1):
			if c[i] != h:
				print(e[i])
				break
			elif c[i][j] != c[i][j + 1]:
				(c[i][j], c[i][j + 1]) = (c[i][j + 1], c[i][j])
				for i in c[i]:
					print(i, end='')
				print()
				break
	else:
		print(-1)
	h = []
	g = 0


for _ in range(int(input())):
	d = {}
	s = input()
	s1 = ''
	for i in s:
		d[i] = d.get(i, 0) + 1
	if len(d) == 1:
		print(-1)
	else:
		for i in d:
			s1 += i * d[i]
		print(s1)


n = int(input())
for i in range(n):
	s = input()
	x = 1
	new = ''
	a = set(s)
	b = sorted(s)
	for i in b:
		new += i
	for i in range(len(s)):
		if s[i] != s[len(s) - 1 - i]:
			x = 0
			break
	if len(a) == 1:
		print('-1')
	elif x == 1:
		print(new)
	else:
		print(s)


def good_string(s):
	if s[::-1] == s:
		s_new = ''.join(sorted(s))
		if s_new[::-1] == s_new:
			return -1
		else:
			return s_new
	else:
		return s
n = int(input())
string = []
for i in range(0, n):
	string.append(input())
for i in range(0, n):
	print(good_string(string[i]))


t = int(input())
for _ in range(t):
	string = input()
	string_copy = list(string)
	if string == string[::-1]:
		for i in range(1, len(string) + 1 // 2):
			if string_copy[i] != string_copy[i - 1]:
				(string_copy[i], string_copy[i - 1]) = (string_copy[i - 1], string_copy[i])
				print(''.join(string_copy))
				break
		else:
			print(-1)
	else:
		print(string)


import sys
import math

def main():
	n = int(sys.stdin.readline().strip())
	for _ in range(n):
		s = sys.stdin.readline().strip()
		if s == s[::-1]:
			k = ''.join(sorted(list(s)))
			if s == k:
				print(-1)
			else:
				print(k)
		else:
			print(s)
main()


for _ in range(int(input())):
	s = input()
	if s.count(s[0]) == len(s):
		print(-1)
	elif s == s[::-1]:
		print(s[1:] + s[0])
	else:
		print(s)


for i in range(int(input())):
	di = {}
	a = input()
	temp = set(a)
	if len(temp) != 1:
		a = list(a)
		mid = len(a) // 2
		if len(a) % 2 != 0 and a[mid] != a[mid - 1] and (a[mid] != a[mid + 1]):
			(a[mid], a[mid - 1]) = (a[mid - 1], a[mid])
		else:
			a.sort()
		print(''.join(a))
	elif len(temp) == 1:
		print(-1)


n = int(input())
for i in range(n):
	s = input()
	if s != s[::-1]:
		print(s)
		continue
	if len(s) == 1:
		print(-1)
		continue
	for j in range(1, len(s) // 2 + len(s) % 2):
		if s[j] != s[0]:
			print(s[j], s[1:j], s[0], s[j + 1:], sep='')
			break
	else:
		print(-1)


def palindrome(t, x, y):
	if x < y:
		if t[x] == t[y]:
			palindrome(t, x + 1, y - 1)
		else:
			return False
	return True
n = int(input())
for i in range(n):
	s = str(input())
	k = sorted(s)
	k = ''.join(k)
	if k == s and palindrome(k, 0, len(s) - 1):
		print(-1)
	else:
		print(k)


n = int(input())
A = []
for i in range(n):
	word = input()
	if len(set(word)) == 1:
		A.append(-1)
	elif word == word[::-1]:
		word = ''.join(sorted(word))
		A.append(word)
	else:
		A.append(word)
print(*A, sep='\n')


for _ in range(int(input())):
	x = input()
	(a, flag) = (x[0], True)
	for el in x:
		if el != a:
			flag = False
	if flag:
		print(-1)
	elif x == x[::-1]:
		print(x[1:], x[0], sep='')
	else:
		print(x)


a = []
for j in range(26):
	a.append(0)
t = int(input())
for i in range(t):
	s = input()
	for j in s:
		a[ord(j) - 97] += 1
	s1 = ''
	x = 0
	for j in range(26):
		if a[j] != 0:
			x += 1
		while a[j] != 0:
			s1 += chr(j + 97)
			a[j] -= 1
	if x > 1:
		print(s1)
	else:
		print(-1)


i = input
exec(int(i()) * "a=''.join(sorted(i()));print([a,-1][len(set(a))<2]);")


t = int(input())
respuesta = -1
for i in range(t):
	condicion = False
	cadena = input()
	for j in range(1, len(cadena)):
		if cadena[j] != cadena[0]:
			respuesta = cadena[:j] + cadena[j + 1:] + cadena[j]
			condicion = True
			break
	if condicion:
		print(respuesta)
	else:
		print(-1)


n = int(input())
ans = []
for i in range(n):
	s = input()
	t = ''.join(sorted(s))
	if t[0] == t[-1]:
		ans.append(-1)
	else:
		ans.append(t)
for i in range(n):
	print(ans[i])


def a(s):
	if s != s[::-1]:
		return s
	else:
		out = ''.join(sorted(s))
		if out[::-1] == out:
			return -1
		else:
			return out
for i in range(int(input())):
	print(a(input()))


t = int(input())
j = 0
q = ''
for i in range(t):
	s = input()
	if s != s[::-1]:
		print(s)
	else:
		s = list(s)
		if len(set(s)) == 1:
			print(-1)
		else:
			j = 0
			while s[j] == s[j + 1]:
				j += 1
			q = s[j]
			s[j] = s[j + 1]
			s[j + 1] = q
			for l in s:
				print(l, end='')
			print()


t = int(input())
for x in range(t):
	phrase = input()
	letterdict = {}
	letterlist = []
	for y in phrase:
		if y not in letterdict:
			letterdict[y] = 1
			letterlist += y
		else:
			letterdict[y] += 1
	if len(letterdict) < 2:
		print(-1)
	else:
		result = ''
		for y in range(len(letterlist)):
			for z in range(letterdict[letterlist[y]]):
				result += letterlist[y]
		print(result)


t = int(input())
for i in range(t):
	l = []
	s = input()
	for j in s:
		l.append(j)
	j = 1
	while j < len(l):
		if l[j - 1] != l[j]:
			l = sorted(l)
			r = ''.join(l)
			print(r)
			break
		else:
			j = j + 1
	if j == len(l):
		print(-1)


import sys
import math
get_string = lambda : sys.stdin.readline().strip()
get_int_list = lambda : list(map(int, sys.stdin.readline().strip().split()))
get_intList_from_str = lambda : list(map(int, list(sys.stdin.readline().strip())))
get_charList_from_str = lambda : list(sys.stdin.readline().strip())
get_char_list = lambda : sys.stdin.readline().strip().split()
get_int = lambda : int(sys.stdin.readline())
pt = lambda x: sys.stdout.write(str(x))

def palindrome(s):
	for i in range(len(s) // 2 + 1):
		if s[i] != s[~i]:
			return False
	return True
for _ in range(get_int()):
	s = get_string()
	l = len(set(s))
	if l == 1:
		print(-1)
	elif l == 2:
		if len(s) == 2:
			if palindrome(s):
				print(-1)
			else:
				print(s)
		elif palindrome(s):
			print(s[len(s) // 2] + s[:len(s) // 2] + s[len(s) // 2 + 1:])
		else:
			print(s)
	elif len(s) == l:
		print(s)
	elif palindrome(s):
		print(s[len(s) // 2] + s[:len(s) // 2] + s[len(s) // 2 + 1:])
	else:
		print(s)


n = int(input())
for i in range(n):
	s = input()
	le = len(s)
	if s.count(s[0]) == le:
		print(-1)
	else:
		l = list(s)
		l.sort()
		print(''.join(l))


from collections import Counter
import random

def isPossible(s):
	c = Counter(s)
	if len(c) == 1:
		return False
	return True

def isPalin(s):
	m = len(s) // 2
	for i in range(m, -1, -1):
		if s[i] != s[len(s) - i - 1]:
			return False
	return True
for _ in range(int(input())):
	s = input().strip()
	if not isPossible(s):
		print(-1)
	else:
		l = list(s)
		n = len(l)
		while isPalin(l):
			f = random.randint(0, n - 1)
			for t in range(n):
				if f != t and l[f] != l[t]:
					break
			(l[f], l[t]) = (l[t], l[f])
		print(''.join(l))


for i in range(int(input())):
	k = input()
	if len(set(k)) == 1:
		print('-1')
		continue
	else:
		r = ''.join(sorted(k))
		print(str(r))


t = int(input())
for _ in range(t):
	s = input()
	a = [-1] * 26
	l = 0
	r = len(s) - 1
	n = len(s)
	while l < r and s[l] == s[r]:
		r -= 1
		l += 1
	if l >= r:
		t = []
		for i in range(n):
			a[ord(s[i]) - 97] = i
		for i in range(26):
			if a[i] > -1:
				t.append(a[i])
		if len(t) > 1:
			s = list(s)
			(s[t[0]], s[t[1]]) = (s[t[1]], s[t[0]])
			s = ''.join(s)
			print(s)
		else:
			print(-1)
	else:
		print(s)


def is_full(s):
	return s == s[0] * len(s)

def refracture(s):
	for i in range(len(s)):
		if s[i] != s[0]:
			return s[i] + s[1:i] + s[0] + s[i + 1:]

def palindrome(s):
	k = True
	for i in range(len(s)):
		if s[i] != s[len(s) - i - 1]:
			k = False
	return k
t = int(input())
for i in range(t):
	s = input()
	if is_full(s):
		print(-1)
	elif palindrome(s):
		print(refracture(s))
	else:
		print(s)


n = int(input())
for _ in range(n):
	st = list(input())
	st.sort()
	if len(list(set(st))) == 1:
		print(-1)
	else:
		print(*st, sep='')


t = int(input())
s = []
for kjn in range(0, t):
	x = input()
	a = []
	for i in x:
		a.append(i)
	a.sort()
	b = a[:]
	a.reverse()
	if b == a:
		s.append(-1)
	else:
		d = ''
		for i in a:
			d += i
		s.append(d)
for i in s:
	print(i)


import sys
for _ in range(int(input())):
	s = input()
	d = list(s)
	d.sort()
	k = ''
	for i in range(len(d)):
		k += d[i]
	if s[::-1] == s and k != s:
		print(k)
	elif s[::-1] != s:
		print(s)
	else:
		print('-1')


t = int(input())
for i in range(t):
	s = input()
	f = True
	for i in range(0, len(s) // 2):
		if s[i] != s[-i - 1]:
			f = False
	if not f:
		print(s)
	else:
		i = 0
		while i < len(s) and s[i] == s[0]:
			i += 1
		if i == len(s):
			print(-1)
		else:
			print(s[i] + s[1:i] + s[0] + s[i + 1:])


t = int(input())
for i in range(0, t):
	a = input()
	k = len(a)
	r = ''
	f = 1
	for i in range(k - 1, -1, -1):
		r = r + a[i]
	if r == a:
		for i in range(1, k):
			if a[0] != a[i]:
				f = 0
				break
		if f == 0:
			k = list(a)
			k.sort()
			print(''.join(k))
		else:
			print('-1')
	else:
		print(a)


n = int(input())
l = []
for i in range(n):
	t = input()
	if t.count(t[0]) == len(t):
		print(-1)
	elif t == t[::-1]:
		for i in range(1, len(t)):
			if t[i] != t[0]:
				t = t[:i] + t[-1] + t[i + 1:len(t) - 1] + t[i]
				print(t)
				break
	else:
		print(t)


t = int(input())
while t:
	s = input()
	if s != s[::-1]:
		print(s)
	else:
		val = s[0]
		val1 = ''
		for i in range(1, len(s)):
			if s[i] != val:
				val1 = i
				break
		if val1 == '':
			print(-1)
		else:
			ans = s[0:val1] + s[val1 + 1:len(s)] + s[val1]
			print(ans)
	t -= 1


queries = [input() for i in range(int(input()))]
for q in queries:
	if len(q) == q.count(q[-1]):
		print(-1)
	else:
		print(''.join(sorted(q)))


import sys
t = int(input())
for i in range(t):
	x = input()
	x = sorted(x)
	x = ''.join(x)
	if x[0] == x[-1]:
		print(-1)
	else:
		print(x)
sys.exit()


p = int(input())
for q in range(p):
	s = input()
	if len(set(list(s))) == 1:
		print(-1)
	else:
		print(''.join(sorted(s)))


for i in range(int(input())):
	s = input()
	if s == s[0] * len(s):
		print(-1)
	else:
		i = ''
		for e in sorted(s):
			i += e
		print(i)


from operator import itemgetter
t = int(input())
for i in range(t):
	s = list(input())
	s.sort()
	s = ''.join(s)
	i = 0
	flag = 1
	n = len(s)
	for i in range(n // 2 + n % 2):
		if s[i] != s[n - i - 1]:
			flag = 0
	if flag == 1:
		print(-1)
	else:
		print(s)


numQueries = int(input())
for i in range(numQueries):
	word = input()
	length = len(word)
	if length == 1:
		print(-1)
		continue
	prevStart = ''
	prevEnd = ''
	end = length - 1
	good = False
	newWord = word
	middle = length // 2
	if length % 2 == 1:
		middle = length // 2 + 1
	for start in range(middle):
		if start == end - start:
			middleLetter = word[start]
			for index in range(start):
				if word[index] != middleLetter:
					newWord = word[0:index] + middleLetter + word[index + 1:start] + word[index] + word[start + 1:]
					good = True
			break
		if word[start] != word[end - start]:
			good = True
			break
		if start != 0 and prevStart != word[start]:
			newWord = word[0:start - 1] + word[start] + prevStart + word[start + 1:]
			good = True
			break
		if start != 0 and prevEnd != word[end - start]:
			newWord = word[0:end] + prevEnd + word[end] + word[end + 1:]
			good = True
			break
		prevStart = word[start]
		prevEnd = word[end]
	if good:
		print(newWord)
	else:
		print(-1)


for u in range(int(input())):
	s = input()
	l = list(s)
	l.sort()
	s = ''.join(l)
	if s == s[::-1]:
		print(-1)
	else:
		print(s)


n = int(input())
for i in range(n):
	s = input()
	ok = True
	for j in range(len(s) // 2):
		if s[j] != s[len(s) - j - 1]:
			ok = False
			break
	if not ok:
		print(s)
	else:
		ok = False
		for j in range(1, len(s)):
			if s[j] != s[j - 1]:
				ok = True
				print(s[:j - 1] + s[j] + s[j - 1] + s[j + 1:])
				break
		if not ok:
			print(-1)


t = int(input())
result = []
for i in range(t):
	row = input()
	first_letter = row[0]
	another = -1
	for (j, letter) in enumerate(row):
		if letter != first_letter:
			another = j
	a = len(row) // 2
	b = len(row) % 2
	if b == 0:
		left = row[:a]
		right = row[a:]
	else:
		left = row[:a]
		right = row[a + 1:]
	for (le, ri) in zip(reversed(left), right):
		if le != ri:
			polindrom = False
			break
	else:
		polindrom = True
	if not polindrom:
		r = row
	elif another == -1:
		r = '-1'
	else:
		r = row[another] + row[1:another] + row[0] + row[another + 1:]
	another = -1
	result.append(r)
for el in result:
	print(el)


import os
import heapq
import sys, threading
import math
import bisect
import operator
from collections import defaultdict
sys.setrecursionlimit(10 ** 5)
from io import BytesIO, IOBase

def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)

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

def inar():
	return [int(k) for k in input().split()]

def lcm(num1, num2):
	return num1 * num2 // gcd(num1, num2)

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 check(n, m, arr):
	(c1, c2) = (1, 1)
	for i in range(n):
		for j in range(1, m):
			if arr[i][j] > arr[i][j - 1]:
				continue
			else:
				c1 = 0
				break
	for i in range(m):
		for j in range(1, n):
			if arr[j][i] > arr[j - 1][i]:
				continue
			else:
				c2 = 0
				break
	if c1 and c2:
		return True
	else:
		return False

def main():
	for _ in range(int(input())):
		st = list(input())
		n = len(st)
		ok = 0
		st.sort()
		for i in range(n // 2):
			if st[i] != st[n - i - 1]:
				ok = 1
				break
		if ok:
			print(''.join(st))
		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()


t = int(input())
for x in range(t):
	s = input()
	s = list(s)
	if len(set(s)) > 1:
		s.sort()
		print(''.join(s))
	else:
		print(-1)


n = int(input())
for i in range(n):
	s = input()
	x = s[::-1]
	if x == s:
		x = ''.join(sorted(s))
		if x == s:
			print(-1)
			continue
		else:
			print(x)
			continue
	else:
		print(s)
		continue


N = int(input())

def is_palindrome(st):
	return st == st[::-1]

def find_non_palidrome(st):
	if len(set(st)) <= 1:
		return '-1'
	if not is_palindrome(st):
		return st
	for i in range(len(st)):
		if st[0] != st[i]:
			if not is_palindrome(st[i] + st[1:i] + st[0] + st[i + 1:]):
				return st[i] + st[1:i] + st[0] + st[i + 1:]
for i in range(N):
	print(find_non_palidrome(input()))


def solve(s):
	if s == s[-1::-1]:
		x = set(s)
		if len(x) == 1:
			return -1
		a = x.pop()
		b = x.pop()
		x = s.index(a)
		y = s.index(b)
		s = list(s)
		s[x] = b
		s[y] = a
		s = ''.join(s)
	return s

def main():
	for _ in range(int(input())):
		s = input()
		print(solve(s))
main()


for _ in ' ' * int(input()):
	a = input()
	po = 0
	if a != a[::-1]:
		print(a)
	else:
		for i in range(len(a)):
			a = a[1:] + a[0]
			if a != a[::-1]:
				print(a)
				po = 1
				break
		if po == 0:
			print(-1)


a = int(input())
while a > 0:
	s = input()
	p = sorted(s)
	p = ''.join(p)
	if p[0] == p[len(p) - 1]:
		print('-1')
	else:
		print(p)
	a = a - 1


import sys
import math
t = int(input())
for _ in range(t):
	astr = str(input())
	kaa = astr[:][::-1]
	if astr != kaa:
		print(astr)
	else:
		seta = set(astr)
		if len(seta) == 1:
			print('-1', end='')
		else:
			mstr = sorted(astr)
			for j in range(len(mstr)):
				print(mstr[j], end='')
		print()


def rearrange(s):
	N = len(s)
	if N == 1:
		return -1
	for i in range(N // 2):
		if s[i] == s[N - 1 - i]:
			if s[i] != s[i + 1]:
				stemp = list(s)
				(stemp[i], stemp[i + 1]) = (stemp[i + 1], stemp[i])
				return ''.join(stemp)
		else:
			return s
	return -1
for i in range(int(input())):
	print(rearrange(input()))


t = int(input())
for i in range(t):
	s = input()
	rev = s[::-1]
	if rev != s:
		print(s)
	elif rev == s:
		if len(set(s)) == 1:
			print(-1)
		else:
			l = list(s)
			for i in range(1, len(l) - 1):
				if l[i] != l[i - 1]:
					(l[i], l[i - 1]) = (l[i - 1], l[i])
					break
				elif l[i] != l[i + 1]:
					(l[i], l[i + 1]) = (l[i + 1], l[i])
					break
			st = ''.join(l)
			print(st)


import math
from math import gcd, floor, sqrt, log

def iin():
	return int(input())

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

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

def liststr():
	return list(map(str, input().strip().split()))

def ceill(x):
	return int(x) if x == int(x) else int(x) + 1

def ceilldiv(x, d):
	return x // d if x % d == 0 else x // d + 1

def LCM(a, b):
	return a * b // gcd(a, b)

def solve():
	s = [i for i in sin()]
	if s != s[::-1]:
		print(''.join(s))
		return
	m = sorted(s)
	if m == s:
		print(-1)
	else:
		print(''.join(m))
t = 1
t = int(input())
for hula in range(t):
	solve()


t = int(input())
s = [None] * t
for x in range(t):
	s[x] = str(input())
for x in range(t):
	b = sorted(s[x])
	if b[0] != b[len(s[x]) - 1]:
		print(''.join(b))
	else:
		print('-1')


t = int(input())
for _ in range(t):
	s = input()
	a = []
	flag = True
	for i in range(len(s)):
		a.append(s[i])
	a.sort()
	for i in range(len(s)):
		if a[i] != a[len(s) - 1 - i]:
			flag = False
	if flag:
		print(-1, end='')
	else:
		for i in range(len(s)):
			print(a[i], end='')
	print()


for _ in range(int(input())):
	s = input().strip()
	arr = list(s)
	if len(set(arr)) == 1:
		print(-1)
	else:
		print(''.join(sorted(arr)))


for _ in range(int(input())):
	s = input()
	b = True
	for (i, c) in enumerate(s[1:]):
		if c != s[0]:
			b = False
			break
	if b:
		print(-1)
	else:
		s = list(s)
		s[i + 1] = s[-1]
		s[-1] = c
		print(''.join(s))


t = int(input())
for t1 in range(t):
	s = input()
	l = [0 for i in range(26)]
	for i in s:
		l[ord(i) - 97] += 1
	z = 0
	for i in range(26):
		if l[i] == len(s):
			z = -1
			break
	if z == -1:
		print(-1)
	else:
		str1 = ''
		print(str1.join(sorted(s)))


TC = int(input())
for tc in range(TC):
	s = input()
	s2 = sorted(s)
	print(''.join(s2) if s2 != list(reversed(s2)) else -1)


t = int(input())
for i in range(t):
	str = input()
	arr = [i for i in str]
	arr1 = set(arr)
	if len(arr1) == 1:
		print('-1')
	else:
		arr.sort()
		str1 = ''
		for let in arr:
			str1 += let
		print(str1)


def mi():
	return map(int, input().split())
from collections import Counter as c
for _ in range(int(input())):
	li = list(input())
	s = c(li)
	if len(s) == 1:
		print(-1)
	else:
		print(''.join(sorted(li)))


t = int(input())
for _ in range(t):
	a = list(input())
	x = a[0]
	f = 0
	n = len(a)
	for i in range(int(n / 2)):
		if not a[i] == a[n - 1 - i]:
			f = -1
			break
	if f == 0:
		for i in range(n):
			if not a[i] == x:
				(a[i], a[0]) = (a[0], a[i])
				print(''.join(a))
				break
			else:
				f += 1
		if f == n:
			print(-1)
	else:
		print(''.join(a))


for i in range(int(input())):
	slovo = input()
	if len(set(slovo)) == 1:
		print(-1)
	elif slovo != slovo[-1::-1]:
		print(slovo)
	else:
		sl = list(slovo)
		for s in range(1, len(slovo)):
			if sl[0] != sl[s]:
				(sl[0], sl[s]) = (sl[s], sl[0])
				break
		print(''.join(sl))


t = int(input())
for i in range(t):
	fleg = 0
	s = input()
	r = s[::-1]
	if r == s:
		x = s[0]
		for j in range(len(s)):
			if x != s[j]:
				fleg = 1
				break
		if fleg != 1:
			s = '-1'
		else:
			temp = s[0]
			s += temp
			s = s.replace(s[0], '', 1)
	print(s)


t = int(input())
for i in range(t):
	s = sorted(input())
	if s[0] == s[-1]:
		print(-1)
		continue
	print(''.join(s))


t = int(input())
for y in range(0, t, 1):
	st = input()
	same = True
	for x in range(0, len(st) - 1):
		if st[x] != st[x + 1]:
			same = False
			break
	if same:
		print('-1')
	else:
		s = sorted(st)
		for i in range(0, len(st)):
			print(s[i], end='')
		print()


R = lambda : map(int, input().split())
for _ in range(int(input())):
	s = input()
	rev_s = s[::-1]
	str_sort = ''.join(sorted(s))
	if s == rev_s:
		if str_sort == str_sort[::-1]:
			print(-1)
		else:
			print(str_sort)
	else:
		print(s)


import sys
input = sys.stdin.readline
ins = lambda : input().rstrip()
ini = lambda : int(input().rstrip())
inm = lambda : map(int, input().rstrip().split())
inl = lambda : list(map(int, input().split()))
out = lambda x, s='\n': print(s.join(map(str, x)))
t = ini()
for _ in range(t):
	s = ins()
	if len(set(s)) == 1:
		print(-1)
	else:
		out(sorted(s), '')


t = int(input())
for _ in range(t):
	s = input()
	s = ''.join(sorted(s))
	t = ''.join(reversed(s))
	if s == t:
		print(-1)
	else:
		print(s)


t = int(input())
for i in range(t):
	s = list(input())
	s.sort()
	if s[0] == s[-1]:
		print(-1)
	else:
		s1 = ''.join(s)
		print(s1)


a = int(input())
for i in range(a):
	b = list(input())
	b.sort()
	if b == b[::-1]:
		print(-1)
	else:
		print(''.join(b))


t = int(input())
for i in range(t):
	s = input()
	x = ''.join(sorted(s))
	if len(set(s)) == 1:
		print('-1')
	else:
		print(x)


t = int(input())
for i in range(t):
	s = list(input())
	if len(set(s)) == 1:
		print(-1)
	else:
		s.sort()
		a = ''
		for i in s:
			a += i
		print(a)


for _ in range(int(input())):
	s = input()
	if len(set(s)) != 1:
		if s != s[::-1]:
			print(s)
		else:
			print(s[-1] + s[:-1])
	else:
		print(-1)


from sys import stdin, stdout
import cProfile, math
from collections import Counter
from bisect import bisect_left, bisect, bisect_right
import itertools
from copy import deepcopy
from fractions import Fraction
import sys, threading
sys.setrecursionlimit(10 ** 6)
threading.stack_size(2 ** 27)
printHeap = str()
memory_constrained = False
P = 10 ** 9 + 7
import sys
sys.setrecursionlimit(10000000)

class Operation:

	def __init__(self, name, function, function_on_equal, neutral_value=0):
		self.name = name
		self.f = function
		self.f_on_equal = function_on_equal

def add_multiple(x, count):
	return x * count

def min_multiple(x, count):
	return x

def max_multiple(x, count):
	return x
sum_operation = Operation('sum', sum, add_multiple, 0)
min_operation = Operation('min', min, min_multiple, 1000000000.0)
max_operation = Operation('max', max, max_multiple, -1000000000.0)

class SegmentTree:

	def __init__(self, array, operations=[sum_operation, min_operation, max_operation]):
		self.array = array
		if type(operations) != list:
			raise TypeError('operations must be a list')
		self.operations = {}
		for op in operations:
			self.operations[op.name] = op
		self.root = SegmentTreeNode(0, len(array) - 1, self)

	def query(self, start, end, operation_name):
		if self.operations.get(operation_name) == None:
			raise Exception('This operation is not available')
		return self.root._query(start, end, self.operations[operation_name])

	def summary(self):
		return self.root.values

	def update(self, position, value):
		self.root._update(position, value)

	def update_range(self, start, end, value):
		self.root._update_range(start, end, value)

	def __repr__(self):
		return self.root.__repr__()

class SegmentTreeNode:

	def __init__(self, start, end, segment_tree):
		self.range = (start, end)
		self.parent_tree = segment_tree
		self.range_value = None
		self.values = {}
		self.left = None
		self.right = None
		if start == end:
			self._sync()
			return
		self.left = SegmentTreeNode(start, start + (end - start) // 2, segment_tree)
		self.right = SegmentTreeNode(start + (end - start) // 2 + 1, end, segment_tree)
		self._sync()

	def _query(self, start, end, operation):
		if end < self.range[0] or start > self.range[1]:
			return None
		if start <= self.range[0] and self.range[1] <= end:
			return self.values[operation.name]
		self._push()
		left_res = self.left._query(start, end, operation) if self.left else None
		right_res = self.right._query(start, end, operation) if self.right else None
		if left_res is None:
			return right_res
		if right_res is None:
			return left_res
		return operation.f([left_res, right_res])

	def _update(self, position, value):
		if position < self.range[0] or position > self.range[1]:
			return
		if position == self.range[0] and self.range[1] == position:
			self.parent_tree.array[position] = value
			self._sync()
			return
		self._push()
		self.left._update(position, value)
		self.right._update(position, value)
		self._sync()

	def _update_range(self, start, end, value):
		if end < self.range[0] or start > self.range[1]:
			return
		if start <= self.range[0] and self.range[1] <= end:
			self.range_value = value
			self._sync()
			return
		self._push()
		self.left._update_range(start, end, value)
		self.right._update_range(start, end, value)
		self._sync()

	def _sync(self):
		if self.range[0] == self.range[1]:
			for op in self.parent_tree.operations.values():
				current_value = self.parent_tree.array[self.range[0]]
				if self.range_value is not None:
					current_value = self.range_value
				self.values[op.name] = op.f([current_value])
		else:
			for op in self.parent_tree.operations.values():
				result = op.f([self.left.values[op.name], self.right.values[op.name]])
				if self.range_value is not None:
					bound_length = self.range[1] - self.range[0] + 1
					result = op.f_on_equal(self.range_value, bound_length)
				self.values[op.name] = result

	def _push(self):
		if self.range_value is None:
			return
		if self.left:
			self.left.range_value = self.range_value
			self.right.range_value = self.range_value
			self.left._sync()
			self.right._sync()
			self.range_value = None

	def __repr__(self):
		ans = '({}, {}): {}\n'.format(self.range[0], self.range[1], self.values)
		if self.left:
			ans += self.left.__repr__()
		if self.right:
			ans += self.right.__repr__()
		return ans

def display(string_to_print):
	stdout.write(str(string_to_print) + '\n')

def primeFactors(n):
	factors = dict()
	for i in range(2, math.ceil(math.sqrt(n)) + 1):
		while n % i == 0:
			if i in factors:
				factors[i] += 1
			else:
				factors[i] = 1
			n = n // i
	if n > 2:
		factors[n] = 1
	return factors

def isprime(n):
	if n < 4:
		return True
	if n % 2 == 0:
		return False
	if n % 3 == 0:
		return False
	i = 5
	w = 2
	while i * i <= n:
		if n % i == 0:
			return False
		i += w
		w = 6 - w
	return True

def test_print(*args):
	if testingMode:
		print(args)

def display_list(list1, sep=' '):
	stdout.write(sep.join(map(str, list1)) + '\n')

def get_int():
	return int(stdin.readline().strip())

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

def get_list():
	return list(map(int, stdin.readline().split()))
memory = dict()

def clear_cache():
	global memory
	memory = dict()

def cached_fn(fn, *args):
	global memory
	if args in memory:
		return memory[args]
	else:
		result = fn(*args)
		memory[args] = result
		return result
TestCases = True
testingMode = False
optimiseForReccursion = False

def main():
	n = list(input())
	n.sort()
	count = Counter(n)
	if len(list(count.keys())) == 1:
		print(-1)
		return
	else:
		print(''.join(n))
if TestCases:
	for _ in range(get_int()):
		cProfile.run('main()') if testingMode else main()
else:
	(cProfile.run('main()') if testingMode else main()) if not optimiseForReccursion else threading.Thread(target=main).start()


t = int(input())
ans = list()
for _ in range(0, t):
	str = input()
	sz = len(str)
	p = str[0] * sz
	if str == p:
		ans.append(-1)
		continue
	rev = str[::-1]
	if rev == str:
		str = ''.join(sorted(str))
		ans.append(str)
	else:
		ans.append(str)
for i in ans:
	print(i)


def arrange(s):
	char_map = {}
	for i in range(0, len(s)):
		curr_char = s[i]
		char_map[curr_char] = char_map.get(curr_char, 0) + 1
	if len(char_map) == 1:
		return '-1'
	else:
		tmp = ''
		for (k, v) in char_map.items():
			tmp += k * v
		return tmp
n = int(input())
for i in range(0, n):
	s = input()
	print(arrange(s))


x = int(input())
a = []
for f in range(x):
	m = input()
	c = 1
	for n in range(1, len(m)):
		if m[n] == m[0]:
			c = c + 1
	if c == len(m):
		print(-1)
	elif m != m[::-1]:
		print(m)
	else:
		n = len(m)
		while 1:
			lst = list(m)
			(lst[0], lst[int(n / 2)]) = (lst[int(n / 2)], lst[0])
			t = ''.join(lst)
			if t != t[::-1]:
				print(t)
				break
			n = n / 2


def give(b):
	if b.count(b[0]) == len(b):
		return -1
	if b != b[::-1]:
		return b
	else:
		a = b[0]
		b = b[1:len(b)] + a
		return give(b)
n = int(input())
a = []
c = []
for i in range(0, n):
	b = input()
	a.append(b)
	c.append(give(b))
for i in c:
	print(i)


n = int(input())
a1 = []
for k in range(n):
	a1.append(input())
for a in a1:
	if len(a) == 1:
		print(-1)
	elif a != a[::-1]:
		print(a)
	else:
		a = list(a)
		mid = (len(a) + 1) // 2
		count = 0
		for i in range(len(a)):
			if a[i] != a[mid]:
				temp = a[i]
				a[i] = a[mid]
				a[mid] = temp
				print(''.join(a))
				break
			else:
				count += 1
		if count == len(a):
			print(-1)


t = int(input())
while t:
	t -= 1
	s = input()
	if len(set(list(s))) == 1:
		print('-1')
	else:
		print(''.join(sorted(list(s))))


def is_palindrome(l, mid, s):
	(i, j) = (0, l - 1)
	while i <= mid <= j:
		if s[i] != s[j]:
			return False
		i += 1
		j -= 1
	return True

def solve(s):
	l = len(s)
	mid = l // 2
	c = s.count(s[0])
	if c == l:
		print(-1)
		return
	else:
		arr = list(s)
		found = False
		for i in range(mid, -1, -1):
			temp = arr[i]
			arr[i] = arr[mid]
			arr[mid] = temp
			if not is_palindrome(l, mid, arr):
				print(''.join(arr))
				found = True
				break
			arr = list(s)
		if not found:
			print(-1)

def main():
	q = int(input())
	for i in range(q):
		s = input()
		solve(s)
main()


t = int(input())
for ti in range(t):
	s = input()
	if s == s[::-1]:
		if len(set(s)) == 1:
			print(-1)
		else:
			print(''.join(sorted(s)))
	else:
		print(s)


n = int(input())
for i in range(n):
	s = input()
	if s == s[::-1]:
		k = sorted(s)
		if len(s) == s.count(s[0]):
			print(-1)
		elif k == k[::-1]:
			print(-1)
		else:
			print(''.join(k))
	else:
		print(s[::-1])


for _ in range(int(input())):
	a = list(input())
	if a != a[::-1]:
		print(''.join(a))
	elif len(a) == 1 or len(set(a)) == 1:
		print(-1)
	else:
		a.sort()
		print(''.join(a))


for cas in range(int(input())):
	s = input()
	s = list(s)
	ln = len(s)
	cnt = 0
	for i in range(ln - 1):
		if s[i] != s[i + 1]:
			cnt += 1
	if cnt == 0:
		print(-1)
		continue
	ln = ln // 2
	palindrm = True
	for i in range(ln):
		if s[i] != s[-(i + 1)]:
			palindrm = False
	if palindrm:
		s.sort()
		print(''.join(s))
	else:
		print(''.join(s))


def goodorbad(str1):
	return ''.join(sorted(list(str1))) if len(set(str1)) != 1 else -1
n = int(input())
for _ in range(n):
	print(goodorbad(input()))


n = int(input())
L = []
for i in range(26):
	L.append(0)
for j in range(n):
	s = input()
	for k in range(len(s)):
		L[ord(s[k]) - ord('a')] = L[ord(s[k]) - ord('a')] + 1
	flag = 0
	final = ''
	for m in range(26):
		for t in range(L[m]):
			final = final + chr(ord('a') + m)
		if L[m] != 0:
			flag = flag + 1
	if flag == 1:
		print('-1')
	else:
		print(final)
	for g in range(26):
		L[g] = 0


n = int(input())
strings = []
for i in range(n):
	strings.append(input())

def is_palindrom(s):
	return s == s[::-1]
for i in range(n):
	sorted_str = ''.join(sorted(strings[i]))
	if is_palindrom(sorted_str):
		print(-1)
		continue
	else:
		print(sorted_str)
		continue


for _ in range(int(input())):
	s = list(input())
	if len(set(s)) == 1:
		print(-1)
	else:
		for i in set(s):
			print(i * s.count(i), end='')
		print('')


import math
import sys
t = int(input())
line_t = []
for i in range(t):
	a = input()
	line_t.append(a)

def isaa(a):
	str1 = a
	str2 = str1[::-1]
	if str1 == str2:
		str1 = list(str1)
		str3 = sorted(str1)
		str4 = ''.join(str3)
		str5 = ''.join(str1)
		if str4 == str4[::-1]:
			return -1
		else:
			return str4
	else:
		return str1
for i in range(t):
	print(isaa(line_t[i]))


t = int(input())
A = [input() for i in range(t)]
for a in A:
	ANS = sorted(list(a))
	if ANS[0] == ANS[-1]:
		print(-1)
		continue
	else:
		for a in ANS:
			print(a, end='')
		print()


for i in range(int(input())):
	a = input()
	b = ''.join(set(a))
	if len(b) == 1:
		print(-1)
	else:
		i = 1
		while 1:
			c = a[i:] + a[:i]
			if c != c[::-1]:
				print(c)
				break
			i += 1


t = int(input())
for i in range(t):
	a = input()
	if len(a) == 1:
		print(-1)
	else:
		l = []
		l.append(a[0])
		v = 0
		for j in range(1, len(a)):
			if a[j] != a[j - 1] and v == 0:
				v = 1
			l.append(a[j])
		if v == 0:
			print(-1)
		else:
			l.sort()
			for j in range(len(a)):
				print(l[j], end='')
			print()


t = int(input())
s = []
for i in range(t):
	inp = input()
	s.append(inp)
for i in range(t):
	length = len(s[i])
	if length == 1:
		print(-1)
	else:
		string = s[i]
		string_reversed = string[::-1]
		if string == string_reversed:
			string_sorted = ''.join(sorted(string))
			if string == string_sorted:
				print(-1)
			else:
				print(string_sorted)
		else:
			print(string)


def main():
	t = int(input())
	for i in range(t):
		s = input()
		solver(s)

def solver(s):
	if s == s[0] * len(s):
		print(-1)
		return
	else:
		for i in range(len(s) // 2 + 1):
			if s[i] != s[len(s) - i - 1]:
				print(s)
				return
		for i in range(1, len(s)):
			if s[i] != s[0]:
				result = s[i] + s[1:i] + s[0] + s[i + 1:]
				print(result)
				return
		print(-1)
		return
main()


for i in range(int(input())):
	s = list(map(str, input()))
	p = ''
	for j in range(0, len(s) // 2):
		if s[j] != s[len(s) - j - 1]:
			p = s[1]
			break
	if p == '':
		for k in range(0, len(s) // 2):
			if s[k] != s[k + 1]:
				p = s[k + 1]
				s[k + 1] = s[k]
				s[k] = p
				break
	if p != '':
		print(*s, sep='')
	else:
		print(-1)


n = int(input())
for i in range(n):
	a = input()
	b = ''.join(sorted(a))
	k = len(a)
	print('-1' if b[0] == b[k - 1] else b)


def palin(s):
	for i in range(0, len(s)):
		if s[i] != s[len(s) - i - 1]:
			return False
	return True
t = int(input())
answer = []
for i in range(0, t):
	s = input()
	if s.count(s[0]) == len(s):
		answer.append(-1)
	elif palin(s):
		answer.append(''.join(s[1:]) + s[0])
	else:
		answer.append(s)
for x in answer:
	print(x)


q = int(input())
for i in range(q):
	s = input()
	if len(set(s)) == 1:
		print(-1)
	else:
		ls = list(s)
		ls.sort()
		print(''.join((ls[i] for i in range(len(ls)))))


t = int(input())
for j in range(t):
	s = input()
	count = 0
	if len(s) % 2 == 0:
		for i in range(int(len(s) / 2)):
			if s[int(len(s) / 2) + i] == s[int(len(s) / 2) - 1 - i]:
				count += 1
			else:
				break
		if count == int(len(s) / 2):
			count1 = 0
			for i in range(count):
				if s[i] == s[i + 1]:
					count1 += 1
				else:
					break
			if count1 == count:
				print(-1)
			else:
				s1 = list(s)
				for i in range(count):
					if s1[i] != s1[i + 1]:
						temp = s1[i]
						s1[i] = s1[i + 1]
						s1[i + 1] = temp
						break
				s = ''
				for i in range(len(s1)):
					s += s1[i]
				print(s)
		else:
			print(s)
	else:
		for i in range(int(len(s) / 2)):
			if s[int(len(s) / 2) + i + 1] == s[int(len(s) / 2) - 1 - i]:
				count += 1
			else:
				break
		if count == int(len(s) / 2):
			count1 = 0
			for i in range(count):
				if s[i] == s[i + 1]:
					count1 += 1
				else:
					break
			if count1 == count:
				print(-1)
			else:
				s1 = list(s)
				for i in range(count):
					if s1[i] != s1[i + 1]:
						temp = s1[i]
						s1[i] = s1[i + 1]
						s1[i + 1] = temp
						break
				s = ''
				for i in range(len(s1)):
					s += s1[i]
				print(s)
		else:
			print(s)


n = int(input())
for i in range(n):
	a = list(input())
	b = a.count(a[0])
	a.sort()
	if b == len(a):
		print('-1')
	else:
		print(''.join(a))


from math import ceil

def pal(s):
	for i in range(ceil(len(s) / 2)):
		if s[i] != s[-i - 1]:
			return False
	return True
t = int(input())
for i in range(t):
	s = input()
	if s == s[0] * len(s):
		print(-1)
	elif pal(s):
		for i in range(1, len(s)):
			if s[0] != s[i]:
				print(s[i], s[1:i], s[0], s[i + 1:], sep='')
				break
	else:
		print(s)


import math
t = int(input())
for _ in range(t):
	s = input()
	n = len(s)
	for i in range(math.ceil(n / 2)):
		if s[i] != s[n - 1 - i]:
			print(s)
			break
	else:
		if len(set(s)) == 1:
			print(-1)
		else:
			print(*sorted(list(s)), sep='')


for t in range(int(input())):
	s = input()
	a = [0 for j in range(26)]
	for j in range(26):
		a[j] = s.count(chr(97 + j))
	if a.count(0) == 25:
		print(-1)
	else:
		p = ''
		for j in range(26):
			p += chr(j + 97) * a[j]
		print(p)


n = int(input())
for i in range(n):
	s = list(input())
	s.sort()
	if s[0] == s[-1]:
		print(-1)
	else:
		print(''.join(s))


def getElements(s):
	dicr = {}
	for i in s:
		if i in dicr:
			dicr[i] = dicr[i] + 1
		else:
			dicr[i] = 1
	return dicr

def isPalindrome(s):
	return s == ''.join(reversed(s))

def isGood(s):
	if not isPalindrome(s):
		return s
	else:
		dict = getElements(s)
		if len(dict) == 1:
			return '-1'
		else:
			res = ''
			for i in dict:
				res = res + i * dict[i]
			return res
t = int(input())
for i in range(0, t):
	s = input()
	print(isGood(s))


for _ in range(int(input())):
	s = input()
	if s != s[::-1]:
		print(s)
	elif len(set(s)) == 1:
		print(-1)
	else:
		l = sorted(list(s))
		print(''.join(map(str, l)))


n = int(input())
for i in range(n):
	s = input()
	s1 = sorted(s)
	s2 = s1[::-1]
	if s1 == s2:
		print(-1)
		continue
	if s == s1:
		print(s)
		continue
	print(''.join(s1))


n = int(input())
L = []
for i in range(n):
	x = input()
	if len(set(x)) == 1:
		L.append(-1)
	elif x == x[::-1]:
		x = ''.join(sorted(x))
		L.append(x)
	else:
		L.append(x)
for i in L:
	print(i)


n = int(input())
for i in range(n):
	s = list(input())
	z = True
	for j in range(len(s) // 2):
		if s[j] != s[-j - 1]:
			z = False
			break
	output = list()
	if not z:
		output = s
	else:
		for j in range(len(s) // 2):
			if s[j] != s[len(s) // 2]:
				a = s[j]
				s[j] = s[len(s) // 2]
				s[len(s) // 2] = a
				output = s
				break
	if len(output) == 0:
		print(-1)
	else:
		for k in range(len(s)):
			print(output[k], end='')
		print()


from collections import Counter

def read_input():
	n_queries = int(input())
	strings = []
	for _ in range(n_queries):
		strings.append(input())
	return strings

def print_results(results):
	for result in results:
		print(result)

def letters_rearranging(string):
	s_counts = dict(Counter(string))
	if len(s_counts) == 1:
		return -1
	else:
		result = ''
		for letter in s_counts:
			result += letter * s_counts[letter]
		return result
strings = read_input()
results = []
for string in strings:
	results.append(letters_rearranging(string))
print_results(results)


def goodstring(s):
	if list(s) != list(reversed(s)):
		return s
	else:
		s = list(s)
		for x in range(1, len(s)):
			if s[x] != s[-1]:
				s[0] = s[x]
				s[x] = s[-1]
				return ''.join(s)
		return -1
t = int(input())
ans = []
for x in range(t):
	s = input()
	q = goodstring(s)
	ans.append(q)
for y in ans:
	print(y)


n = int(input())
while n:
	l = list(input())
	if len(set(l)) == 1:
		print(-1)
	elif l == l[::-1]:
		print(''.join(sorted(l)))
	else:
		print(''.join(l))
	n -= 1


import math
import collections
import bisect
import heapq
import time
import itertools
import sys

def check(val):
	(l, r) = (0, len(val) - 1)
	while l < r:
		if val[l] != val[r]:
			return True
		l += 1
		r -= 1
	return False
T = int(input())
for ti in range(T):
	s = list(input())
	s.sort()
	if check(s):
		print(''.join(s))
	else:
		print(-1)


tests = int(input())
while tests != 0:
	s = input()
	allSameLetters = True
	for ch in s:
		if ch != s[0]:
			allSameLetters = False
	if allSameLetters:
		print(-1)
	else:
		print(''.join(sorted(s)))
	tests -= 1


def is_palindrom(line):
	for i in range(len(line) // 2):
		if line[i] != line[-i - 1]:
			return False
	return True
n = int(input())
for _ in range(n):
	line = input()
	if not is_palindrom(line):
		answer = line
	elif line.count(line[0]) != len(line):
		i = 1
		while line[i] == line[0]:
			i += 1
		letters = list(line)
		letter = letters[0]
		letters[0] = letters[i]
		letters[i] = letter
		answer = ''.join(letters)
	else:
		answer = -1
	print(answer)


def goodstr(s):
	n = len(s)
	if s.count(s[0]) == n:
		return -1
	elif s != s[::-1]:
		return s
	else:
		m = n // 2
		j = m + 1
		while s[m] == s[j]:
			j += 1
		return s[:m] + s[j] + s[m + 1:j] + s[m] + s[j + 1:]
for i in range(int(input())):
	print(goodstr(input()))


from sys import stdin, stdout
n = int(stdin.readline())
for i in range(n):
	a = []
	b = []
	z = input()
	for j in z:
		a.append(j)
		b.append(j)
	a.sort()
	if a == b:
		a.reverse()
		if a == b:
			stdout.write('-1')
			stdout.write('\n')
		else:
			for j in a:
				stdout.write(j)
			stdout.write('\n')
	else:
		for j in a:
			stdout.write(j)
		stdout.write('\n')


for i in range(int(input())):
	a = input()
	if len(set(a)) == 1:
		print(-1)
	else:
		p = 0
		for j in range(0, len(a) // 2):
			if a[j] == a[len(a) - j - 1]:
				p += 1
		if len(a) % 2 == 0:
			if p == len(a) // 2:
				print(a[1:] + a[0])
			else:
				print(a)
		elif len(a) % 2 != 0:
			if p == len(a) // 2:
				print(a[len(a) // 2] + a[0:len(a) // 2] + a[len(a) // 2 + 1:])
			else:
				print(a)


n = int(input())
t = 0
for i in range(n):
	k = input()
	k = list(k)
	n = set(k)
	n = list(n)
	if len(n) > 2:
		k.sort()
		for i in k:
			print(i, end='')
		print()
	if len(n) == 1:
		print('-1')
	if len(n) == 2:
		k.sort()
		for i in k:
			print(i, end='')
		print()


n = int(input())
for i in range(n):
	s = str(input())
	r = True
	for j in range(len(s) // 2):
		if s[j] != s[len(s) - j - 1]:
			r = False
	if r:
		t = True
		for j in range(len(s)):
			if s[0] != s[j]:
				print(s[j] + s[1:j] + s[0] + s[j + 1:])
				t = False
				break
		if t:
			print(-1)
	else:
		print(s)


t = int(input())
for i in range(t):
	s = [c for c in input().strip()]
	if len(set(s)) == 1:
		print(-1)
	else:
		sr = s.copy()
		sr.reverse()
		if s != sr:
			print(*s, sep='')
		else:
			print(*s[1:] + s[0:1], sep='')


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

def rearrangable(s):
	if len(set(s)) == 1:
		return (False, s)
	for i in range(len(s)):
		for j in range(i + 1, len(s)):
			temp = s[:i] + s[j] + s[i + 1:j] + s[i] + s[j + 1:]
			if not isPalindrome(temp):
				return (True, temp)
	return (False, s)
t = int(input())
for i in range(t):
	s = input()
	if isPalindrome(s):
		r = rearrangable(s)
		if r[0]:
			print(r[1])
		else:
			print(-1)
	else:
		print(s)


for _ in range(int(input())):
	s = sorted(input())
	if len(set(s)) == 1:
		print(-1)
	else:
		for i in s:
			print(i, end='')
		print()


a = int(input())
r = 0
c = list()
while r < a:
	b = [char for char in input()]
	if b.count(b[0]) == len(b):
		c.append('-1')
	else:
		b.sort()
		c.append(''.join((char for char in b)))
	r = r + 1
r = 0
while r < a:
	print(c[r])
	r = r + 1


def palindrome(a):
	l = len(a)
	p = 0
	for i in range(l // 2):
		if a[i] != a[l - 1 - i]:
			p = p + 1
			break
	if p == 0:
		return True
	return False
q = int(input())
for _ in range(q):
	a = input()
	if palindrome(a):
		b = sorted(a)
		b = ''.join(b)
		if b == a:
			print(-1)
		else:
			print(b)
	else:
		print(a)


from sys import stdin

def iinput():
	return int(stdin.readline())

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

def linput():
	return list(map(int, stdin.readline().split()))
t = iinput()
while t:
	t -= 1
	s = list(input())
	if s == s[::-1]:
		for i in range(1, len(s)):
			if s[i] != s[0]:
				(s[i], s[0]) = (s[0], s[i])
				print(''.join(s))
				break
		else:
			print('-1')
	else:
		print(''.join(s))


import sys
import collections
input = sys.stdin.readline

def printnl(val):
	sys.stdout.write(str(val) + '\n')
T = int(input())
while T:
	s = list(input())
	n = len(s) - 1
	s = s[:n]
	s.sort()
	flag = True
	for (cs, cr) in zip(s, reversed(s)):
		if cs != cr:
			flag = False
			print(''.join(s))
			break
	if flag:
		print(-1)
	T -= 1


for i in range(int(input())):
	s = input()
	size = len(s)
	flag = True
	for j in range(size - 1):
		if s[j] != s[j + 1]:
			flag = False
			break
	if flag:
		print(-1)
	else:
		l = list(s)
		l.sort()
		print(''.join(l))


n = int(input())
for i in range(n):
	str = input()
	if ''.join(reversed(str)) != str:
		print(str)
	elif len(str) == 1:
		print(-1)
	else:
		for x in range(len(str) - 1):
			if str[x] != str[x + 1]:
				a = x
				b = x + 1
				temp = str[b]
				trailer = str[b + 1:] if b + 1 < len(str) else ''
				str = str[0:b] + str[a] + trailer
				str = str[0:a] + temp + str[a + 1:]
				print(str)
				break
			elif x == len(str) - 2:
				print(-1)
				break


from math import floor
n = int(input())
q = []
for i in range(0, n):
	q.append(input())
for i in range(0, n):
	if q[i].count(q[i][0]) == len(q[i]):
		print(-1)
	else:
		print(''.join(sorted(q[i])))


n = int(input())
for _ in range(n):
	a = sorted(input())
	if a == a[::-1]:
		print(-1)
	else:
		print(''.join(a))


for _ in range(int(input())):
	s = input()
	palindrome = 1
	a = []
	for i in range(len(s) // 2 + 1):
		if s[i] != s[len(s) - 1 - i]:
			palindrome = 0
			break
	if palindrome:
		i = 0
		while i < len(s) - 1:
			if s[i] != s[i + 1]:
				s = s[:i] + s[i + 1] + s[i] + s[i + 2:]
				print(s)
				break
			i += 1
		else:
			print(-1)
	else:
		print(s)


import re
for i in range(int(input())):
	s = input()
	if len(set(s)) == 1:
		print(-1)
	else:
		print(''.join(sorted(s)))


def rearrange(input_string):
	length = len(input_string)
	mid_char = input_string[length // 2]
	output_string = list(input_string)
	for (index, char) in enumerate(input_string):
		if input_string[index] != mid_char:
			output_string[index] = mid_char
			output_string[length // 2] = input_string[index]
			break
		else:
			continue
	return ''.join(output_string)

def main():
	test_case = int(input())
	for i in range(test_case):
		input_string = input()
		reverse = input_string[::-1]
		input_set = set(input_string)
		if input_string != reverse:
			print(input_string)
		elif len(input_set) < 2:
			print('-1')
		else:
			print(rearrange(input_string))
main()


t = int(input())
for i in range(t):
	s = input()
	k = len(s)
	count = 0
	if len(s) == 1:
		print(-1)
	elif len(set(s)) == 1:
		print(-1)
	else:
		for i in range(len(s) // 2):
			if s[i] == s[-i - 1]:
				count += 1
				pass
			else:
				print(s)
				break
		if count == len(s) // 2:
			print(s[0:k // 2] + s[k // 2 + 1:] + s[k // 2])


import random
t = int(input())
for _ in range(t):
	s = list(input())
	if len(s) == s.count(s[0]):
		print(-1)
	else:
		while list(reversed(s)) == s:
			random.shuffle(s)
		print(''.join(s))


def swap(c, i, j):
	c = list(c)
	(c[i], c[j]) = (c[j], c[i])
	return ''.join(c)
n = int(input())
for j in range(n):
	x = input()
	w = x[::-1]
	if x == w:
		if len(set(x)) == 1:
			print(-1)
		else:
			for rahat in range(len(x) - 1):
				if x[rahat] != x[rahat + 1]:
					x = swap(x, rahat, rahat + 1)
					break
			print(x)
	else:
		print(x)


i = int(input())
while i:
	n = input()
	print(-1) if len(set(n)) == 1 else print(''.join(sorted(n)))
	i -= 1


for j in range(int(input())):
	s = input()
	s2 = set(s)
	s3 = s[::-1]
	if len(s2) == 1:
		print('-1')
	elif s != s[::-1]:
		print(s)
	else:
		x = s[0]
		s4 = list(s)
		s4.pop()
		print(x + ''.join(s4))


def inp_n():
	return int(input())

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

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

def is_odd(n):
	if n & 1:
		return True
	return False
for _ in range(inp_n()):
	n = input()
	l = sorted(n)
	if l[0] == l[-1]:
		print(-1)
	else:
		print(''.join(l))


def solve(s):
	s = sorted(s)
	if s[0] == s[-1]:
		return -1
	else:
		return ''.join(s)
n = int(input())
for i in range(n):
	s = input()
	print(solve(s))


n = int(input())
text = []
c = False
for i in range(n):
	word = input().split()
	current = list(word[0])
	if len(current) > 1:
		if all((i == current[0] for i in current)):
			print('-1')
		else:
			for i in range(len(current)):
				if current[i] != current[-i - 1]:
					print(''.join(current))
					break
				elif i == len(current) - 1:
					different = list(set(current).difference([current[i]]))
					k = current.index(different[0])
					(current[i], current[k]) = (current[k], current[i])
					print(''.join(current))
	else:
		print('-1')


t = int(input())
for t_itr in range(0, t):
	s = input()
	if s == s[0] * len(s):
		print(-1)
	elif s != s[::-1]:
		print(s)
	else:
		s = list(s)
		for i in range(1, len(s)):
			if s[i] != s[i - 1]:
				(s[i - 1], s[i]) = (s[i], s[i - 1])
				break
		print(''.join(s))


n = int(input())
for i in range(n):
	s = input()
	if s == s[::-1]:
		if len(set(s)) == 1:
			print(-1)
		else:
			print(''.join((str(i) for i in sorted(s))))
	else:
		print(s)


t = int(input())
for z in range(t):
	arr = [0] * 26
	s = list(input())
	n = len(s)
	for i in s:
		index = ord(i) - 97
		arr[index] += 1
	same = n in arr
	if same:
		print(-1)
	else:
		s.sort()
		print(''.join(s))


t = int(input())
while t > 0:
	s = input()
	if s.count(s[0]) == len(s):
		print(-1)
	elif s != s[::-1]:
		print(s)
	else:
		for i in range(len(s) - 1):
			if s[i] != s[0]:
				b = list(s)
				(b[0], b[i]) = (b[i], b[0])
				print(''.join(b))
				break
	t -= 1


t = int(input())
while t:
	s1 = input()
	s2 = s1[::-1]
	count = 0
	for i in range(len(s1)):
		if s1[i] == s2[i]:
			count += 1
	if count == len(s1):
		s3 = s1[0]
		s4 = s1[1:]
		s5 = s4 + s3
		if s5 == s1:
			print(-1)
		else:
			print(s5)
	else:
		print(s1)
	t -= 1


n = int(input())
a = list()
res = 0
for i in range(n):
	x = str(input())
	a.append(x)
for x in a:
	b = sorted(x)
	if len(set(sorted(str(x)))) == 1:
		print(-1)
	else:
		print(''.join(map(str, b)))


t = int(input())
for _ in range(t):
	s = input()
	d = set(s)
	if len(d) == 1:
		print('-1')
	elif s != s[::-1]:
		print(s)
	else:
		z = len(s)
		print(s[z - 1] + s[:z - 1])


import re
q = int(input())
for x in range(q):
	s = ''
	s1 = ''
	n = input()
	c = n.count('a')
	s = s + 'a' * c
	l = ['a']
	for y in n:
		if y in l:
			continue
		else:
			c = n.count(y)
			s = s + y * c
			l.append(y)
	for y in s:
		s1 = y + s1
	if re.match(s, s1):
		print('-1')
	else:
		print(s)


def palindrome(string):
	k = int(len(string) / 2)
	length = len(string)
	for val in range(k):
		if string[val] != string[length - 1 - val]:
			return -1
	return 1
t = int(input())
for v in range(t):
	new_str = input()
	if palindrome(new_str) == -1:
		print(new_str)
	else:
		p = 0
		new_list = list(new_str)
		for va in range(0, len(new_list) - 1):
			if new_list[va] != new_list[va + 1]:
				temp = new_list[va]
				new_list[va] = new_list[va + 1]
				new_list[va + 1] = temp
				print(''.join(new_list))
				p = 1
				break
		if p == 0:
			print(-1)


t = int(input())
for j in range(t):
	s = input()
	f = s.count(s[0])
	if f == len(s):
		print(-1)
	else:
		while s == s[::-1]:
			i = 0
			for i in range(1, len(s) - 1):
				a = s[0:i]
				b = s[i:]
				s = b + a
				if s != s[::-1]:
					break
		print(s)


for _ in range(int(input())):
	s = input()
	if s != s[::-1]:
		print(s)
	else:
		l = [i for i in s]
		s1 = ''.join(sorted(l))
		if s1 == s1[::-1]:
			print(-1)
		else:
			print(s1)


n = int(input())
for i in range(n):
	s = input()
	se = set()
	a = []
	for j in s:
		se.add(j)
		a.append(j)
	if len(se) == 1:
		print(-1)
	else:
		a.sort()
		for j in a:
			print(j, end='')
		print()


t = int(input())

def ispalin(str):
	if len(str) <= 1:
		return True
	if str[0] != str[-1]:
		return False
	return ispalin(str[1:-1])

def isallsame(str):
	for i in str:
		if i != str[0]:
			return False
	return True

def combination(str):
	if isallsame(str):
		return str
	for i in range(len(str)):
		a = str[i:]
		a += str[0:i]
		if ispalin(a) == False:
			return a
	return str
for i in range(t):
	s = input()
	if ispalin(s) == False:
		print(s)
	else:
		comb = combination(s)
		if comb != s:
			print(comb)
		else:
			print(-1)


t = int(input())
p = []
for m in range(t):
	temp = input()
	p.append(temp)
for i in range(t):
	s = p[i]
	n = len(s)
	h = int(n / 2)
	if h != n / 2:
		h = h + 1
	c = 0
	l = []
	for j in range(n):
		l.append(s[j])
		if s[0] != s[j]:
			c = c + 1
	if c == 0:
		print(-1)
	pal = True
	for _ in range(h):
		if s[_] != s[n - 1 - _]:
			pal = False
			print(s)
			break
	if pal == True:
		for v in range(h):
			if s[0] != s[v]:
				(l[0], l[v]) = (l[v], l[0])
				temp = ''.join(l)
				print(temp)
				break


for i in range(int(input())):
	x = input()
	if len(set(x)) == 1:
		print(-1)
	elif x == x[::-1]:
		print(x[-1] + x[0:-1])
	else:
		print(x)


n = int(input())
a = [input() for i in range(n)]
temp = list()
rand = 1
for i in range(n):
	if a[i][0] != a[i][-1]:
		print(a[i])
	elif a[i].count(a[i][0]) != len(a[i]):
		temp = list(a[i])
		while a[i][rand] == a[i][0]:
			rand += 1
		(temp[0], temp[rand]) = (temp[rand], temp[0])
		print(''.join(temp))
	else:
		print('-1')


t = int(input())
for i in range(t):
	s = input()
	r = sorted(s)
	if len(set(s)) == 1:
		print(-1)
	else:
		print(*r, sep='')


n = int(input())
for i in range(n):
	r = input()
	n = list(r)
	n.sort()
	nn = ''.join(n)
	if nn[::-1] == nn:
		print(-1)
	else:
		print(nn)


for n in range(int(input())):
	s = input()
	z = sorted(s)
	if z[0] == z[len(z) - 1]:
		print(-1)
	else:
		if z[::-1] == z:
			r = z[0]
			z[0] = z[len(z) - 1]
			z[len(z) - 1] = r
		else:
			z = z
		print(''.join(z))


n = int(input())
for i in range(n):
	s = input()
	if s != s[::-1]:
		print(s)
	else:
		j = (len(s) + 1) // 2 - 1
		s1 = list(s[:len(s) // 2 + 1])
		for i in range(len(s1) - 1):
			if s1[i] != s1[j]:
				(s1[j], s1[i]) = (s1[i], s1[j])
				print(''.join(s1) + s[len(s) // 2 + 1:])
				break
		else:
			print(-1)


import sys

def solve(t, ss):

	def output(s):
		s = s.rstrip()
		letters = set(s)
		if len(letters) == 1:
			return '-1'
		return ''.join(sorted(s))
	return map(output, ss)
t = input()
ss = sys.stdin.readlines()
res = solve(t, ss)
for s in res:
	print(s)


t = int(input())
for _ in range(t):
	str = list(input())
	if len(set(str)) == 1:
		print(-1)
	else:
		str.sort()
		for n in str:
			print(n, end='')
		print()


t = int(input())
for _ in range(t):
	a = input()
	if a[0] * len(a) == a:
		print('-1')
	else:
		print(''.join(sorted(a)))


n = int(input())
for i in range(n):
	s = input()
	if s != s[::-1]:
		print(s)
	else:
		t = s[1:] + s[0]
		if s == t:
			print('-1')
		else:
			print(t)


from collections import Counter
n = int(input())
for i in range(n):
	curr = input()
	c = Counter()
	resString = ''
	odd = 0
	for j in curr:
		c[j] += 1
	for j in c.keys():
		if c[j] % 2 == 1:
			odd += 1
		resString += j * c[j]
	if len(c.keys()) == 1:
		print(-1)
	else:
		print(resString)


import collections
t = int(input())
for q in range(0, t):
	a = input()
	s = a[::-1]
	if s != a:
		print(a)
	else:
		d = collections.Counter(a)
		if d[a[0]] == len(s):
			print('-1')
		else:
			a = list(a)
			for i in range(1, len(a)):
				if a[0] != a[i]:
					temp = a[i]
					a[i] = a[0]
					a[0] = temp
					break
			print(*a, sep='')


n = int(input())
for i in range(n):
	l = list(input())
	t = l[:]
	t.reverse()
	if l != t:
		z = ''.join(l)
		print(z)
	elif len(set(l)) == 1:
		print(-1)
	else:
		for j in range(len(l) - 1):
			if l[j] != l[j + 1]:
				(l[j], l[j + 1]) = (l[j + 1], l[j])
				z = ''.join(l)
				print(z)
				break


n = int(input())
for i in range(n):
	s = input()
	if s.count(s[0]) == len(s):
		print(-1)
		continue
	a = [i for i in s]
	if a[0] != a[len(s) - 1]:
		print(s)
		continue
	i = 0
	while a[0] == a[i]:
		i += 1
	(a[i], a[0]) = (a[0], a[i])
	for i in range(len(a)):
		print(a[i], end='')
	print()


for i in range(int(input())):
	s = input()
	ar = [str(i) for i in s]
	ar.sort()
	print('-1' if ar[0] == ar[-1] else ''.join(ar))


n = int(input())

def ispal(s):
	if len(s) == 0 or len(s) == 1:
		return True
	elif s[0] == s[-1]:
		return ispal(s[1:-1])
while n > 0:
	f = input()
	if len(set(f)) == 1:
		print(-1)
	elif ispal(f):
		l = len(f)
		print(f[:l // 2] + f[l // 2 + 1:] + f[l // 2])
	else:
		print(f)
	n -= 1


import collections, atexit, math, sys, bisect
sys.setrecursionlimit(1000000)

def getIntList():
	return list(map(int, input().split()))
try:
	import numpy

	def dprint(*args, **kwargs):
		print(*args, file=sys.stderr)
	dprint('debug mode')
except Exception:

	def dprint(*args, **kwargs):
		pass
inId = 0
outId = 0
if inId > 0:
	dprint('use input', inId)
	sys.stdin = open('input' + str(inId) + '.txt', 'r')
if outId > 0:
	dprint('use output', outId)
	sys.stdout = open('stdout' + str(outId) + '.txt', 'w')
	atexit.register(lambda : sys.stdout.close())
(N,) = getIntList()
for _ in range(N):
	s = input()
	c = s[0]
	ok = False
	for x in s:
		if x != c:
			g = list(s)
			g.sort()
			s = ''.join(g)
			print(s)
			ok = True
			break
	if not ok:
		print(-1)


t = int(input())
s = ''
chs = ''
ch1 = ''
for i in range(t):
	ch = input()
	ls = sorted(ch)
	cs = ''.join(ls)
	ls.sort(reverse=1)
	cr = ''.join(ls)
	if cr != cs:
		s += ''.join(ls) + '\n'
	else:
		s += '-1' + '\n'
print(s[:-1])


import math
t = int(input())
while t > 0:
	t -= 1
	s = str(input())
	d = [0] * 26
	for i in s:
		d[ord(i) - 97] += 1
	odd = 0
	ind = -1
	qq = 'abcdefghijklmnopqrstuvwxyz'
	for i in range(26):
		if d[i] % 2 == 1:
			ind = qq[i]
			odd += 1
	if d.count(0) == 25:
		print(-1)
		continue
	val = False
	for i in range(len(s)):
		if s[i] != s[len(s) - i - 1]:
			val = True
	if val:
		print(s)
	else:
		print(''.join(sorted(s)))


t = int(input())
for i in range(t):
	a = input()
	c = str
	b = a[::-1]
	if a == b:
		for i in range(len(a) - 1):
			if a[i] != a[i + 1]:
				a = list(a)
				c = a[i]
				a[i] = a[i + 1]
				a[i + 1] = c
				a = ''.join(a)
				print(a)
				break
		else:
			print(-1)
	else:
		print(a)


count = {j: 0 for j in 'abcdefghijklmnopqrstuvwxyz'}
t = int(input())
for i in range(t):
	string = input()
	for char in string:
		count[char] += 1
	nonzero = 0
	for (key, value) in count.items():
		if value != 0:
			nonzero += 1
			if nonzero >= 2:
				break
	if nonzero == 1:
		print(-1)
	else:
		ans = ''
		for (key, value) in count.items():
			ans += key * value
		print(ans)
	count = {j: 0 for j in 'abcdefghijklmnopqrstuvwxyz'}


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
from collections import 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')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for _ in range(int(input())):
	s = list(input())
	s.sort()
	if s[0] == s[-1]:
		print(-1)
	else:
		print(*s, sep='')


from collections import Counter
x = int(input())
lst = []
for i in range(x):
	lst.append(input())

def convert_non_palindrome(s):
	counts = Counter(s)
	if len(counts) == 1:
		return '-1'
	sorted_s = ''.join([x for x in sorted(s)])
	return sorted_s
for s in lst:
	print(convert_non_palindrome(s))


T = int(input())

def comparacion(string):
	if len(v) % 2 == 0:
		temp = v[:len(v) // 2]
		temp.reverse()
		if ''.join(temp) == ''.join(v[len(v) // 2:]):
			return True
		else:
			return False
	else:
		temp = v[:len(v) // 2]
		temp.reverse()
		if ''.join(temp) == ''.join(v[len(v) // 2 + 1:]):
			return True
		else:
			return False
while T:
	T -= 1
	v = input()
	if len(set(v)) == 1:
		print(-1)
	else:
		flag = 0
		v = list(v)
		for i in range(len(v) // 2 + 1):
			if comparacion(v) == True:
				temp = v[0]
				v[0] = v[len(v) // 2 + i]
				v[len(v) // 2 + i] = temp
			else:
				print(''.join(v))
				break


n = int(input())
for i in range(n):
	a = input()
	if a.count(a[0]) == len(a):
		print(-1)
	else:
		b = list(set(a))
		for j in range(len(b)):
			print(b[j] * a.count(b[j]), end='')
		print()


t = int(input())
for i in range(t):
	A = list(input())
	A.sort()
	if A[0] == A[-1]:
		print(-1)
	else:
		for c in A:
			print(c, end='')
		print('')


n = int(input())
for i in range(n):
	s = input()
	l = sorted(s)
	if l[0] == l[len(l) - 1]:
		print('-1')
	else:
		for i in l:
			print(i, end='')
		print()


n = int(input())
for i in range(n):
	s = input()
	if len(s) == 1:
		print('-1')
		continue
	k = s[::-1]
	if k != s:
		print(s)
		continue
	elif s.count(s[0]) == len(s):
		print('-1')
	else:
		i = 1
		while s[0] == s[i]:
			i += 1
		print(s[i] + s[1:i] + s[0] + s[i + 1:len(s)])


for _ in range(int(input())):
	s = input()
	st = set(s)
	if len(st) == 1:
		print(-1)
	else:
		s = list(s)
		s.sort()
		print(''.join(map(str, s)))


T = int(input())
for i in range(0, T):
	s = input()
	s = s.strip()
	bag = set()
	for c in s:
		if c not in bag:
			bag.add(c)
	if len(bag) == 1:
		print(-1)
	else:
		print(''.join(sorted(s)))


t = int(input())
for i in range(0, t):
	s = input()
	x = 'string'
	for i in range(0, len(s)):
		if s[i] != s[0]:
			x = i
			break
	if x == 'string':
		print(-1)
	else:
		print(s[:x] + s[x + 1:] + s[x])


def rearrange(mystr):
	if mystr is None:
		return None
	lm = list(mystr)
	if lm == lm[::-1]:
		lms = sorted(lm)
		if lms == lm:
			return -1
		else:
			return ''.join(lms)
	else:
		return mystr
n = int(input())
for _ in range(n):
	print(rearrange(str(input())))


n = int(input())
for i in range(n):
	string = list(input())
	s = list(dict.fromkeys(string))
	if len(s) == 1:
		print(-1)
	else:
		string.sort()
		print(''.join(string))


n = int(input())
for i in range(n):
	s = list(input())
	if s.count(s[0]) == len(s):
		print(-1)
	else:
		k = s[::-1]
		if s != k:
			print(''.join(s))
		else:
			if len(s) % 2 == 0:
				a = s[len(s) // 2 - 1]
				b = s[len(s) // 2]
				s.pop(len(s) // 2 - 1)
				s.pop(len(s) // 2)
				s.append(a)
				s.append(b)
			else:
				a = s.pop(len(s) // 2)
				s.append(a)
			print(''.join(s))


import sys
import math
import bisect
import itertools

def main():
	for _ in range(int(input())):
		A = list(input())
		A.sort()
		if A == A[::-1]:
			print(-1)
		else:
			print(''.join(list((str(a) for a in A))))
main()


t = int(input())
l = [0 for i in range(101)]
while t:
	s = input()
	r = ''
	r1 = s[0]
	e = '-1'
	for i in range(1, len(s)):
		if s[i] != r1:
			e = i
			break
	if e == '-1':
		print(e)
	else:
		for i in range(len(s)):
			if i != e:
				r = r + s[i]
		r = r + s[e]
		print(r)
	t = t - 1


def reverse(string):
	return string[::-1]
n = int(input())
while n:
	x = input()
	y = reverse(x)
	if x != y:
		print(x)
	else:
		for i in range(1, len(x)):
			if x[i] != x[i - 1]:
				x = x[:i - 1] + x[i] + x[i - 1] + x[i + 1:]
				break
		if x == y:
			print(-1)
		else:
			print(x)
	n -= 1


t = int(input())
for g in range(0, t):
	s = input()
	a = list(set(s))
	fre = []
	if len(set(a)) == 1:
		print(-1)
	else:
		for i in range(0, len(a)):
			temp = 0
			for j in range(0, len(s)):
				if a[i] == s[j]:
					temp += 1
			fre.append(temp)
		ans = ''
		for i in range(0, len(a)):
			ans += fre[i] * a[i]
		print(ans)


t = int(input())
li = []

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

def dsort(s):
	return ''.join(sorted(s))
i = 0
while i < t:
	i += 1
	j = input()
	li = li + [j]
for n in li:
	n = dsort(n)
	if palindrome(n):
		print('-1')
	else:
		print(n)


import collections
n = int(input())
l = [input() for i in range(n)]
for i in l:
	a = collections.Counter(i)
	if len(a) == 1:
		print(-1)
	else:
		b = list(a.items())
		for j in b:
			print(j[0] * j[1], end='')
		print()


x = int(input())
for i in range(x):
	y = input()
	z = set(y)
	if len(z) == 1:
		print(-1)
	else:
		a = y[::-1]
		if a == y:
			print(y[0] + y[:0:-1])
		else:
			print(y)


from bisect import bisect_right as br
from bisect import bisect_left as bl
from collections import defaultdict
from itertools import combinations
import sys
import math
MAX = sys.maxsize
MAXN = 10 ** 6 + 10
MOD = 10 ** 9 + 7

def isprime(n):
	n = abs(int(n))
	if n < 2:
		return False
	if n == 2:
		return True
	if not n & 1:
		return False
	for x in range(3, int(n ** 0.5) + 1, 2):
		if n % x == 0:
			return False
	return True

def mhd(a, b, x, y):
	return abs(a - x) + abs(b - y)

def numIN():
	return map(int, sys.stdin.readline().strip().split())

def charIN():
	return sys.stdin.readline().strip().split()
t = [(-1, -1)] * 1000010

def create(a):
	global t, n
	for i in range(n, 2 * n):
		t[i] = (a[i - n], i - n)
	for i in range(n - 1, 0, -1):
		x = [t[2 * i], t[2 * i + 1]]
		x.sort(key=lambda x: x[0])
		t[i] = x[1]

def update(idx, value):
	global t, n
	idx = idx + n
	t[idx] = value
	while idx > 1:
		idx = idx // 2
		x = [t[2 * idx], t[2 * idx + 1]]
		x.sort(key=lambda x: x[0])
		t[idx] = x[1]
for _ in range(int(input())):
	s = input()
	if s != s[::-1]:
		print(s)
	else:
		x = ''.join(sorted(s))
		if x[0] == x[-1]:
			print(-1)
		else:
			print(x)


t = int(input())
letter = 'abcdefghijklmnopqrstuvwxyz'
mp = {}
for i in range(0, 26):
	mp[letter[i]] = i
while t > 0:
	t -= 1
	s = input()
	n = len(s)
	a = [0 for i in range(0, 26)]
	ok = 0
	for i in range(0, n):
		a[mp[s[i]]] += 1
		if i < n - 1 and s[i] != s[i + 1]:
			ok = 1
	if ok == 0:
		print(-1)
	else:
		for i in range(0, 26):
			for j in range(0, a[i]):
				print(letter[i], end='')
		print()


n = int(input())
for i in range(n):
	d = input()
	u = sorted(d)
	if u == u[::-1]:
		print(-1)
	else:
		print(''.join(u))


n = int(input())

def func(n):
	n = sorted(n)
	if n[0] == n[-1]:
		print(-1)
	else:
		res = ''
		for x in n:
			res += x
		print(res)
for i in range(n):
	func(input())


def changestring(l):
	a = list(l)
	c = list(l)
	b = list(l)
	a.reverse()
	if a == b:
		for i in range(len(b) // 2):
			(b[i], b[i + 1]) = (b[i + 1], b[i])
			if b != c:
				return ''.join(b)
			else:
				continue
		if c == b:
			return '-1'
	else:
		return l
a = int(input())
c = ''
b = ''
d = []
for i in range(a):
	n = input()
	c = c + ' ' + changestring(n)
b = c.strip()
d = c.split(' ')
for i in range(len(d)):
	print(d[i], end='\n')


n = int(input())
for i in range(n):
	l = list(input())
	m = len(l)
	for i in range(m // 2 + 1):
		r = l.count(l[i])
		if r == m:
			print(-1)
			break
		elif l[i] == l[m - 1 - i]:
			if i == m - 2:
				print(-1)
				break
			elif l[i] != l[i + 1]:
				p = l[i]
				r = l[i + 1]
				l[i] = r
				l[i + 1] = p
				print(''.join(l))
				break
			else:
				continue
		elif l[i] != l[m - i - 1]:
			print(''.join(l))
			break


def isPalin(s):
	for i in range(len(s) // 2):
		if s[i] != s[len(s) - 1 - i]:
			return False
	return True
n = int(input())
for i in range(n):
	s = list(input())
	s.sort()
	if isPalin(s):
		print(-1)
	else:
		print(''.join(s))


t = int(input())
S = [input() for i in range(t)]
for i in range(t):
	word = list(S[i])
	if len(set(word)) == 1:
		print(-1)
	else:
		word.sort()
		print(''.join(map(str, word)))


def is_palindrome(word):
	(i, j) = (0, len(word) - 1)
	all_equal = True
	letters = set(word)
	if len(letters) > 1:
		all_equal = False
		while i < j:
			if word[i] != word[j]:
				all_equal = False
				return (False, all_equal)
			i += 1
			j -= 1
	return (True, all_equal)
t = int(input())
for _ in range(t):
	word = input()
	ans = is_palindrome(word)
	if ans[1] is True:
		print('-1')
	elif ans[0] is False:
		print(word)
	elif len(word) & 1:
		print(word[:len(word) // 2] + word[len(word) // 2 + 1:] + word[len(word) // 2])
	else:
		print(word[1:] + word[0])


n = int(input())
list = []
for i in range(n):
	t = input()
	if len(t) * t[0] == t:
		list.append(-1)
	elif t == t[::-1]:
		for j in range(1, len(t)):
			if t[j] != t[0]:
				t = t[j] + t[:j] + t[j + 1:]
				list.append(t)
				break
	else:
		list.append(t)
for i in range(n):
	print(list[i])


for i in range(int(input())):
	s = input()
	res = ''.join(sorted(s))
	st = set()
	for j in range(len(s)):
		st.add(s[j])
	if len(st) == 1:
		print(-1)
	else:
		print(res)


def is_equal(a, b):
	l = len(a)
	count = 0
	for i in range(l):
		if a[i] != b[i]:
			count = 1
			break
	if count == 0:
		return True
	else:
		return False

def is_palindrome(a):
	b = a[::-1]
	if is_equal(a, b):
		return True
	else:
		return False
t = int(input())
for p in range(t):
	string = input()
	if is_palindrome(string):
		sor_string = sorted(string)
		if is_equal(sor_string, string):
			print(-1)
		else:
			for s in sor_string:
				print(s, end='')
			print('')
	else:
		print(string)


def f(n, i):
	if len(n) <= 1:
		return -1
	elif len(n) == 2 or i == len(x) // 2:
		return -1
	elif n[i] != n[i + 1]:
		return n[:i] + n[i + 1] + n[i] + n[i + 2:]
	else:
		return f(n, i + 1)
t = int(input())
for i in range(t):
	n = input()
	x = n[::-1]
	if x != n:
		print(n)
	else:
		print(f(n, 0))


t = int(input())
for i in range(t):
	s = input()
	if s == s[0] * len(s):
		print(-1)
	elif s == s[::-1]:
		for j in range(len(s) - 1):
			if s[j] != s[j + 1]:
				s = s[:j] + s[j + 1] + s[j] + s[j + 2:]
				break
		print(s)
	else:
		print(s)


t = int(input())
for i in range(t):
	s = input()
	a = []
	for j in range(len(s)):
		a.append(s[j])
	a.sort()
	s = ''.join(a)
	if s == s[::-1]:
		print('-1')
	else:
		print(s)


A = []
for i in range(int(input())):
	q = input()
	B = list(q)
	B.sort()
	if B[0] == B[-1]:
		A.append(-1)
	else:
		A.append(''.join(B))
for a in A:
	print(a)


def f(s):
	l = len(s)
	for i in range(l // 2 + 1):
		if s[i] != s[l - i - 1]:
			return s
	flag = True
	for i in range(1, l):
		if s[0] != s[i]:
			flag = False
			break
	if flag:
		return -1
	st = 0
	for i in range(1, l):
		if s[st] != s[i]:
			st = i
			break
	return s[st] + s[1:st] + s[0] + s[st + 1:]
t = int(input())
for _ in range(t):
	s = input()
	print(f(s))


def letrear():
	t = int(input())
	l = list()
	for i in range(t):
		l.append(input())
	for i in range(t):
		if l[i] != l[i][::-1]:
			print(l[i])
		else:
			s = l[i]
			le = sorted(s)
			s = ''
			for j in le:
				s += j
			if s == s[::-1]:
				print(-1)
			else:
				print(s)
letrear()


t = int(input())
ansarr = []
for l in range(t):
	s = str(input())
	dict1 = {}
	for i in range(len(s)):
		try:
			dict1[s[i]] += 1
		except:
			KeyError
			dict1[s[i]] = 1
	if len(s) == s.count(s[0]):
		ansarr.append(-1)
	else:
		s1 = ''
		for i in dict1.keys():
			s1 += dict1[i] * i
		ansarr.append(s1)
print(*ansarr)


import random
t = int(input())
while t > 0:
	s = list(input())
	if s != s[::-1]:
		print(''.join(s))
	elif s.count(s[0]) == len(s):
		print(-1)
	else:
		while s == s[::-1]:
			random.shuffle(s)
		print(''.join(s))
	t -= 1


t = int(input())
for i in range(t):
	a = input()
	c = 0
	for j in range(1, len(a), 1):
		if a[0] == a[j]:
			c += 1
	if c == len(a) - 1:
		print(-1)
	elif a[0] != a[-1]:
		print(a)
	elif a[0] == a[-1]:
		letter = []
		for k in a:
			letter.append(k)
		for m in range(1, len(letter) - 1, 1):
			if letter[0] != letter[m]:
				main = letter[0]
				letter[0] = letter[m]
				letter[m] = main
		for kl in letter:
			print(kl, end='')
		print()


def divisors(M):
	d = []
	i = 1
	while M >= i ** 2:
		if M % i == 0:
			d.append(i)
			if i ** 2 != M:
				d.append(M // i)
		i = i + 1
	return d

def popcount(x):
	x = x - (x >> 1 & 1431655765)
	x = (x & 858993459) + (x >> 2 & 858993459)
	x = x + (x >> 4) & 252645135
	x = x + (x >> 8)
	x = x + (x >> 16)
	return x & 127

def eratosthenes(n):
	res = [0 for i in range(n + 1)]
	prime = set([])
	for i in range(2, n + 1):
		if not res[i]:
			prime.add(i)
			for j in range(1, n // i + 1):
				res[i * j] = 1
	return prime

def factorization(n):
	res = []
	for p in prime:
		if n % p == 0:
			while n % p == 0:
				n //= p
			res.append(p)
	if n != 1:
		res.append(n)
	return res

def euler_phi(n):
	res = n
	for x in range(2, n + 1):
		if x ** 2 > n:
			break
		if n % x == 0:
			res = res // x * (x - 1)
			while n % x == 0:
				n //= x
	if n != 1:
		res = res // n * (n - 1)
	return res

def ind(b, n):
	res = 0
	while n % b == 0:
		res += 1
		n //= b
	return res

def isPrimeMR(n):
	d = n - 1
	d = d // (d & -d)
	L = [2, 3, 5, 7, 11, 13, 17]
	for a in L:
		t = d
		y = pow(a, t, n)
		if y == 1:
			continue
		while y != n - 1:
			y = y * y % n
			if y == 1 or t == n - 1:
				return 0
			t <<= 1
	return 1

def findFactorRho(n):
	from math import gcd
	m = 1 << n.bit_length() // 8
	for c in range(1, 99):
		f = lambda x: (x * x + c) % n
		(y, r, q, g) = (2, 1, 1, 1)
		while g == 1:
			x = y
			for i in range(r):
				y = f(y)
			k = 0
			while k < r and g == 1:
				ys = y
				for i in range(min(m, r - k)):
					y = f(y)
					q = q * abs(x - y) % n
				g = gcd(q, n)
				k += m
			r <<= 1
		if g == n:
			g = 1
			while g == 1:
				ys = f(ys)
				g = gcd(abs(x - ys), n)
		if g < n:
			if isPrimeMR(g):
				return g
			elif isPrimeMR(n // g):
				return n // g
			return findFactorRho(g)

def primeFactor(n):
	i = 2
	ret = {}
	rhoFlg = 0
	while i * i <= n:
		k = 0
		while n % i == 0:
			n //= i
			k += 1
		if k:
			ret[i] = k
		i += 1 + i % 2
		if i == 101 and n >= 2 ** 20:
			while n > 1:
				if isPrimeMR(n):
					(ret[n], n) = (1, 1)
				else:
					rhoFlg = 1
					j = findFactorRho(n)
					k = 0
					while n % j == 0:
						n //= j
						k += 1
					ret[j] = k
	if n > 1:
		ret[n] = 1
	if rhoFlg:
		ret = {x: ret[x] for x in sorted(ret)}
	return ret

def divisors(n):
	res = [1]
	prime = primeFactor(n)
	for p in prime:
		newres = []
		for d in res:
			for j in range(prime[p] + 1):
				newres.append(d * p ** j)
		res = newres
	res.sort()
	return res

def xorfactorial(num):
	if num == 0:
		return 0
	elif num == 1:
		return 1
	elif num == 2:
		return 3
	elif num == 3:
		return 0
	else:
		x = baseorder(num)
		return 2 ** x * ((num - 2 ** x + 1) % 2) + function(num - 2 ** x)

def xorconv(n, X, Y):
	if n == 0:
		res = [X[0] * Y[0] % mod]
		return res
	x = [X[i] + X[i + 2 ** (n - 1)] for i in range(2 ** (n - 1))]
	y = [Y[i] + Y[i + 2 ** (n - 1)] for i in range(2 ** (n - 1))]
	z = [X[i] - X[i + 2 ** (n - 1)] for i in range(2 ** (n - 1))]
	w = [Y[i] - Y[i + 2 ** (n - 1)] for i in range(2 ** (n - 1))]
	res1 = xorconv(n - 1, x, y)
	res2 = xorconv(n - 1, z, w)
	former = [(res1[i] + res2[i]) * inv for i in range(2 ** (n - 1))]
	latter = [(res1[i] - res2[i]) * inv for i in range(2 ** (n - 1))]
	former = list(map(lambda x: x % mod, former))
	latter = list(map(lambda x: x % mod, latter))
	return former + latter

def merge_sort(A, B):
	(pos_A, pos_B) = (0, 0)
	(n, m) = (len(A), len(B))
	res = []
	while pos_A < n and pos_B < m:
		(a, b) = (A[pos_A], B[pos_B])
		if a < b:
			res.append(a)
			pos_A += 1
		else:
			res.append(b)
			pos_B += 1
	res += A[pos_A:]
	res += B[pos_B:]
	return res

class UnionFindVerSize:

	def __init__(self, N):
		self._parent = [n for n in range(0, N)]
		self._size = [1] * N
		self.group = N

	def find_root(self, x):
		if self._parent[x] == x:
			return x
		self._parent[x] = self.find_root(self._parent[x])
		stack = [x]
		while self._parent[stack[-1]] != stack[-1]:
			stack.append(self._parent[stack[-1]])
		for v in stack:
			self._parent[v] = stack[-1]
		return self._parent[x]

	def unite(self, x, y):
		gx = self.find_root(x)
		gy = self.find_root(y)
		if gx == gy:
			return
		self.group -= 1
		if self._size[gx] < self._size[gy]:
			self._parent[gx] = gy
			self._size[gy] += self._size[gx]
		else:
			self._parent[gy] = gx
			self._size[gx] += self._size[gy]

	def get_size(self, x):
		return self._size[self.find_root(x)]

	def is_same_group(self, x, y):
		return self.find_root(x) == self.find_root(y)

class WeightedUnionFind:

	def __init__(self, N):
		self.parent = [i for i in range(N)]
		self.size = [1 for i in range(N)]
		self.val = [0 for i in range(N)]
		self.flag = True
		self.edge = [[] for i in range(N)]

	def dfs(self, v, pv):
		stack = [(v, pv)]
		new_parent = self.parent[pv]
		while stack:
			(v, pv) = stack.pop()
			self.parent[v] = new_parent
			for (nv, w) in self.edge[v]:
				if nv != pv:
					self.val[nv] = self.val[v] + w
					stack.append((nv, v))

	def unite(self, x, y, w):
		if not self.flag:
			return
		if self.parent[x] == self.parent[y]:
			self.flag = self.val[x] - self.val[y] == w
			return
		if self.size[self.parent[x]] > self.size[self.parent[y]]:
			self.edge[x].append((y, -w))
			self.edge[y].append((x, w))
			self.size[x] += self.size[y]
			self.val[y] = self.val[x] - w
			self.dfs(y, x)
		else:
			self.edge[x].append((y, -w))
			self.edge[y].append((x, w))
			self.size[y] += self.size[x]
			self.val[x] = self.val[y] + w
			self.dfs(x, y)

class Dijkstra:

	class Edge:

		def __init__(self, _to, _cost):
			self.to = _to
			self.cost = _cost

	def __init__(self, V):
		self.G = [[] for i in range(V)]
		self._E = 0
		self._V = V

	@property
	def E(self):
		return self._E

	@property
	def V(self):
		return self._V

	def add_edge(self, _from, _to, _cost):
		self.G[_from].append(self.Edge(_to, _cost))
		self._E += 1

	def shortest_path(self, s):
		import heapq
		que = []
		d = [10 ** 15] * self.V
		d[s] = 0
		heapq.heappush(que, (0, s))
		while len(que) != 0:
			(cost, v) = heapq.heappop(que)
			if d[v] < cost:
				continue
			for i in range(len(self.G[v])):
				e = self.G[v][i]
				if d[e.to] > d[v] + e.cost:
					d[e.to] = d[v] + e.cost
					heapq.heappush(que, (d[e.to], e.to))
		return d

def Z_algorithm(s):
	N = len(s)
	Z_alg = [0] * N
	Z_alg[0] = N
	i = 1
	j = 0
	while i < N:
		while i + j < N and s[j] == s[i + j]:
			j += 1
		Z_alg[i] = j
		if j == 0:
			i += 1
			continue
		k = 1
		while i + k < N and k + Z_alg[k] < j:
			Z_alg[i + k] = Z_alg[k]
			k += 1
		i += k
		j -= k
	return Z_alg

class BIT:

	def __init__(self, n, mod=0):
		self.BIT = [0] * (n + 1)
		self.num = n
		self.mod = mod

	def query(self, idx):
		res_sum = 0
		mod = self.mod
		while idx > 0:
			res_sum += self.BIT[idx]
			if mod:
				res_sum %= mod
			idx -= idx & -idx
		return res_sum

	def update(self, idx, x):
		mod = self.mod
		while idx <= self.num:
			self.BIT[idx] += x
			if mod:
				self.BIT[idx] %= mod
			idx += idx & -idx
		return

class dancinglink:

	def __init__(self, n, debug=False):
		self.n = n
		self.debug = debug
		self._left = [i - 1 for i in range(n)]
		self._right = [i + 1 for i in range(n)]
		self.exist = [True for i in range(n)]

	def pop(self, k):
		if self.debug:
			assert self.exist[k]
		L = self._left[k]
		R = self._right[k]
		if L != -1:
			if R != self.n:
				(self._right[L], self._left[R]) = (R, L)
			else:
				self._right[L] = self.n
		elif R != self.n:
			self._left[R] = -1
		self.exist[k] = False

	def left(self, idx, k=1):
		if self.debug:
			assert self.exist[idx]
		res = idx
		while k:
			res = self._left[res]
			if res == -1:
				break
			k -= 1
		return res

	def right(self, idx, k=1):
		if self.debug:
			assert self.exist[idx]
		res = idx
		while k:
			res = self._right[res]
			if res == self.n:
				break
			k -= 1
		return res

class SparseTable:

	def __init__(self, A, merge_func, ide_ele):
		N = len(A)
		n = N.bit_length()
		self.table = [[ide_ele for i in range(n)] for i in range(N)]
		self.merge_func = merge_func
		for i in range(N):
			self.table[i][0] = A[i]
		for j in range(1, n):
			for i in range(0, N - 2 ** j + 1):
				f = self.table[i][j - 1]
				s = self.table[i + 2 ** (j - 1)][j - 1]
				self.table[i][j] = self.merge_func(f, s)

	def query(self, s, t):
		b = t - s + 1
		m = b.bit_length() - 1
		return self.merge_func(self.table[s][m], self.table[t - 2 ** m + 1][m])

class BinaryTrie:

	class node:

		def __init__(self, val):
			self.left = None
			self.right = None
			self.max = val

	def __init__(self):
		self.root = self.node(-10 ** 15)

	def append(self, key, val):
		pos = self.root
		for i in range(29, -1, -1):
			pos.max = max(pos.max, val)
			if key >> i & 1:
				if pos.right is None:
					pos.right = self.node(val)
					pos = pos.right
				else:
					pos = pos.right
			elif pos.left is None:
				pos.left = self.node(val)
				pos = pos.left
			else:
				pos = pos.left
		pos.max = max(pos.max, val)

	def search(self, M, xor):
		res = -10 ** 15
		pos = self.root
		for i in range(29, -1, -1):
			if pos is None:
				break
			if M >> i & 1:
				if xor >> i & 1:
					if pos.right:
						res = max(res, pos.right.max)
					pos = pos.left
				else:
					if pos.left:
						res = max(res, pos.left.max)
					pos = pos.right
			elif xor >> i & 1:
				pos = pos.right
			else:
				pos = pos.left
		if pos:
			res = max(res, pos.max)
		return res

def solveequation(edge, ans, n, m):
	x = [0] * m
	used = [False] * n
	for v in range(n):
		if used[v]:
			continue
		y = dfs(v)
		if y != 0:
			return False
	return x

	def dfs(v):
		used[v] = True
		r = ans[v]
		for (to, dire, id) in edge[v]:
			if used[to]:
				continue
			y = dfs(to)
			if dire == -1:
				x[id] = y
			else:
				x[id] = -y
			r += y
		return r

class Matrix:
	mod = 10 ** 9 + 7

	def set_mod(m):
		Matrix.mod = m

	def __init__(self, L):
		self.row = len(L)
		self.column = len(L[0])
		self._matrix = L
		for i in range(self.row):
			for j in range(self.column):
				self._matrix[i][j] %= Matrix.mod

	def __getitem__(self, item):
		if type(item) == int:
			raise IndexError('you must specific row and column')
		elif len(item) != 2:
			raise IndexError('you must specific row and column')
		(i, j) = item
		return self._matrix[i][j]

	def __setitem__(self, item, val):
		if type(item) == int:
			raise IndexError('you must specific row and column')
		elif len(item) != 2:
			raise IndexError('you must specific row and column')
		(i, j) = item
		self._matrix[i][j] = val

	def __add__(self, other):
		if (self.row, self.column) != (other.row, other.column):
			raise SizeError('sizes of matrixes are different')
		res = [[0 for j in range(self.column)] for i in range(self.row)]
		for i in range(self.row):
			for j in range(self.column):
				res[i][j] = self._matrix[i][j] + other._matrix[i][j]
				res[i][j] %= Matrix.mod
		return Matrix(res)

	def __sub__(self, other):
		if (self.row, self.column) != (other.row, other.column):
			raise SizeError('sizes of matrixes are different')
		res = [[0 for j in range(self.column)] for i in range(self.row)]
		for i in range(self.row):
			for j in range(self.column):
				res[i][j] = self._matrix[i][j] - other._matrix[i][j]
				res[i][j] %= Matrix.mod
		return Matrix(res)

	def __mul__(self, other):
		if type(other) != int:
			if self.column != other.row:
				raise SizeError('sizes of matrixes are different')
			res = [[0 for j in range(other.column)] for i in range(self.row)]
			for i in range(self.row):
				for j in range(other.column):
					temp = 0
					for k in range(self.column):
						temp += self._matrix[i][k] * other._matrix[k][j]
					res[i][j] = temp % Matrix.mod
			return Matrix(res)
		else:
			n = other
			res = [[n * self._matrix[i][j] % Matrix.mod for j in range(self.column)] for i in range(self.row)]
			return Matrix(res)

	def __pow__(self, m):
		if self.column != self.row:
			raise MatrixPowError('the size of row must be the same as that of column')
		n = self.row
		res = Matrix([[int(i == j) for i in range(n)] for j in range(n)])
		while m:
			if m % 2 == 1:
				res = res * self
			self = self * self
			m //= 2
		return res

	def __str__(self):
		res = []
		for i in range(self.row):
			for j in range(self.column):
				res.append(str(self._matrix[i][j]))
				res.append(' ')
			res.append('\n')
		res = res[:len(res) - 1]
		return ''.join(res)
import sys, random, bisect
from collections import deque, defaultdict
from heapq import heapify, heappop, heappush
from itertools import permutations
from math import log, gcd
input = lambda : sys.stdin.readline().rstrip()
mi = lambda : map(int, input().split())
li = lambda : list(mi())
for _ in range(int(input())):
	s = input()
	n = len(s)
	s = [s[i] for i in range(n)]
	s.sort()
	if s[0] == s[-1]:
		print(-1)
	else:
		print(''.join(s))


for _ in range(int(input())):
	s = list(map(str, input().replace('', ' ').split()))
	t = s[:]
	r = s[:]
	r.reverse()
	t.sort()
	if s == t:
		if s != r:
			print(*t, sep='')
		else:
			print(-1)
	else:
		print(*t, sep='')


from collections import defaultdict
t = int(input())
for _ in range(t):
	s = input()
	d = defaultdict(int)
	for i in s:
		d[i] += 1
	if len(d) <= 1:
		print('-1')
	else:
		s = sorted(s)
		print(''.join(s))


for _ in range(int(input())):
	s = input()
	d = list(s)
	d = set(d)
	if len(d) == 1:
		print(-1)
	elif s[::-1] != s:
		print(s)
	else:
		s = list(s)
		n = len(s)
		for i in range(1, n):
			if s[i] != s[i - 1]:
				c = s[i]
				s[i] = s[i - 1]
				s[i - 1] = c
				break
		for i in s:
			print(i, end='')
		print()


t = int(input())
while t:
	s = input()
	ls = []
	for i in range(len(s)):
		ls.append(s[i])
	ls.sort()
	if ls.count(ls[0]) == len(ls):
		print(-1)
	else:
		print(''.join((x for x in ls)))
	t -= 1


def allSame(s):
	if len(s) == 1:
		return True
	for i in range(1, len(s)):
		if s[i] != s[0]:
			return False
	return True

def isPalin(s):
	i = 0
	j = len(s) - 1
	res = True
	while i < j:
		if s[i] != s[j]:
			res = False
			break
		i += 1
		j -= 1
	return res

def sol():
	s = input().strip()
	if allSame(s):
		print(-1)
	else:
		if isPalin(s):
			l = s[-1]
			for i in range(len(s)):
				if s[i] != l:
					temp = s[i]
					s = s[:i] + l + s[i + 1:]
					s = s[:len(s) - 1] + temp
					break
		print(s)

def main():
	t = int(input())
	for i in range(t):
		sol()
main()


def swap(s, i, j):
	return ''.join((s[:i], s[j], s[i + 1:j], s[i], s[j + 1:]))

def palindrome(s):
	flag = 0
	for i in range(len(s)):
		if s[i] != s[len(s) - i - 1]:
			flag = 1
			break
	return flag
t = int(input())
while t > 0:
	s = input()
	if s.count(s[0]) == len(s):
		print('-1')
		t = t - 1
		continue
	if palindrome(s) == 0:
		for i in range(len(s) - 1):
			if s[i] != s[i + 1]:
				s = swap(s, i, i + 1)
				break
		print(s)
	else:
		print(s)
	t = t - 1


t = int(input())
l = []
for _ in range(t):
	s = list(input())
	s.sort()
	if s[-1] == s[0]:
		print('-1')
	else:
		print(''.join(s))


def palin(s):
	n = len(s)
	i = 0
	while i < n / 2:
		if s[i] != s[n - 1 - i]:
			return False
		else:
			pass
		i += 1
	return True

def make_good(s):
	for i in range(len(s) - 2):
		s1 = s[0:i] + s[i + 1] + s[i] + s[i + 2:]
		if not palin(s1):
			return s1
n = int(input())
l = []
for i in range(n):
	s = input()
	if not palin(s):
		l.append(s)
	elif len(set([x for x in s])) <= 1:
		l.append('-1')
	else:
		l1 = [x for x in s]
		l1.sort()
		s = ''.join(l1)
		l.append(s)
for k in l:
	print(k)


t = int(input())
for i in range(t):
	s = input()
	if s == s[::-1]:
		a = len(s)
		done = False
		for j in range(a - 1):
			if s[j] != s[j + 1]:
				print(s[:j] + s[j + 1] + s[j] + s[j + 2:])
				done = True
				break
		if not done:
			print(-1)
	else:
		print(s)


t = int(input())
answers = []
for i in range(0, t):
	s = input()
	res = ' '
	x = s[0]
	y = s[len(s) - 1]
	if x != y:
		res = s
	else:
		for i in range(1, len(s)):
			if s[i] != x and s[i] != y:
				res = s[i] + s[1:i] + x + s[i + 1:]
				break
	if res == ' ':
		answers.append(-1)
	else:
		answers.append(res)
for i in range(0, len(answers)):
	print(answers[i])


t = int(input())
for i in range(t):
	s = input()
	k = True
	for i in range(len(s)):
		if s[i] != s[len(s) - i - 1]:
			k = False
			break
	if not k:
		print(s)
	else:
		s1 = ''
		for i in range(len(s) - 1):
			if s[i] != s[i + 1]:
				k = False
				s1 += s[:i] + s[i + 1] + s[i] + s[i + 2:]
				break
		if not k:
			print(s1)
		else:
			print(-1)


from collections import defaultdict

def solve():
	s = input()
	if s != s[::-1]:
		return s
	s = list(s)
	for idx in range(1, len(s) - 1):
		if s[idx] != s[0]:
			(s[idx], s[0]) = (s[0], s[idx])
			return ''.join(s)
	return -1
T = int(input())
for _ in range(T):
	print(solve())


for _ in range(int(input())):
	d = {}
	for c in input():
		if c in d:
			d[c] += 1
		else:
			d[c] = 1
	if len(d) == 1:
		print(-1)
	else:
		gs = ''
		for c in d:
			gs = gs + c * d[c]
		print(gs)


for i in range(int(input())):
	str1 = input()
	hash = []
	size = len(str1)
	if size == 1:
		print('-1')
	else:
		for j in range(30):
			hash.append(0)
		for j in str1:
			hash[ord(j) - 97] += 1
		f = 0
		for j in range(size - 1):
			if str1[j] == str1[j + 1]:
				f = 1
			else:
				f = 0
				break
		if f:
			print('-1')
		else:
			for j in range(26):
				for k in range(hash[j]):
					print(chr(j + 97), end='')
				hash[j] = int(hash[j] / 2)
			print()


gi = lambda : list(map(int, input().split()))
for k in range(gi()[0]):
	s = input()
	if len(set(s)) == 1:
		print(-1)
	else:
		print(''.join(sorted(s)))


n = int(input())
for _ in range(n):
	string = input()
	sorted_string = ''.join(sorted(string))
	set_string = set(string)
	if len(set_string) == 1:
		print(-1)
	else:
		print(sorted_string)


t = int(input())
while t > 0:
	x = str(input())
	y = len(x)
	if x[-1:-y - 1:-1] != x:
		print(x)
	elif x.count(x[0]) == y:
		print('-1')
	else:
		for i in range(1, y):
			if x[0] != x[i]:
				print(x[i], end='')
				print(x[1:i], end='')
				print(x[0], end='')
				print(x[i + 1:y])
				break
	t -= 1


for i in range(int(input())):
	a = sorted(input())
	if a[0] == a[-1]:
		print('-1')
	else:
		print(''.join(a))


def ispalindrome(s):
	for x in range(len(s) // 2):
		if s[x] != s[len(s) - x - 1]:
			return False
	return True
t = int(input())
for i in range(t):
	s = input()
	if s.count(s[0]) == len(s):
		print(-1)
	elif ispalindrome(s):
		for g in range(len(s)):
			if s[g] != s[0]:
				print(s[g] + s[1:g] + s[0] + s[g + 1:])
				break
	else:
		print(s)


t = int(input())

def process(str_in):
	(i1, ic2) = (0, 0)
	(i1, i2) = (len(str_in) // 2 - 1, len(str_in) // 2)
	ic1 = i2
	if len(str_in) % 2 == 1:
		ic1 = i2
		i2 += 1
	while i2 < len(str_in):
		if str_in[i1] != str_in[i2]:
			return str_in
		if str_in[i2] != str_in[ic1]:
			return str_in[:ic1] + str_in[i2] + str_in[ic1 + 1:i2] + str_in[ic1] + str_in[i2 + 1:]
		i2 += 1
		i1 -= 1
	return -1
for i in range(t):
	print(process(input()))


chars = 'abcdefghijklmnopqrstuvwxyz'
mapping = {}
for (i, char) in enumerate(chars):
	mapping[char] = i

def main():
	s = input()
	count = [0] * 26
	for char in s:
		count[mapping[char]] += 1
	if len(s) in count:
		print('-1')
		return
	res = ''
	for (key, val) in mapping.items():
		res += key * count[val]
	print(res)
for _ in range(int(input())):
	main()


n = int(input())
while n > 0:
	string = input()
	string = sorted(string)
	if string[0] == string[-1]:
		print('-1')
	else:
		print(''.join((c for c in string)))
	n -= 1


for _ in range(int(input())):
	s = input()
	s = [i for i in s]
	if s != s[::-1]:
		print(''.join(s))
	elif s.count(s[0]) == len(s):
		print(-1)
	else:
		j = 0
		for i in range(len(s)):
			if s[i] != s[0]:
				j = i
				break
		(s[0], s[j]) = (s[j], s[0])
		print(''.join(s))


from collections import Counter
num = int(input())
for i in range(num):
	a = input()
	if len(set(a)) == 1:
		print('-1')
	else:
		st = ''
		c = Counter(a)
		for i in c:
			st += i * c[i]
		print(st)


t = int(input())
for i in range(t):
	n = list(input())
	n.sort()
	a = n[::-1]
	if n == a:
		print(-1)
	else:
		print(''.join(n))


for i in range(int(input())):
	sa = [k for k in input()]
	for s in sa:
		if sa.count(s) >= len(sa):
			print(-1)
			break
		else:
			sa.sort()
			print(''.join(sa))
			break


import sys

def is_palindromes(string):
	good = True
	for k in range(len(string) // 2):
		if string[k] != string[-(k + 1)]:
			good = False
			break
	return good

def rearrange(i, j, string):
	(string[i], string[j]) = (string[j], string[i])
	return string
for _ in range(int(sys.stdin.readline())):
	string = list(sys.stdin.readline().rstrip())
	is_good = False
	for i in range(len(string) - 1):
		re_string = rearrange(i, i + 1, string)
		if not is_palindromes(re_string):
			is_good = True
			print(''.join(re_string))
			break
	if not is_good:
		print(-1)


n = int(input())

def check_(string):
	s = string[0]
	for i in range(len(string)):
		if string[i] != string[-1 - i]:
			return string
		if string[i] != s:
			return string[i] + string[1:i] + s + string[i + 1:]
	return -1
for i in range(n):
	print(check_(input()))


t = int(input())
for i in range(t):
	s = input()
	st = sorted(s)
	if st[0] == st[len(st) - 1]:
		print(-1)
	else:
		print(''.join(st))


t = int(input())
for _ in range(t):
	s = list(input())
	if len(set(s)) == 1:
		print(-1)
		continue
	flag = True
	for i in range(len(s)):
		if s[i] != s[len(s) - i - 1]:
			flag = False
			break
	if flag:
		l = list(set(s))
		i = s.index(l[0])
		j = s.index(l[1])
		(s[i], s[j]) = (s[j], s[i])
	print(''.join(s))


def main():
	n = int(input())
	for i in range(n):
		palind = True
		s = ''.join(sorted(input()))
		for j in range(1, len(s)):
			if s[j] != s[j - 1]:
				palind = False
		print('-1' if palind else s)
main()


t = int(input())
s = []
for i in range(t):
	k = input()
	s.append(sorted(k))
for i in s:
	if i[0] == i[-1]:
		print(-1)
	else:
		for j in i:
			print(j, end='')
		print('\t')


import math

def palindrome(s):
	l = len(s)
	for i in range(l // 2):
		if s[i] != s[l - i - 1]:
			return False
	return True
for _ in range(int(input())):
	n = sorted(input())
	if palindrome(n):
		print(-1)
	else:
		for i in n:
			print(i, end='')
		print('')


for _ in range(int(input())):
	s = input()
	d = {}
	for i in range(97, 123):
		d[chr(i)] = 0
	if len(set(s)) == 1:
		print(-1)
		continue
	if s == s[::-1]:
		temp = ''
		for i in range(len(s)):
			a = s[i]
			d[a] += 1
		for i in range(97, 123):
			a = chr(i)
			for j in range(d[a]):
				temp += a
		print(temp)
	else:
		print(s)


import sys, math
t = int(sys.stdin.readline())
for i in range(t):
	mot = sys.stdin.readline().replace('\n', '')
	ok = False
	for lettre in mot:
		if lettre != mot[0]:
			ok = True
			break
	if not ok:
		print(-1)
	palindrome = True
	for a in range(len(mot)):
		if mot[a] != mot[len(mot) - 1 - a]:
			palindrome = False
			break
	if not palindrome and ok:
		print(mot)
	elif palindrome and ok:
		indice = 0
		for l in range(len(mot)):
			if mot[l] != mot[0]:
				indice = l
				break
		print(mot[indice], end='')
		for l in range(1, len(mot)):
			if l == indice:
				print(mot[0], end='')
			else:
				print(mot[l], end='')
		print()


from collections import defaultdict
for _ in range(int(input())):
	s = list(input())
	unq = dict()
	(i, j) = (0, len(s) - 1)
	palindrome = True
	while j >= i:
		(unq[s[i]], unq[s[j]]) = (i, j)
		if s[i] == s[j]:
			(j, i) = (j - 1, i + 1)
		else:
			palindrome = False
			break
	if not palindrome:
		print(''.join(s))
	elif len(unq) == 1:
		print(-1)
	else:
		(a, b) = tuple(unq.keys())[:2]
		(s[unq[a]], s[unq[b]]) = (b, a)
		print(''.join(s))


t = int(input())
for q in range(t):
	s = input()
	l = len(s)
	if s.replace(s[0], '') == '':
		print('-1')
		continue
	if s == s[::-1]:
		while s == s[::-1]:
			s = s[l - 1] + s[:l - 1]
		print(s)
	else:
		print(s)


for _ in range(int(input())):
	n = input()
	if n != n[::-1]:
		print(n)
	elif len(n) == 1:
		print(-1)
	elif all((x == n[0] for x in n)):
		print(-1)
	elif n == n[::-1] and len(n) > 2:
		print(n[1:] + n[0])


def good_string(string):
	if string[::-1] != string:
		return string
	else:
		string = string[-1] + string[:-1]
		try:
			return good_string(string)
		except:
			return -1
queries = int(input())
for _ in range(queries):
	string = input()
	print(good_string(string))


t = int(input())
for i in range(t):
	s = input()
	pr = s[0]
	f = False
	for j in range(1, len(s)):
		if s[j] != pr:
			f = True
			break
	if f:
		print(''.join(sorted(s)))
	else:
		print(-1)


def isPalindrome(s):
	if s.count(s[0]) == len(s):
		return -1
	else:
		for j in range(0, len(s) // 2):
			if s[j] != s[len(s) - 1 - j]:
				return ''.join(s)
		for j in range(1, len(s) // 2 + 1):
			if s[j] != s[j - 1]:
				t = s[j]
				s[j] = s[j - 1]
				s[j - 1] = t
				return ''.join(s)
t = int(input())
for i in range(t):
	s = list(input())
	print(isPalindrome(s))


for _ in range(int(input())):
	i = ''.join(sorted(input()))
	print(-1) if len(set(i)) == 1 else print(i)


def reverse(s):
	return s[::-1]

def isPalindrome(s):
	rev = reverse(s)
	if s == rev:
		return True
	return False
t = int(input())
for _ in range(t):
	s = input()
	if isPalindrome(s):
		if len(set(list(s))) == 1:
			print(-1)
		else:
			a = s[0]
			s = list(s)
			for i in range(1, len(s)):
				if s[i] != a:
					s[0] = s[i]
					s[i] = a
					break
			print(''.join(s))
	else:
		print(s)


for i in range(int(input())):
	s = list(input())
	l = len(s)
	flag = 0
	b_i = 0
	for i in range(1, l):
		if s[i] != s[0]:
			b_i = i
			flag = 1
			break
	if flag == 0:
		print('-1')
		continue
	i = 0
	j = l - 1
	while i < l // 2:
		if s[i] != s[j]:
			flag = 0
			break
		i += 1
		j -= 1
	if flag == 0:
		print(''.join(s))
	else:
		t = s[0]
		s[0] = s[b_i]
		s[b_i] = t
		print(''.join(s))


n = int(input())
for _ in range(n):
	s = input()
	if len(set(s)) == 1:
		print('-1')
	else:
		print(''.join(sorted(s)))


n = int(input())
for i in range(n):
	x = input()
	if x != x[::-1]:
		print(x)
	else:
		d = ''.join(sorted(x))
		if d == x:
			print(-1)
		elif d != x:
			print(d)


for i in range(int(input())):
	a = input()
	a = list(a)
	cnt = len(set(a))
	if cnt == 1:
		print(-1)
	else:
		a.sort()
		for j in a:
			print(str(j), end='')
	print()


def solve():
	for _ in range(int(input())):
		s = input()
		if s != s[::-1]:
			print(s)
			continue
		if len(set(s)) == 1:
			print(-1)
			continue
		li = list(s)
		for i in range(1, len(li)):
			if li[i] != li[i - 1]:
				(li[i], li[i - 1]) = (li[i - 1], li[i])
				break
		print(''.join((k for k in li)))
solve()


def perestanovka(lst):
	a = list()
	for elem in lst:
		if sorted(elem)[0] == sorted(elem)[len(elem) - 1]:
			a.append(-1)
		else:
			a.append(''.join(sorted(elem)))
	return a
n = int(input())
b = list()
for i in range(n):
	s = input()
	b.append(s)
print(*perestanovka(b), sep='\n')


def solve():
	s = input()
	a = s[::-1]
	if s != a:
		print(s)
	else:
		st = set(s)
		if len(st) == 1:
			print(-1)
		elif len(st) == 2 and len(s) == 2:
			print(-1)
		else:
			l = list(s)
			for i in range(0, len(l)):
				if l[i] != l[len(l) - 1]:
					(l[i], l[len(l) - 1]) = (l[len(l) - 1], l[i])
					break
			sx = ''
			for i in l:
				sx += str(i)
			print(sx)
n = int(input())
while n != 0:
	solve()
	n -= 1


def solve(st):
	if st != st[::-1]:
		return st
	else:
		st = sorted(st)
		if st == st[::-1]:
			return -1
		else:
			return ''.join(st)
for _ in range(int(input())):
	print(solve(input()))


t = int(input())
for j in range(t):
	s = input()
	a = [i for i in s]
	m = []
	for i in range(len(a) - 1, -1, -1):
		m.append(a[i])
	b = [i for i in set(a)]
	if m != a:
		print(s)
	elif len(b) >= 2:
		i = a.index(b[0])
		j = a.index(b[1])
		(a[i], a[j]) = (a[j], a[i])
		print(''.join(a))
	else:
		print(-1)


def palindrone(s):
	l = len(s)
	count = 0
	for i in range(l):
		if s[i] == s[l - i - 1]:
			count += 1
	if count == l:
		return 1
	else:
		return 0
t = int(input())
for z in range(t):
	s = input()
	if s.replace(s[0], '') == '':
		print(-1)
	elif palindrone(s):
		for i in range(1, len(s) // 2 + 2):
			if s[0] != s[i]:
				s = s[i] + s[:i] + s[i + 1:]
				print(s)
				break
	else:
		print(s)


def func(s):
	if len(set(list(s))) == 1:
		return '-1'
	s = list(s)
	s.sort()
	return ''.join(s)
t = int(input())
t_input = [input() for i in range(t)]
for i in list(map(func, t_input)):
	print(i)


from collections import deque
n = int(input())
for i in range(n):
	X = input()
	if X.count(X[0]) == len(X):
		print(-1)
	elif X == ''.join(reversed(X)):
		Y = deque(X)
		Y.appendleft(Y.pop())
		print(*list(Y), sep='')
	else:
		print(X)


a = [input() for i in range(int(input()))]
b = []
for i in a:
	if i.count(i[0]) == len(i):
		b.append('-1')
	elif i == i[-1::-1]:
		i = i[0] + i[-1] + i[1:-1]
		b.append('%s' % i)
	else:
		b.append('%s' % i)
for i in b:
	print(i)


n = int(input())
for i in range(n):
	t = ''.join(sorted(input()))
	print([-1, t][len(set(t)) > 1])


def swap(s, i, j):
	tmp = s[i]
	s[i] = s[j]
	s[j] = tmp
	return s

def main(s):
	n = len(s)
	if s.count(s[0]) == n:
		return [str(-1)]
	synm = True
	elm1 = s[0]
	for i in range(0, n // 2 + 1):
		if s[i] != s[-(i + 1)]:
			synm = False
			return s
		if s[i] != elm1:
			out_s = swap(s, 0, i)
			break
	return out_s
t = int(input())
for i in range(t):
	s = list(input())
	out = main(s)
	print(''.join(out))


def isPalindrome(string):
	for i in range(len(string) // 2):
		if string[i] != string[-(i + 1)]:
			return False
	return True

def run(string):
	if string == len(string) * string[0]:
		return -1
	string = list(string)
	for i in range(len(string)):
		for j in range(len(string)):
			if i == j or string[i] == string[j]:
				pass
			else:
				sj = string[j]
				si = string[i]
				inter = string
				inter[j] = si
				inter[i] = sj
				if not isPalindrome(inter):
					return ''.join(inter)
	return -1
i = int(input())
for _ in range(i):
	string = input()
	print(run(string))


t = int(input())
while t:
	z = list(input())
	z.sort()
	z = ''.join(z)
	if z == z[::-1]:
		print(-1)
	else:
		print(z)
	t -= 1


import math

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

def good_str(s):
	if not is_palindrom(s):
		return s
	cur_sym = s[0]
	diff_sym = None
	for (i, sym) in enumerate(s[1:], start=1):
		if sym != cur_sym:
			return sym + s[1:i] + cur_sym + s[i + 1:]
	return -1
n = int(input())
for _ in range(n):
	s = input()
	print(good_str(s))


try:
	for _ in range(int(input())):
		s = input()
		L = len(s)
		x = set(s)
		d = dict()
		for v in s:
			if v in d:
				d[v] += 1
			else:
				d[v] = 1
		if len(x) < 2:
			print('-1')
		elif L % 2 == 0:
			if s[:L // 2] == s[L - 1:L // 2 - 1:-1]:
				Ans = []
				for v in d:
					Ans.append(v * d[v])
				print(''.join(Ans))
			else:
				print(s)
		elif s[:L // 2] == s[L - 1:L // 2:-1]:
			Ans = []
			for v in d:
				Ans.append(v * d[v])
			print(''.join(Ans))
		else:
			print(s)
except:
	pass


def check(s):
	if s[0] == s[-1]:
		check(s[1:])
	else:
		return 0
t = int(input())
for i in range(t):
	s = input()
	temp = s[0]
	c = 0
	for j in range(1, len(s)):
		if s[j] != temp:
			c = 1
			break
	if c == 1:
		x = 1
		x = check(s)
		if x == 0:
			print(s)
		else:
			for j in range(1, len(s)):
				if s[j] != temp:
					temp2 = s[j]
					y = int(j)
					break
			a = ''
			a = a + temp2
			a = a + s[1:y]
			a = a + temp
			a = a + s[y + 1:len(s)]
			print(a)
	else:
		print('-1')


import sys
t = int(sys.stdin.readline())
for i in range(t):
	cur = sys.stdin.readline().strip()
	all_same = True
	for i in range(1, len(cur)):
		if cur[i] != cur[i - 1]:
			all_same = False
			break
	if all_same == True:
		print(-1)
		continue
	chars = list(cur)
	chars.sort()
	print(''.join(chars))


for i in range(int(input())):
	s = list(map(str, input()))
	if len(dict.fromkeys(s)) == 1:
		print('-1')
	elif s == s[::-1]:
		print(''.join(sorted(s)))
	else:
		print(''.join(s))


t = int(input())
for q in range(t):
	a = input()
	s = set(a)
	if len(s) == 1:
		print(-1)
		continue
	sa = sorted(a)
	for i in sa:
		print(i, end='')
	print()


def letters_rearranging_problem():
	t = int(input())
	while t != 0:
		t -= 1
		s = input()
		new_s_list = sorted(s)
		new_s = ''
		for (i, _) in enumerate(new_s_list):
			new_s += new_s_list[i]
		if new_s[0] == new_s[-1]:
			print('-1')
		else:
			print(new_s)
	return
letters_rearranging_problem()


def myfn(strp):
	x = len(strp)
	bool = True
	l = [strp[i] for i in range(len(strp))]
	for i in range(int(x / 2) + 1):
		if l[i] != l[x - 1 - i]:
			bool = False
			break
		elif l[i] != l[0]:
			temp = l[0]
			l[0] = l[i]
			l[i] = temp
			bool = False
			break
	if bool == False:
		print(''.join((str(i) for i in l)))
	else:
		print('-1')
for t in range(int(input())):
	st = input()
	myfn(st)


for i in range(int(input())):
	s = input()
	if s == s[::-1]:
		k = set(s)
		if len(k) == 1:
			print(-1)
		else:
			for i in k:
				print(i * s.count(i), end='')
			print()
	else:
		print(s)


t = int(input())
for T in range(t):
	s = input()
	ss = list(s)
	ss.sort()
	l = len(ss)
	if ss[0] == ss[l - 1]:
		print(-1)
	else:
		for i in range(l):
			print(ss[i], end='')
		print('')


n = int(input())
for i in range(n):
	a = str(input())
	if len(set(a)) == 1:
		print(-1)
	elif a == a[::-1]:
		e = ''
		a = sorted(a)
		for j in range(0, len(a)):
			e = e + a[j]
		print(e)
	else:
		print(a)


t = int(input())
for i in range(0, t):
	n = input()
	n = sorted(n)
	if n[0] == n[len(n) - 1]:
		print('-1')
	else:
		for j in range(0, len(n)):
			print(n[j], end='')
		print()


n = int(input())
for i in range(0, n):
	c = input()
	if c.count(c[0]) == len(c):
		print(-1)
	elif c == c[::-1]:
		t = list(c)
		k = len(c) // 2
		j = k
		while t[j] == t[k]:
			j += 1
		(t[k], t[j]) = (t[j], t[k])
		c = ''.join(t)
		print(c)
	else:
		print(c)


import sys
input = sys.stdin.readline
from collections import defaultdict as dc
from collections import Counter
from bisect import bisect_right, bisect_left
import math
from operator import itemgetter
from heapq import heapify, heappop, heappush
from queue import PriorityQueue as pq
for _ in range(int(input())):
	s = input()[:-1]
	if len(set(s)) == 1:
		print(-1)
	else:
		print(''.join(sorted(s)))


ans = []
for _ in range(int(input())):
	s = list(input())
	if len(set(s)) != 1:
		if len(s) % 2:
			if s[0:int((len(s) - 1) / 2)] != s[int((len(s) - 1) / 2) + 1:][::-1]:
				ans.append(''.join(s))
			else:
				for i in range(1, len(s)):
					if s[0] != s[i]:
						(s[0], s[i]) = (s[i], s[0])
						break
				ans.append(''.join(s))
		elif s[0:int(len(s) / 2)] != s[int(len(s) / 2):][::-1]:
			ans.append(''.join(s))
		else:
			for i in range(1, len(s)):
				if s[0] != s[i]:
					(s[0], s[i]) = (s[i], s[0])
					break
			ans.append(''.join(s))
	else:
		ans.append('-1')
for i in ans:
	print(i)


def ispalindrome(ar):
	for i in range(0, len(ar) // 2):
		if ar[i] != ar[len(ar) - i - 1]:
			return 0
	return 1
x = int(input())
for i in range(0, x):
	n = input()
	ar = []
	s = ''
	for j in n:
		ar.append(j)
	if ispalindrome(ar) == 1:
		if ar.count(ar[0]) == len(ar):
			print('-1')
		else:
			ar.sort()
			print(s.join(ar))
	else:
		print(n)


for i in range(int(input())):
	s = list(input())
	if s != s[::-1]:
		print(''.join(s))
	else:
		ok = False
		for i in range(len(s) - 1):
			if s[i] != s[i + 1]:
				(s[i], s[i + 1]) = (s[i + 1], s[i])
				ok = True
				break
		if ok:
			print(''.join(s))
		else:
			print(-1)


t = int(input())
for i in range(t):
	s = input()
	if s != s[::-1]:
		print(s)
	else:
		s = s[len(s) // 2] + s[:len(s) // 2] + s[len(s) // 2 + 1:]
		if s != s[::-1]:
			print(s)
		else:
			print('-1')


def rearrange(words):
	ans = []
	for word in words:
		word = sorted(word)
		word = str(''.join(word))
		if word[0] == word[-1]:
			ans.append('-1')
		else:
			ans.append(word)
	return ans
n = int(input())
words = []
for i in range(n):
	word = input()
	words.append(word)
ans = rearrange(words)
for i in ans:
	print(i)


from sys import stdin

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

def readInt():
	return int(readLine())

def readInts():
	return list(map(int, readLine().split()))
(T, S) = (0, None)

def main():
	global T, S
	T = readInt()
	for i in range(T):
		S = list(readLine())
		n = len(S)
		isImpossible = all((S[i] == S[0] for i in range(n)))
		if isImpossible:
			print('-1')
		else:
			while True:
				if S != S[::-1]:
					print(''.join(S))
					break
				else:
					for j in range(1, n):
						if S[j] != S[0]:
							(S[0], S[j]) = (S[j], S[0])
							break
main()


def main():
	n = int(input())
	for i in range(n):
		dd = input()
		if len(set([c for c in dd])) == 1:
			print(-1)
		else:
			d = [c for c in dd]
			if d[0] == d[-1]:
				for i in range(1, len(d)):
					if d[i] != d[0]:
						t = d[i]
						d[i] = d[-1]
						d[-1] = t
						break
			print(''.join(d))
main()


for _ in [0] * int(input()):
	s = sorted(input())
	print((-1, ''.join(s))[s[0] < s[-1]])


def letters(s):
	x = sorted(s)
	if x == x[::-1]:
		return -1
	return ''.join(x)
t = int(input())
for i in range(t):
	s = input()
	print(letters(s))


from collections import Counter
t = int(input())
s = ''
m = ''
while t > 0:
	s = input()
	mydict = Counter(s)
	if len([*mydict]) == 1:
		print(-1)
	elif len([*mydict]) == 2:
		for (i, j) in mydict.items():
			m = m + i * j
		if m == m[::-1]:
			print(-1)
		else:
			print(m)
	else:
		for (i, j) in mydict.items():
			m = m + i * j
		print(m)
	m = ''
	t = t - 1


for i in range(int(input())):
	s = input()
	s1 = sorted(s)
	rev = s1[::-1]
	if len(set(s)) == 1 or s1 == rev:
		print(-1)
		continue
	ans = ''.join(s1)
	print(ans)


import sys
sys.setrecursionlimit(2000)
from collections import Counter

def is_palindrome(s):
	for i in range(len(s) // 2):
		if s[i] != s[len(s) - 1 - i]:
			return False
	return True
t = [int(val) for val in input().split()][0]
for test in range(t):
	a = [str(val) for val in input()]
	c = Counter(a)
	s = ''
	for (key, val) in c.items():
		s += key * val
	pos = is_palindrome(s)
	if pos:
		print(-1)
	else:
		print(s)


def check(s):
	i = 0
	j = len(s) - 1
	while i < j:
		if s[i] != s[j]:
			return False
		i += 1
		j -= 1
	return True
t = int(input())
for i in range(t):
	r = 0
	s = list(input())
	if check(s):
		d = list(set(s))
		if len(d) > 1:
			k = s[1:]
			k += s[0]
			s = k
		else:
			r = 1
			print(-1)
	if r == 0:
		print(''.join(s))


for _ in range(int(input())):
	s = input()
	if len(set(s)) == 1:
		print(-1)
	elif s == s[::-1]:
		temp = list(s)
		f = 0
		for i in range(len(temp)):
			for j in range(i + 1, len(temp)):
				if temp[i] != temp[j]:
					f = 1
					(temp[i], temp[j]) = (temp[j], temp[i])
					break
			if f == 1:
				break
		print(''.join(temp))
	else:
		print(s)


T = int(input())
solutions = []

def palindrome(string):
	if string == '' or len(string) == 1:
		return True
	elif string[0] == string[len(string) - 1]:
		return palindrome(string[1:len(string) - 1])
	else:
		return False

def allSame(string):
	x = string[0]
	for i in range(len(string)):
		if x != string[i]:
			return False
	return True

def rearrange(string):
	x = sorted(string)
	z = ''.join(x)
	return z
while T > 0:
	s = input()
	if palindrome(s):
		if allSame(s):
			solutions.append(-1)
		else:
			solutions.append(rearrange(s))
	else:
		solutions.append(s)
	T = T - 1
for x in solutions:
	print(x)


n = int(input())
for item in range(n):
	o = 0
	s = input()
	for i in range(len(s) // 2):
		if s[i] != s[-(i + 1)]:
			o = 1
			print(s)
			break
	if o == 0:
		if len(set(list(s))) == 1:
			print(-1)
		else:
			for item in range(1, len(s)):
				if s[item] != s[0]:
					s_ = s[item] + s[1:item] + s[0] + s[item + 1:]
					print(s_)
					break


def isgood(ss):
	for i in range(len(ss)):
		if i >= len(ss) - 1 - i:
			break
		if ss[i] != ss[len(ss) - 1 - i]:
			return False
	return True

def allsame(ss):
	s = ss[0]
	for i in range(len(ss)):
		if s != ss[i]:
			return False
	return True
t = int(input())
a = -1
for i in range(t):
	s = ''
	ss = input()
	if not isgood(ss):
		print(ss)
	elif allsame(ss):
		print(str(a))
	else:
		for i in range(1, len(ss)):
			s += ss[i]
		s += ss[0]
		print(s)


for t in range(int(input())):
	s = list(input())
	s.sort()
	if s == s[::-1]:
		print(-1)
	else:
		print(*s, sep='')


import math, sys

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

def main():
	n = int(input())
	for i in range(n):
		a = list(input().strip())
		a.sort()
		if a[0] == a[-1]:
			print(-1)
		else:
			print(''.join(a))
deb = 0
if deb:
	file = open('input.txt', 'w')
else:
	input = sys.stdin.readline
main()


t = int(input())
for _ in range(t):
	s = input()
	if s == s[::-1]:
		if len(set(s)) == 1:
			print(-1)
		else:
			got = False
			baruaja = False
			for i in range(len(s)):
				if not got and s[i] != s[i + 1]:
					print(s[i + 1], end='')
					got = True
					baruaja = True
				elif baruaja:
					print(s[i - 1], end='')
					baruaja = False
				else:
					print(s[i], end='')
			print()
	else:
		print(s)


import random

def ispallindrome(s):
	f = True
	l = int(len(s) / 2)
	for i in range(l):
		if s[i] != s[i * -1 - 1]:
			f = False
			break
	return f

def canbeconverted(s):
	fl = False
	if len(s) > 1:
		for ch in s:
			if s[0] != ch:
				fl = True
				break
	return fl

def randstring(s):
	list1 = list(s)
	random.shuffle(list1)
	s1 = ''
	for c in list1:
		s1 = s1 + c
	return s1
listofstrings = []
outputlist = []
t = int(input())
for i in range(t):
	listofstrings.append(input())
for str in listofstrings:
	if ispallindrome(str):
		if canbeconverted(str):
			str1 = str
			while ispallindrome(str1):
				str1 = randstring(str)
			outputlist.append(str1)
		else:
			outputlist.append(-1)
	else:
		outputlist.append(str)
for e in outputlist:
	print(e)


t = int(input())
for f in range(t):
	s = input()
	first = s[0]
	flag = False
	arr = []
	for i in range(26):
		arr.append(0)
	for i in range(len(s)):
		if s[i] != s[0]:
			flag = True
		val = ord(s[i]) - 97
		arr[val] += 1
	if flag == False:
		print(-1)
	else:
		ans = ''
		for i in range(26):
			val = arr[i]
			for j in range(val):
				ans += chr(i + 97)
		print(ans)


def pal(a):
	for i in range(len(a) // 2):
		if a[i] != a[len(a) - i - 1]:
			return False
			break
	return True

def terma(a):
	b = a[0]
	for i in a:
		if i != b:
			return True
			break
	return False
a = int(input())
l = []
for i in range(a):
	b = input()
	l.append(b)
for i in l:
	if not pal(i):
		print(i)
	elif terma(i) == False:
		print(-1)
	else:
		b = i[0]
		for a in range(len(i)):
			if b != i[a]:
				s = a
				print(i[a] + i[1:s] + b + i[s + 1:len(i)])
				break


def main():
	t = int(input())
	for i in range(t):
		cnt = {'a': 0, 'b': 0, 'c': 0, 'd': 0, 'e': 0, 'f': 0, 'g': 0, 'h': 0, 'i': 0, 'j': 0, 'k': 0, 'l': 0, 'm': 0, 'n': 0, 'o': 0, 'p': 0, 'q': 0, 'r': 0, 's': 0, 't': 0, 'u': 0, 'v': 0, 'w': 0, 'x': 0, 'y': 0, 'z': 0}
		s = input()
		n = len(s)
		for ch in s:
			cnt[ch] += 1
		letters = 0
		for ch in cnt:
			if cnt[ch] > 0:
				letters += 1
		if letters == 1:
			print(-1)
		else:
			ans = ''
			s = sorted(s)
			for ch in s:
				ans += ch
			print(ans)
main()


from collections import Counter
t = int(input())
for i in range(t):
	s = input().strip()
	ctr = Counter(list(s))
	if len(ctr) == 1:
		print(-1)
	else:
		t = ''
		for a in ctr:
			t += a * ctr[a]
		print(t)


t = int(input())
M = []

def fonction(s):
	if len(set(s)) == 1:
		return -1
	else:
		return ''.join(sorted(s))
for i in range(t):
	M.append(fonction(input()))
for k in M:
	print(k)


tc = int(input())
tc += 1
while tc - 1:
	tc -= 1
	x = str(input())
	bol = True
	for i in range(1, len(x), 1):
		if x[i] != x[0]:
			bol = False
	if bol:
		print(-1)
	else:
		x = ''.join(sorted(x))
		print(x)


def swap(list, pos1, pos2):
	(list[pos1], list[pos2]) = (list[pos2], list[pos1])
	return list
t = int(input())
for i in range(t):
	n = list(input())
	if n.count(n[0]) == len(n):
		print(-1)
	elif len(n) == 1:
		print(-1)
	else:
		for j in range(len(n) - 1):
			if n[j] != n[j + 1] and n[j] == n[len(n) - j - 1] and (j != len(n) - j - 1):
				swap(n, j, j + 1)
		print(*n, sep='')


n = int(input())
for i in range(n):
	arr = list(input())
	if len(set(arr)) == 1:
		print(-1)
	else:
		arr.sort()
		print(*arr, sep='')


t = int(input())
result = []
for i in range(t):
	s = list(input())
	length = len(s)
	same = 1
	good = 1
	for j in range(length):
		if s[j] != s[0]:
			same = 0
			index = j
			break
	if same == 1:
		result.append('-1')
	else:
		for j in range(length):
			if s[j] != s[length - 1 - j]:
				good = 0
				break
		if good == 1:
			(s[0], s[index]) = (s[index], s[0])
		string = ''
		for j in range(length):
			string += s[j]
		result.append(string)
for i in range(t):
	print(result[i])


from collections import Counter
n = int(input())
for i in range(n):
	string = input()
	cnt = Counter(string)
	if len(cnt) == 1:
		print(-1)
	else:
		print(''.join(sorted(string)))


for _ in range(int(input())):
	inp = ''.join(sorted(input()))
	if inp[0] == inp[-1]:
		print(-1)
	else:
		print(inp)


n = int(input())
m = [input() for _ in range(n)]
sol = []

def rearr(s):
	t = s[0]
	m = ''
	for i in range(1, len(s)):
		if s[i] != t:
			m = s[i] + s[1:i] + t + s[i + 1:]
	return m
for i in m:
	if len(i) == 1 or i.count(i[0]) == len(i):
		sol.append(-1)
	else:
		le = len(i)
		for j in range(le):
			if i[j] != i[le - j - 1]:
				sol.append(i)
				break
			if j >= le - j - 1:
				sol.append(rearr(i))
				break
print(*sol, sep='\n')


def is_pal(n):
	return str(n) == str(n)[::-1]
t = int(input())
for i in range(t):
	s = input()
	if not is_pal(s):
		print(s)
	elif 1 == len(set(s)):
		print(-1)
	else:
		s = list(s)
		for j in range(len(s) - 1):
			if s[j + 1] != s[j]:
				(s[j + 1], s[j]) = (s[j], s[j + 1])
				break
		for j in s:
			print(j, end='')
		print()


t = int(input())
for _ in range(t):
	s = input()
	s = ''.join(sorted(s))
	n = len(s)
	is_pal = all((s[i] == s[n - i - 1] for i in range(n)))
	if is_pal:
		print(-1)
	else:
		print(s)


def pal(a):
	p = a[::-1]
	if p == a:
		return True
	else:
		return False
n = int(input())
for i in range(n):
	s = input()
	if s.count(s[0]) == len(s):
		print(-1)
	elif pal(s) == True:
		for j in range(len(s)):
			s = s + s[j]
			s = s.replace(s[j], '', 1)
			if pal(s) == False:
				break
		print(s)
	elif pal(s) == False:
		print(s)


def isPalindrome(word):
	return word == word[::-1]

def getGoodString(word):
	if not isPalindrome(word):
		return word
	if len(set(word)) == 1:
		return -1
	i = 0
	while word[i] == word[i + 1]:
		i += 1
	return word[:i] + word[i:i + 2][::-1] + word[i + 2:]
tc = int(input())
for i in range(tc):
	word = input()
	print(getGoodString(word))


t = int(input())
for i in range(t):
	s = list(input())
	l = len(s)
	ans = ''
	flag = -1
	ans = ''.join(s)
	if ans[::-1] != ans:
		print(ans)
		continue
	if l % 2 == 0:
		for j in range(1, l):
			if s[j] != s[j - 1]:
				flag = 0
				tm = s[j]
				s[j] = s[j - 1]
				s[j - 1] = tm
				break
	else:
		tmp = s[l // 2]
		for j in range(1, l):
			if s[j] != s[j - 1] and j != l // 2 and (j != l // 2 + 1):
				flag = 0
				tm = s[j]
				s[j] = s[j - 1]
				s[j - 1] = tm
				break
			elif s[j] != tmp and j != l // 2:
				s[l // 2] = s[j]
				s[j] = tmp
				break
	ans = ''.join(s)
	if ans[::-1] != ans:
		print(ans)
	else:
		print(-1)


def main():
	t = int(input())
	while t:
		s = list(input())
		s.sort()
		conjunto = set(s)
		print('-1' if len(conjunto) == 1 else ''.join(s))
		t -= 1
main()


for i in range(int(input())):
	s = list(input())
	if len(set(s)) < 2:
		print(-1)
	else:
		s.sort()
		print(''.join(s))


s = int(input())
for i in range(0, s):
	a = str(input())
	if len(a) == a.count(a[0]):
		print('-1')
	else:
		print(''.join(sorted(a)))


t = int(input())
for i in range(t):
	n = input()
	c = []
	count = 0
	for i in range(len(n)):
		c.insert(i, n[i])
	m = list(reversed(n))
	if c != m:
		print(n)
	else:
		for i in range(len(n) - 1):
			if n[i] == n[i + 1]:
				count += 1
		if count == len(n) - 1:
			print('-1')
		else:
			x = c[len(n) - 1]
			c.remove(c[len(n) - 1])
			c.append(x)
			for i in range(len(n)):
				print(c[i], end='')
			print()


t = int(input())
for i in range(t):
	s = input()
	if not s.count(s[0]) == len(s):
		if not s[0] == s[-1]:
			print(s)
			continue
		for j in range(len(s)):
			if not s[j] == s[0]:
				print(s[:j] + s[-1] + s[j + 1:-1] + s[j])
				break
	else:
		print(-1)


T = int(input())
for i in range(T):
	s = input()
	t = s[0]
	p = 0
	for (i, j) in enumerate(s):
		if j != t:
			p = i
			break
	if p == 0:
		print(-1)
	else:
		print(s[0] + s[1:p] + s[p + 1:] + s[p])


from sys import stdin, stdout
from collections import Counter
nmbr = lambda : int(input())
lst = lambda : list(map(int, input().split()))
for _ in range(nmbr()):
	s = input()
	n = len(s)
	p1 = p2 = -1
	p1 = 0
	ans = [0] * n
	for i in range(1, n):
		if s[i] != s[p1]:
			p2 = i
			break
	if p2 == -1:
		print(-1)
		continue
	pt = n // 2 - 1
	(ans[pt], ans[n - pt - 1]) = (s[p1], s[p2])
	p = 0
	for i in range(n):
		if p == p1:
			p += 1
		if p == p2:
			p += 1
		if i not in [pt, n - pt - 1]:
			ans[i] = s[p]
			p += 1
	print(''.join(ans))


for i in range(int(input())):
	s = ''.join(sorted(input()))
	print([s, -1][s[0] == s[-1]])


t = int(input())
for _ in range(t):
	s = input()
	arr = [i for i in s]
	arr.sort()
	if arr[0] == arr[-1]:
		print(-1)
	else:
		print(''.join(map(str, arr)))


N = input()
for i in range(int(N)):
	a = input()
	if len(set(a)) == 1:
		print(-1)
	else:
		print(''.join(sorted(a)))


a = int(input())
for x in range(a):
	kolb = 0
	y = input()
	bukv = y[0]
	for z in range(len(y)):
		if y[z] != bukv:
			kolb += 1
	if kolb == 0:
		print(-1)
	else:
		y = sorted(y)
		myString = ''.join(y)
		print(myString)


def is_palindrome(w):
	if len(w) % 2 == 0:
		for i in range(len(w) // 2):
			if w[i] != w[len(w) - i - 1]:
				return False
	else:
		for i in range(len(w) // 2):
			if w[i] != w[len(w) - i - 1]:
				return False
	return True

def easy_ransform(w):
	ls_w = list(w)
	idx = next((i for i in range(len(w)) if w[i] != w[0]))
	(ls_w[idx], ls_w[-1]) = (ls_w[-1], ls_w[idx])
	return ''.join(ls_w)
n_queries = int(input())
res = []
for i in range(n_queries):
	word = input()
	if len(set(word)) == 1:
		res.append(-1)
	elif not is_palindrome(word):
		res.append(word)
	else:
		res.append(easy_ransform(word))
for i in res:
	print(i)


from collections import Counter
for _ in range(int(input())):
	s = sorted(input())
	c = Counter(s)
	if len(c) == 1:
		print(-1)
	else:
		print(''.join(s))


n = int(input())
for count in range(n):
	x = input()
	do = {}
	for i in x:
		if i in do:
			do[i] = do[i] + 1
		else:
			do[i] = 1
	if len(do) == 1:
		print(str(-1))
	else:
		ans = ''
		for i in do:
			ans = ans + i * do[i]
		print(ans)


for t in range(int(input())):
	value = input()
	z = sorted([v for v in value])
	if z[0] == z[-1]:
		print(-1)
	else:
		print(''.join(z))


t = int(input())
for case in range(t):
	s = input()
	if len(set(list(s))) == 1:
		ans = -1
	else:
		l = list(s)
		n = len(l)
		for i in range(1, n):
			if l[i] != l[0]:
				(l[i], l[-1]) = (l[-1], l[i])
				break
		ans = ''.join(l)
	print(ans)


IL = lambda : list(map(int, input().split()))
n = int(input())
for i in range(n):
	s = input()
	if len(set(s)) == 1:
		print(-1)
	else:
		print(''.join(sorted(s)))


def pal(s):
	n = len(s)
	for i in range(int(len(s) / 2)):
		if i != n - i - 1 and s[i] != s[n - i - 1]:
			return False
	return True

def solve():
	rd = lambda : list(map(int, input().split()))
	n = int(input())
	for i in range(n):
		s = list(input())
		s.sort()
		if pal(s):
			print(-1)
		else:
			print(''.join(s))
solve()


import sys
from math import ceil, floor
input = sys.stdin.readline
t = int(input())
for zzz in range(t):
	s = list(input().strip())
	s.sort()
	i = 0
	j = len(s) - 1
	valid = True
	while i <= j:
		if s[i] != s[j]:
			valid = False
			break
		i += 1
		j -= 1
	if not valid:
		print(''.join([str(x) for x in s]))
	else:
		print(-1)


def polin(a):
	for i in range(len(a) // 2):
		if a[i] != a[len(a) - i - 1]:
			return 0
	return 1

def odin(a):
	for i in range(len(a)):
		if a[i] != a[0]:
			return 0
	return 1

def sobr(a):
	b = ''
	lst = list(a)
	lst.sort()
	for i in range(len(lst)):
		b += lst[i]
	return b
n = int(input())
for i in range(n):
	a = input()
	if polin(a) == 0:
		print(a)
	elif odin(a) == 1:
		print(-1)
	else:
		print(sobr(a))


t = int(input())
for test in range(t):
	n = list(input())
	n.sort()
	if len(set(n)) == 1:
		print(-1)
	else:
		print(''.join(n))


n = int(input())
for i in range(n):
	c = input()
	if c[0] * len(c) == c:
		print(-1)
	elif c[::-1] != c:
		print(c)
	else:
		l = [i for i in c]
		for i in range(1, len(l) // 2 + 1):
			if l[0] != l[i]:
				x = l[0]
				l[0] = l[i]
				l[i] = x
		print(''.join(l))


from sys import stdin
max_val = int(10000000000000.0)
min_val = int(-10000000000000.0)

def read_int():
	return int(stdin.readline())

def read_ints():
	return [int(x) for x in stdin.readline().split()]

def read_str():
	return input()

def read_strs():
	return [x for x in stdin.readline().split()]
nb_query = read_int()
for _ in range(nb_query):
	curr = input()
	if curr != curr[::-1]:
		print(curr)
	else:
		ans = ''.join(sorted(curr))
		if ans == curr:
			print(-1)
		else:
			print(ans)


t = int(input())
for j in range(t):
	s = input()
	a = ''
	for i in s:
		if i not in a:
			a = a + i
	if len(a) == 1:
		print(-1)
	elif s[::-1] != s:
		print(s)
	elif s[::-1] == s:
		L = []
		L1 = []
		for i in s:
			if i not in L:
				L.append(i)
				L1.append(1)
			else:
				f = L.index(i)
				L1[f] = L1[f] + 1
		a = ''
		for i in range(len(L)):
			a = a + L[i] * L1[i]
		print(a)


t = int(input())
for i in range(t):
	s = input()
	if s != s[::-1]:
		print(s)
	else:
		flag = True
		for j in range(len(s) - 1):
			if s[j] != s[j + 1]:
				flag = False
				break
		if flag == True:
			print('-1')
		else:
			l = list(s)
			for k in range(len(l) // 2 + 1):
				if l[k] != l[k + 1]:
					(l[k], l[k + 1]) = (l[k + 1], l[k])
					break
			s = ''
			for k in range(len(l)):
				s = s + l[k]
			print(s)


from collections import Counter
CASES = int(input())
for i in range(CASES):
	s = input()
	if len(Counter(s).keys()) == 1:
		print(-1)
	else:
		print(''.join(sorted(s)))


from sys import stdin, stdout
from itertools import combinations
from collections import defaultdict, OrderedDict
import math

def listIn():
	return list(map(int, stdin.readline().strip().split()))

def stringListIn():
	return [x for x in stdin.readline().split()]

def intIn():
	return int(stdin.readline())

def stringIn():
	return stdin.readline().strip()
t = intIn()
for i in range(t):
	s = stringIn()
	if s == s[::-1]:
		if len(set(s)) == 1:
			print(-1)
		else:
			print(''.join(sorted(s)))
	else:
		print(s)


for i in range(int(input())):
	print((lambda x: -1 if len(set(x)) == 1 else x if x != x[::-1] else ''.join(sorted(list(x))))(input()))


n = int(input())
for i in range(n):
	s = input()
	sset = set(s)
	if len(sset) == 1:
		print(-1)
	else:
		ssetFirst = list(sset)[0]
		count = s.count(ssetFirst)
		s = s.replace(ssetFirst, '')
		s = ssetFirst * count + s
		print(s)


t = int(input())
for i in range(t):
	a = str(input())
	t = len(a)
	b = a[:t // 2]
	if t % 2 == 0:
		m = a[t // 2:][::-1]
	else:
		m = a[t // 2 + 1:][::-1]
	if b != m:
		print(a)
	else:
		q = list(set(a))
		if len(q) == 1:
			print(-1)
		else:
			a1 = a.index(q[0])
			a2 = a.index(q[1])
			a = list(a)
			a[a1] = q[1]
			a[a2] = q[0]
			print(''.join(a))


from math import *
from random import shuffle
for i in range(int(input())):
	s = input()
	if all([i == s[0] for i in s]):
		print(-1)
	else:
		d = list(s)
		i = 0
		if d == d[::-1]:
			while i < len(d) - 1 and d[i] == d[i + 1]:
				i += 1
			(d[i], d[i + 1]) = (d[i + 1], d[i])
		print(''.join(d))


for i in range(int(input())):
	s = input()
	n = len(s)
	if s.count(s[:1]) == n:
		print('-1')
	else:
		s1 = sorted(list(s))
		print(''.join(s1))


n = int(input())
for i in range(n):
	s = input()
	rev = ''.join(reversed(s))
	if len(set(s)) == 1:
		print(-1)
	elif s != rev:
		print(s)
	else:
		print(''.join(sorted(s)))


for _ in range(int(input())):
	s = input().strip()
	if s == s[::-1] and len(set(s)) == 1:
		print(-1)
	elif s != s[::-1]:
		print(s)
	else:
		print(''.join(sorted(s)))


for _ in range(int(input())):
	str = input()
	if len(set(str)) == 1:
		print(-1)
		continue
	if str != str[::-1]:
		print(str)
	else:
		for i in range(len(str) - 1):
			if str[i] != str[i + 1]:
				temp1 = str[i]
				temp2 = str[i + 1]
				str = str[:i] + temp2 + temp1 + str[i + 2:]
				print(str)
				break


for i in range(int(input())):
	q = input()
	s = sorted(q)
	a = 0
	for i in range(len(s) - 1):
		if s[i] != s[i + 1]:
			a = 1
	if a == 0:
		print(-1)
	else:
		ans = ''
		for i in range(len(s)):
			ans += s[i]
		print(ans)


t = int(input())

def f(s):
	if s != s[::-1]:
		return s
	d = {}
	for i in s:
		if i not in d.keys():
			d[i] = 1
		else:
			d[i] += 1
	if len(d.keys()) == 1:
		return -1
	c = ''
	for i in d.keys():
		c += i * d[i]
	return c
for i in range(t):
	s = input()
	print(f(s))


t = int(input())
for i in range(t):
	s = str(input())
	a = len(s)

	def is_palindrome(s):
		for i in range(a // 2):
			if s[i] != s[a - i - 1]:
				return False
		return True
	if is_palindrome(s) and len(set(s)) != 1:
		print(''.join(sorted(s)))
	elif len(set(s)) == 1:
		print('-1')
	else:
		print(s)


for _ in range(int(input())):
	s = input()
	if list(reversed(s)) != list(s):
		print(s)
	elif len(list(set(list(s)))) == 1:
		print('-1')
	else:
		n = len(s)
		p = s[int(n / 2)]
		print(s[:int(n / 2)] + s[int(n / 2) + 1:] + s[int(n / 2)])


def has_distinct_alpha(word):
	alpha = word[0]
	for ch in word:
		if ch != alpha:
			return True
	return False

def get_good_string(word):
	if has_distinct_alpha(word):
		if word == word[::-1]:
			good_string = word[len(word) // 2 + 1:] + word[:len(word) // 2 + 1]
			return good_string
		else:
			return word
	else:
		return -1
n = int(input())
for i in range(n):
	print(get_good_string(input()))


for _ in range(int(input())):
	l = input()
	if len(set(l)) == 1:
		print(-1)
	elif l != l[::-1]:
		print(l)
	else:
		l = list(l)
		n = len(l)
		for i in range(n):
			if l[i] != l[n // 2]:
				break
		(l[i], l[n // 2]) = (l[n // 2], l[i])
		print(''.join(l))


n = int(input())
for i in range(n):
	s = input()
	s1 = list(s)
	if len(set(s1)) == 1:
		print(-1)
	else:
		s1.sort()
		print(''.join(s1))


def is_pal(s):
	for i in range(len(s)):
		if s[i] != s[-(i + 1)]:
			return False
	return True
t = int(input())
for tt in range(t):
	s = input()
	if is_pal(s):
		s0 = s[0]
		sw = 0
		for i in range(len(s)):
			if s[i] != s0:
				sw = i
				break
		if sw == 0:
			print(-1)
		else:
			sl = list(s)
			(sl[0], sl[sw]) = (sl[sw], sl[0])
			print(''.join(sl))
	else:
		print(s)


def pallindrome(s):
	x = len(s)
	y = x // 2
	for i in range(y):
		if s[i] != s[x - i - 1]:
			return False
	return True
for _ in range(int(input())):
	s = list(input())
	if len(set(s)) == 1:
		print('-1')
	elif not pallindrome(s):
		print(''.join(s))
	else:
		x = len(s) // 2
		for i in range(x):
			if s[i] != s[i + 1]:
				(s[i], s[i + 1]) = (s[i + 1], s[i])
				break
		print(''.join(s))


def palindrome(s):
	if s[::-1] == s:
		return 1
	else:
		return 0
a = int(input())
for i in range(1, a + 1):
	fin = 0
	x = input()
	if not palindrome(x):
		print(x)
	elif len(x) == 1 or len(x) == 2:
		print(-1)
	else:
		for i in range(len(x)):
			if x[0] != x[i]:
				m = list(x)
				d = m[0]
				m[0] = m[i]
				m[i] = d
				print(''.join(m))
				fin = 1
				break
		if fin != 1:
			print(-1)


def Rearranging(string):
	if len(set(string)) == 1:
		return '-1'
	elif string == string[::-1]:
		for j in range(len(string) // 2):
			newString = string[:j] + string[j + 1] + string[j] + string[j + 2:]
			if string != newString:
				return newString
	else:
		print(string)
for i in range(int(input())):
	string = input()
	if Rearranging(string) != None:
		print(Rearranging(string))


def check(arr):
	p = 1
	for i in range(len(arr)):
		if arr[0] != arr[i]:
			p = 0
			break
	return p
t = int(input())
for p in range(t):
	lst = list(str(input()))
	arr = lst[::-1]
	if lst != arr:
		for i in range(len(lst)):
			print(lst[i], end='')
		print()
	else:
		p = check(lst)
		if p == 1:
			print(-1)
		else:
			q = lst[0]
			for i in range(len(lst)):
				if lst[i] != q:
					l = i
					break
			(lst[0], lst[i]) = (lst[i], lst[0])
			for i in range(len(lst)):
				print(lst[i], end='')
			print()


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, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def update(bit, i):
	while i < len(bit):
		bit[i] += 1
		i += i & -i

def getsum(bit, i):
	res = 0
	while i > 0:
		res += bit[i]
		i -= i & -i
	return res
import math
for _ in range(int(input())):
	s = input()
	if sorted(s) == sorted(s)[::-1]:
		print(-1)
	else:
		print(''.join(sorted(s)))


from collections import Counter
from random import sample

def ans(arr):
	arr = sorted(arr)
	t = arr[::-1]
	if arr == t:
		return -1
	return ''.join(arr)
t = int(input())
for _ in range(t):
	s = input()
	print(ans(s))


n = int(input())
for x in range(n):
	s = input()
	s = ''.join(sorted(list(s)))
	if s == s[::-1]:
		print(-1)
	else:
		print(s)


def test(s):
	pal = False
	if s == s[::-1]:
		pal = True
	return pal

def test1(s):
	if test(s) == False:
		print(s)
		return
	flag = False
	for i in range(len(s) - 1):
		if s[i] != s[i + 1] and flag == False:
			m = list(s)
			(m[i], m[i + 1]) = (m[i + 1], m[i])
			if test(m) == False:
				for i in m:
					print(i, end='')
				flag = True
				print()
	if flag != True:
		print(-1)
n = int(input())
for i in range(n):
	s = input()
	test1(s)


def palindrom(s):
	for i in range(len(s)):
		if s[i] != s[-1 - i]:
			return 0
	return 1

def prints(s):
	for i in s:
		print(i, end='')
	print('')
t = int(input())
while t > 0:
	t -= 1
	s = list(input())
	s = sorted(s)
	if palindrom(s):
		print(-1)
	else:
		prints(s)


for _ in range(int(input())):
	string = input()
	t = 1
	j = 0
	for i in range(len(string) - 1):
		if string[i] == string[i + 1]:
			t += 1
		else:
			j = i + 1
			break
	if t == len(string):
		print('-1')
	else:
		k = 0
		for i in range(len(string) // 2):
			if string[i] == string[len(string) - 1 - i]:
				k += 2
		if len(string) % 2 == 0 and k == len(string):
			l = list(string)
			(l[0], l[j]) = (l[j], l[0])
			print(''.join((i for i in l)))
		elif len(string) % 2 == 1 and k == len(string) - 1:
			l = list(string)
			(l[0], l[j]) = (l[j], l[0])
			print(''.join((i for i in l)))
		else:
			print(string)


t = int(input())
for x in range(t):
	s = input()
	flag = s == s[::-1]
	if flag and s.count(s[0]) == len(s):
		print(-1)
	elif flag:
		f = s[0]
		for x in range(0, len(s)):
			if s[x] != f:
				print(s[:x - 1] + s[x] + s[x - 1] + s[x + 1:])
				break
	else:
		print(s)


for i in range(int(input())):
	y = input()
	if y == y[::-1]:
		p = len(y)
		if p != 0 and y != y[p // 2 + 1:p] + y[0:p // 2 + 1]:
			print(y[p // 2 + 1:p] + y[0:p // 2 + 1])
		else:
			print(-1)
	else:
		print(y)


n = int(input())
z = ''
for i in range(n):
	x = input()
	y = list(x)
	y.sort()
	z = z.join(y)
	if y.count(x[0]) == len(x):
		print(-1)
	else:
		print(z)
	y.clear()
	z = ''


n = int(input())
for i in range(n):
	s = input()
	f = [0] * 26
	for i in s:
		f[ord(i) - ord('a')] += 1
	mm = 0
	for i in f:
		mm = max(i, mm)
	if mm == len(s):
		print('-1')
		continue
	x = s[::-1]
	if x != s:
		print(s)
	else:
		s = sorted(s)
		for i in s:
			print(i, end='')
		print()


t = int(input())
for i in range(t):
	ok = False
	u = list(input())
	n = len(u)
	for i in range(n // 2):
		if u[i] != u[-i - 1]:
			print(''.join(u))
			ok = True
			break
	if ok:
		continue
	a = u[0]
	for i in range(1, n):
		if u[i] != a:
			(u[i - 1], u[i]) = (u[i], u[i - 1])
			print(''.join(u))
			ok = True
			break
	if not ok:
		print(-1)


import sys
import math

def scan(input_type='int'):
	return list(map(int, sys.stdin.readline().strip().split()))

def solution():
	for _ in range(int(input())):
		s = input()
		a = []
		for i in s:
			a.append(i)
		if len(set(a)) == 1:
			print(-1)
		else:
			a.sort()
			for i in a:
				print(i, end='')
			print()
solution()


def process_string(word):
	if word != word[::-1]:
		return word
	word = list(word)
	for i in range(len(word)):
		if word[i] != word[0]:
			(word[0], word[i]) = (word[i], word[0])
			return ''.join(word)
	return -1
n = int(input())
for _ in range(n):
	string = input()
	print(process_string(string))


number = int(input())
d_ict = {}
for i in range(number):
	d_ict[i] = list(input())
for i in range(number):
	new1 = sorted(d_ict[i])
	new2 = list(reversed(new1))
	if new1 == new2:
		print(-1)
	else:
		a = ''
		for j in range(len(new1)):
			a += new1[j]
		print(a)


import math
n = int(input())
queries = []
for i in range(n):
	queries.append(list(input()))
for i in queries:
	i.sort()
	if i[0] == i[-1]:
		print(-1)
	else:
		print(''.join(i))


n = int(input())
for i in range(n):
	x = input()
	r = x[::-1]
	if x == r:
		y = x[0]
		x = x.replace(x[0], '', 1)
		z = x + y
		new = z[::-1]
		if new == z:
			print('-1')
		else:
			print(x + y)
	else:
		print(x)


def func(string):
	bo = True
	for x in range(len(string) // 2):
		if string[x] != string[len(string) - 1 - x]:
			bo = False
			break
	if bo:
		bo = True
		for x in range(len(string) - 1):
			if string[x] != string[x + 1]:
				new = string[:x] + string[x + 1] + string[x] + string[x + 2:]
				print(new)
				bo = False
				break
		if bo:
			print(-1)
	else:
		print(string)

def main():
	n = int(input())
	for _ in range(n):
		func(input())
main()


num = int(input())
for i in range(num):
	string = sorted(input())
	if len(set(string)) == 1:
		print(-1)
	elif string == string[::-1]:
		print(''.join(sorted(string)))
	else:
		print(''.join(string))


import math, itertools, fractions, heapq, collections, bisect, sys, queue, copy
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def LS():
	return sys.stdin.readline().split()

def S():
	return input()

def isPalindrome(s):
	l1 = list(s)
	l2 = l1[::-1]
	if l1 == l2:
		return True
	return False

def main():
	n = I()
	ans = []
	for _ in range(n):
		x = list(S())
		x.sort()
		y = ''.join(x)
		if isPalindrome(y):
			ans.append(-1)
		else:
			ans.append(y)
	for x in ans:
		print(x)
main()


t = int(input())
while t > 0:
	s = input()
	ok = False
	c = s[0]
	for i in s:
		if i != c:
			ok = True
			break
	if ok:
		s = sorted(s)
		print(''.join(s))
	else:
		print(-1)
	t = t - 1


n = int(input())
for i in range(n):
	string = input()
	string1 = sorted(string)
	if string1 == string1[::-1]:
		print('-1')
		continue
	print(''.join(string1))


def is_palid(string):
	for i in range(len(string) // 2):
		if string[i] != string[-i - 1]:
			return False
	return True
amount = int(input())
for i in range(amount):
	string = input()
	if string == string[0] * len(string):
		print(-1)
	elif not is_palid(string):
		print(string)
	else:
		answer = ''
		flag = False
		for i in range(len(string)):
			for j in range(i + 1, len(string)):
				if string[i] != string[j]:
					answer += string[i]
					answer += string[:i]
					answer += string[i + 1:j]
					answer += string[j + 1:]
					answer += string[j]
					flag = True
					print(answer)
					break
			if flag:
				break


for _ in range(int(input())):
	a = input()
	s = [a[0]]
	r = []
	n = len(a)
	for i in range(1, n):
		if a[i] == s[0]:
			s += a[i]
		else:
			r += a[i]
	if not r:
		print(-1)
	else:
		print(*s + r, sep='')


t = int(input())
for i in range(t):
	s = input()
	c = {}
	for j in s:
		if j not in c:
			c[j] = 0
		c[j] += 1
	if len(c) == 1:
		print(-1)
	else:
		l = list(c.keys())
		first = l[0]
		last = l[-1]
		c[first] -= 1
		c[last] -= 1
		ans = first
		for k in l:
			ans += k * c[k]
		ans += last
		print(ans)


t = int(input())
for i in range(t):
	s = input()
	r = ''.join(sorted(list(s)))
	if r[0] == r[-1]:
		print(-1)
	else:
		print(r)


def a(l):
	return l[::-1]
t = int(input())
for i in range(t):
	s = input()
	s = list(s)
	if len(s) % 2 == 0:
		if s[:len(s) // 2] == a(s[len(s) // 2:]):
			y = 0
			for j in range(len(s) - 1):
				if s[j] != s[j + 1]:
					o = s[j]
					s[j] = s[j + 1]
					s[j + 1] = o
					y = 1
					for w in range(len(s)):
						print(s[w], end='')
					print('')
					break
			if y == 0:
				print('-1')
		else:
			for w in range(len(s)):
				print(s[w], end='')
			print('')
	elif s[:len(s) // 2] == a(s[len(s) // 2 + 1:]):
		y = 0
		for j in range(len(s) - 1):
			if s[j] != s[j + 1]:
				o = s[j]
				s[j] = s[j + 1]
				s[j + 1] = o
				y = 1
				for w in range(len(s)):
					print(s[w], end='')
				print('')
				break
		if y == 0:
			print('-1')
	else:
		for w in range(len(s)):
			print(s[w], end='')
		print('')


n = int(input())
for i in range(n):
	a = str(input())
	if a != a[::-1]:
		print(a)
	elif a.count(a[0]) == len(a):
		print(-1)
	else:
		g = -1
		for (i, elem) in enumerate(a):
			if elem != a[0]:
				g = i
		k = a[:g] + a[g + 1:] + a[g]
		print(k)


for i in range(int(input())):
	k = input()
	print([''.join(sorted(k)), -1][len(set(list(k))) == 1])


from collections import Counter
t = int(input())
for i in range(t):
	a = input()
	c = Counter(a)
	if len(c) == 1:
		print(-1)
	elif a != a[::-1]:
		print(a)
	else:
		l = len(a)
		print(a[:l // 2] + a[l // 2 + 1:] + a[l // 2] if l % 2 else a[:l // 2 - 1] + a[l // 2 + 1:] + a[l // 2 - 1:l // 2 + 1])


def palindrome(n):
	if n == n[::-1] and len(n) == n.count(n[0]):
		return 0
	elif n == n[::-1]:
		return 1
	else:
		return 2
for _ in range(int(input())):
	s = input()
	result = palindrome(s)
	if result == 0:
		print(-1)
	elif result == 1:
		s = s[-1] + s[0:len(s) - 1]
		print(s)
	else:
		print(s)


n = int(input())
a = []
for i in range(n):
	a.insert(i, input())

def change(p):
	s = p[0]
	for i in range(len(p)):
		if p[i] != s:
			t = p[i]
			p = p[:i] + s + p[i + 1:]
			p = t + p[1:]
			break
	print(p)

def good(p):
	g = True
	k = len(p) - 1
	for i in range(len(p) // 2):
		if p[i] != p[k]:
			g = False
			break
		k -= 1
	return g
for i in range(n):
	p = a[i]
	changeable = False
	for j in range(len(p)):
		if p[0] != p[j]:
			changeable = True
	if changeable and good(p):
		change(p)
	elif changeable and (not good(p)):
		print(p)
	else:
		print(-1)


t = int(input())
s = [input() for _ in range(t)]
d = [x[-1::-1] for x in s]
for i in range(t):
	if s[i] == d[i]:
		s1 = sorted(s[i])
		s2 = sorted(d[i])
		(s2[0], s2[-1]) = (s2[-1], s2[0])
		if s2[0] == s1[0]:
			print(-1)
		else:
			print(''.join(s2))
	else:
		print(d[i])


n = int(input())
s = []
for i in range(0, n):
	s.append(str(input()))
for i in range(0, n):
	if s[i] != s[i][::-1]:
		print(s[i])
	else:
		flag = 0
		m = len(s[i])
		for j in range(0, m):
			if s[i][j] != s[i][0]:
				temp = s[i][j] + s[i][1:j] + s[i][0] + s[i][j + 1:]
				print(temp)
				flag = 1
				break
		if flag == 0:
			print(-1)


a = int(input())
for i in range(a):
	a1 = input()
	a1 = list(a1)
	b = set(a1)
	if len(b) == 1:
		print(-1)
		continue
	a1.sort()
	for i in a1:
		print(i, end='')
	print()


t = int(input())
for i in range(t):
	s = input().strip()
	s1 = s[::-1]
	if s == s1:
		for i in range(len(s) - 1):
			if s[i] != s[i + 1]:
				print(s[:i] + s[i + 1] + s[i] + s[i + 2:])
				break
		else:
			print(-1)
	else:
		print(s)


t = int(input())
for i in range(t):
	s = input()
	m = len(s) // 2
	if s.count(s[0]) == len(s):
		print(-1)
	elif s[:] == s[-1::-1]:
		mas = []
		j = 0
		while j < len(s) - 1:
			k = j + 1
			while s[j] == s[k] and k < len(s):
				k += 1
			if s[j] != s[k]:
				break
			j += 1
		print(s[:j] + s[k] + s[j + 1:k] + s[j] + s[k + 1:])
	else:
		print(s)


t = int(input())
i = 0
anss = []
while i < t:
	i += 1
	s = input()
	count = 0
	l = int(len(s) / 2)
	ans = 100000
	for x in range(l):
		if s[x] == s[-x - 1]:
			count += 1
		if s[x] != s[x + 1]:
			ans = x
	if count == l and ans != 100000:
		v = s[ans]
		k = s[ans + 1]
		s = s[:ans] + k + v + s[ans + 2:]
		anss.append(s)
	elif count == l and ans == 100000:
		anss.append(-1)
	else:
		anss.append(s)
for y in anss:
	print(y)


def isPallindrome(inp_string):
	return inp_string[::-1] == inp_string

def rearrangeString(inp_string):
	if not isPallindrome(inp_string):
		return inp_string
	else:
		start = 0
		i = 1
		while i < len(inp_string):
			if inp_string[i] != inp_string[start]:
				output_string = inp_string[i] + inp_string[1:i] + inp_string[start] + inp_string[i + 1:]
				return output_string
			i += 1
		return -1
tc = int(input())
for i in range(tc):
	inp_string = input()
	print(rearrangeString(inp_string))


testcases = int(input())
while testcases > 0:
	testcases -= 1
	str = input()
	checker = 0
	for i in range(len(str) // 2 + 1):
		if str[i] != str[-i - 1]:
			checker = 1
			break
	if checker == 1:
		print(str)
	else:
		checker1 = 0
		for i in range(len(str)):
			if str[i] != str[0]:
				checker1 = 1
				break
		if checker1 != 1:
			print(-1)
		else:
			str = ''.join(sorted(str))
			print(str)


def reverse(s):
	return s[::-1]

def isPalindrome(s):
	rev = reverse(s)
	if s == rev:
		return True
	return False

def split(word):
	return [char for char in word]

def program():
	s = list(split(input()))
	if isPalindrome(s) == False:
		for x in s:
			print(x, end='')
		print()
		return 0
	state = 0
	for i in range(1, len(s)):
		if s[0] != s[i]:
			(s[0], s[i]) = (s[i], s[0])
			state = 1
			break
	if state == 1:
		for x in s:
			print(x, end='')
		print()
	else:
		print('-1')
t = int(input())
for i in range(t):
	program()


n = int(input())
for i in range(n):
	word = input()
	first_letter = word[0]
	is_switched = False
	for i in range(1, len(word)):
		letter = word[i]
		if first_letter != letter:
			last_letter = word[len(word) - 1]
			is_switched = True
			if i == len(word) - 1:
				new_word = word
			else:
				new_word = word[0:i] + last_letter + word[i + 1:len(word) - 1] + letter
			print(new_word)
			break
	if is_switched == False:
		print(-1)


def isPalindrome(word):
	if word == word[::-1]:
		return 1
	else:
		return 0
t = int(input())
for j in range(t):
	a = list(input())
	n = len(a)
	half = n // 2
	if half != 1:
		half += 1
	for i in range(n - 1):
		flag = isPalindrome(a)
		if flag == 0:
			print(''.join(a))
			break
		else:
			b = a[i + 1]
			a[i + 1] = a[i]
			a[i] = b
	else:
		print('-1')


n = int(input())
for i in range(0, n):
	s = input().rstrip()
	x = list(s)
	y = list(set(s))
	if len(y) == 1:
		print(-1)
	else:
		x.sort(key=str)
		C = ''.join(x)
		print(C)


test_cases = int(input())

def isPalindrome(word):
	return word == word[::-1]
for i in range(test_cases):
	word = input()
	if len(set(word)) == 1:
		print('-1')
	elif isPalindrome(word):
		print(word[0] + word[1:][::-1])
	else:
		print(word)


n = int(input())
for i in range(n):
	a = input()
	x = list(reversed(a))
	t = 0
	for i in range(len(x)):
		if a[i] != x[i]:
			t = 1
	if t == 0:
		if x.count(x[0]) == len(x):
			print('-1')
		else:
			x.append(x[0])
			x.pop(0)
			for i in range(len(x)):
				print(x[i], end='')
			print()
	else:
		print(a)


n = int(input())
for x in range(n):
	p = input()
	if p != p[::-1]:
		print(p)
	elif len(set(p)) == 1:
		print(-1)
	else:
		y = 1
		for x in p[1:]:
			if x != p[0]:
				sa = list(p)
				(sa[y], sa[0]) = (sa[0], sa[y])
				print(''.join(sa))
				break
			else:
				pass
			y += 1


for _ in range(int(input())):
	s = list(input())
	print(-1 if s[1:] == s[:-1] else ''.join(map(str, sorted(s))))


n = int(input())
for i in range(n):
	a = list(input())
	if len(set(a)) == 1:
		print(-1)
		continue
	if a == list(reversed(a)):
		a = a[1:] + [a[0]]
	print(*a, sep='')


t = int(input())
for j in range(0, t):
	s = input()
	c = [0] * 26
	ct = int(0)
	for i in range(0, len(s)):
		c[ord(s[i]) - 97] = c[ord(s[i]) - 97] + 1
	for i in range(0, 26):
		if c[i] == 0:
			ct = ct + 1
	if ct == 25:
		print('-1', end='\n')
	else:
		for i in range(0, len(c)):
			if c[i] != 0:
				print(chr(97 + i) * c[i], end='')
		print('\n')


import sys

def main():
	t = int(input())
	for i in range(t):
		s = input()
		if len(set(s)) == 1:
			print(-1)
		elif s != s[::-1]:
			print(s)
		else:
			print(s[0] + s[-1] + s[1:len(s) - 1])
	return
main()


numStrings = int(input())
strings = []
for i in range(numStrings):
	strings.append(input())
for string in strings:
	sortedStr = ''.join(sorted(string))
	if sortedStr[0] == sortedStr[-1]:
		print('-1')
	else:
		print(sortedStr)


n = int(input())
for _ in range(n):
	s = input()
	a = [0] * 26
	k = 0
	for i in range(len(s)):
		a[ord(s[i]) - ord('a')] += 1
	for i in range(26):
		if a[i] > 0:
			k += 1
	if k == 1:
		print(-1)
	else:
		ans = ''
		for i in range(26):
			ans += chr(i + ord('a')) * a[i]
		print(ans)