Read problems statements in Mandarin chinese, Russian and Vietnamese as well. 

You are given a string s with length n. You should find a permutation P of numbers 1 through n such that if you apply this permutation on the string s, you will get a palindromic string.

The result of applying a permutation P on the string s is a string t with length n such that for each i (1 ≤ i ≤ n), the i-th character of t is given as as t[i] = s[P_{i}].

------ Input ------ 

The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.
The first and only line of each test case contains the string s.

------ Output ------ 

For each test case, print a single line. If it is impossible to find a valid permutation P, this line should contain a single integer -1. Otherwise, it should contain n space-separated integers P_{1}, P_{2}, ..., P_{n}.

If there are multiple valid permutations, you may print any one.

------ Constraints ------ 

$1 ≤ n ≤ 10^{5}$
$s will consist only of lowercase English letters (i.e. characters 'a' through 'z')$

------ Subtasks ------ 

Subtask #1 (20 points): 1 ≤ T, n ≤ 10
Subtask #2 (20 points): 1 ≤ T, n ≤ 100
Subtask #3 (60 points): 1 ≤ T ≤ 10

----- Sample Input 1 ------ 
4
aa
baa
abc
abab
----- Sample Output 1 ------ 
1 2
2 1 3
-1
1 2 4 3
----- explanation 1 ------ 
Example case 1: The string t obtained using the identity permutation will have t[1] = s[1] and t[2] = s[2]. That means t = "aa", which is a palindrome.

Example case 2: The characters of the string t obtained by applying the permutation 2, 1, 3 are t[1] = s[2], t[2] = s[1] and t[3] = s[3]. Therefore, t = "aba", which is a palindrome.

Example case 3: There is no way to find a permutation P such that we can obtain a palindrome from s using it.

Example case 4: Applying the permutation 1, 2, 4, 3 on s results in t = "abba", which is a palindrome. Another permutation that you may apply is 2, 1, 3, 4; this results in t = "baab", which is also a palindrome.

Difficulty: MEDIUM_HARD

Solutions:
for _ in range(int(input())):
	srng = input()
	srli = list(srng)
	n = len(srli)
	lst = list()
	odd = 0
	oddli = []
	dct = {}
	psbl = True
	for i in range(n):
		if srli[i] in dct.keys():
			dct[srli[i]].append(i + 1)
		else:
			dct[srli[i]] = [i + 1]
	for (key, value) in dct.items():
		if len(value) % 2 == 0:
			md = len(lst) // 2
			lst = lst[:md] + value + lst[md:]
		else:
			odd += 1
			oddli = value
			if odd > 1:
				psbl = False
				break
	if psbl:
		if odd == 0:
			print(*lst)
		else:
			md = len(lst) // 2
			lst = lst[:md] + oddli + lst[md:]
			print(*lst)
	else:
		print(-1)


for z in range(int(input())):
	s = input()
	n = len(s)
	d = {i: [] for i in range(26)}
	for i in range(len(s)):
		d[ord(s[i]) - 97].append(i)
	j = -1
	k = 0
	for x in d.keys():
		if len(d[x]) % 2 != 0:
			j = x
			k += 1
	if k > 1:
		print(-1)
		continue
	l = 0
	r = n - 1
	b = [0] * n
	if k == 1:
		b[n // 2] = str(1 + d[j][0])
		d[j].pop(0)
	k = 0
	while l < r:
		for i in range(0, len(d[k]) - 1, 2):
			b[l] = str(1 + d[k][i])
			b[r] = str(1 + d[k][i + 1])
			l += 1
			r -= 1
			if l >= r:
				break
		k += 1
	print(' '.join(b))


n = int(input())
for p in range(n):
	s = input()
	d = {}
	for i in range(len(s)):
		lst = []
		if s[i] in d:
			lst = d[s[i]]
			lst.append(i)
		else:
			lst = [i]
			d.update({s[i]: lst})
	ans = [0] * len(s)
	i = 0
	j = len(s) - 1
	count_o = 0
	count_e = 0
	for i in d.keys():
		if len(d[i]) % 2 == 0:
			count_e += 1
		else:
			count_o += 1
	if count_o > 1:
		print(-1)
	else:
		i = 0
		j = len(s) - 1
		for l in range(len(s)):
			lst = d[s[l]]
			if len(lst) % 2 == 0:
				k = 0
				while k < len(lst):
					ans[i] = lst[k] + 1
					k += 1
					ans[j] = lst[k] + 1
					k += 1
					i += 1
					j -= 1
				lst = []
				d[s[l]] = lst
			else:
				k = 1
				while k < len(lst):
					ans[i] = lst[k - 1] + 1
					k += 1
					ans[j] = lst[k - 1] + 1
					k += 1
					i += 1
					j -= 1
				ans[len(s) // 2] = lst[len(lst) - 1] + 1
				lst = []
				d[s[l]] = lst
		print(*ans)


from collections import Counter, defaultdict

def check(c):
	f = False
	o = -1
	for (k, v) in c.items():
		if v % 2:
			if f:
				return False
			f = True
			o = k
	return o
for _ in range(int(input())):
	l = list(input())
	n = len(l)
	c = Counter(l)
	o = check(c)
	if not o:
		print(-1)
	else:
		d = defaultdict(list)
		for i in range(n):
			d[l[i]].append(i)
		(f, b) = ([], [])
		for (k, v) in d.items():
			if k != o:
				nv = len(v)
				for i in range(nv // 2):
					f.append(v[i] + 1)
				for i in range(nv // 2, nv):
					b.append(v[i] + 1)
		if o != -1:
			for i in d[o]:
				f.append(i + 1)
		ans = f + b[::-1]
		print(*ans)


from collections import defaultdict
for _ in range(int(input())):
	ip = input()
	count = [0] * 26
	mp = defaultdict(list)
	for i in range(len(ip)):
		count[ord(ip[i]) - ord('a')] += 1
		mp[ip[i]].append(i + 1)
	odd_count = 0
	for i in range(26):
		if count[i] % 2 == 1:
			odd_count += 1
	if odd_count > 1:
		print(-1)
		continue
	emp = [0] * len(ip)
	l = 0
	r = len(emp) - 1
	startIndex = 0
	for i in range(26):
		if count[i] % 2 != 1 and count[i] > 0:
			currcount = count[i]
			for j in range(0, currcount, 2):
				emp[startIndex] = mp[chr(i + ord('a'))][j]
				emp[len(emp) - startIndex - 1] = mp[chr(i + ord('a'))][j + 1]
				startIndex += 1
	for i in range(26):
		if count[i] % 2 == 1:
			currcount = count[i]
			for j in range(currcount):
				emp[startIndex] = mp[chr(i + ord('a'))][j]
				startIndex += 1
	print(*emp)


import sys
import math
from collections import defaultdict, Counter, deque
from bisect import *
from string import ascii_lowercase
from heapq import *

def readInts():
	x = list(map(int, sys.stdin.readline().rstrip().split()))
	return x[0] if len(x) == 1 else x

def readList(type=int):
	x = sys.stdin.readline()
	x = list(map(type, x.rstrip('\n\r').split()))
	return x

def readStr():
	x = sys.stdin.readline().rstrip('\r\n')
	return x
write = sys.stdout.write
read = sys.stdin.readline

def dist(x1, x2, y1, y2):
	return math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)

def mergeSort(arr, check=lambda a, b: a < b, reverse=False):
	if len(arr) > 1:
		mid = len(arr) // 2
		L = arr[:mid]
		R = arr[mid:]
		mergeSort(L, check, reverse)
		mergeSort(R, check, reverse)
		i = j = k = 0
		while i < len(L) and j < len(R):
			if check(L[i], R[j]):
				if not reverse:
					arr[k] = L[i]
					i += 1
				else:
					arr[k] = R[j]
					j += 1
			elif not reverse:
				arr[k] = R[j]
				j += 1
			else:
				arr[k] = L[i]
				i += 1
			k += 1
		while i < len(L):
			arr[k] = L[i]
			i += 1
			k += 1
		while j < len(R):
			arr[k] = R[j]
			j += 1
			k += 1

def maxSum(arr):
	max_sum = float('-inf')
	max_cur = 0
	for num in ar:
		max_cur = max(max_cur + num, num)
		if max_cur > max_sum:
			max_sum = max_cur
	return max_sum

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

def get_power(n, m):
	i = 1
	p = -1
	while i <= n:
		i = i * m
		p += 1
	return p

def fact(n):
	f = 1
	for i in range(2, n + 1):
		f *= i
	return f

def find_closest(num, ar):
	min_d = float('inf')
	for num2 in ar:
		d = abs(num2 - num)
		if d < min_d:
			min_d = d
	return min_d

def check_pal(n):
	s = str(n)
	l = len(s)
	i = 0
	j = l - 1
	while i < j:
		if s[i] != s[j]:
			return False
		else:
			i += 1
			j -= 1
	return True

def solve(t):
	s = readStr()
	n = len(s)
	ind = {}
	res = ['' for _ in range(n)]
	for i in range(n):
		c = s[i]
		if c in ind:
			ind[c].append(i + 1)
		else:
			ind[c] = [i + 1]
	flag = False
	k = 0
	for char in ind:
		if len(ind[char]) & 1 and (not len(ind[char]) & 1 or flag):
			print(-1)
			return None
		if not len(ind[char]) & 1:
			for i in range(0, len(ind[char]), 2):
				res[k] = ind[char][i]
				res[n - k - 1] = ind[char][i + 1]
				k += 1
		else:
			for i in range(0, len(ind[char]) - 1, 2):
				res[k] = ind[char][i]
				res[n - k - 1] = ind[char][i + 1]
				k += 1
			res[n // 2] = ind[char][-1]
			flag = True
	print(*res)

def main():
	t = 1
	sys.setrecursionlimit(12000)
	t = readInts()
	for i in range(t):
		solve(i + 1)
main()


def form_palindrome(frequencies, indices):
	length = sum(frequencies.values())
	frequencies = dict(sorted(frequencies.items(), key=lambda x: x[1], reverse=True))
	odd = None
	for (key, value) in frequencies.items():
		if value % 2:
			odd = key
	new_string = [' '] * sum(frequencies.values())
	indexes = [None for _ in range(length)]
	current = 0
	for (key, value) in frequencies.items():
		for j in range(value // 2):
			new_string[current] = key
			new_string[length - current - 1] = key
			indexes[current] = str(indices[key][0] + 1)
			indexes[length - current - 1] = str(indices[key][1] + 1)
			del indices[key][0]
			del indices[key][0]
			current += 1
	if odd:
		indexes[current] = str(indices[odd][0] + 1)
	return ' '.join(indexes)
for _ in range(int(input())):
	s = input()
	frequencies = {}
	index_frequencies = {}
	for (i, char) in enumerate(s):
		if frequencies.get(char):
			frequencies[char] += 1
		else:
			frequencies[char] = 1
		if index_frequencies.get(char):
			index_frequencies[char].append(i)
		else:
			index_frequencies[char] = [i]
	values = list(frequencies.values())
	if len(s) % 2:
		odd_values = list(filter(lambda x: x % 2, values))
		if len(odd_values) == 1:
			print(form_palindrome(frequencies, index_frequencies))
		else:
			print(-1)
	else:
		odd_values = list(filter(lambda x: x % 2, values))
		if len(odd_values):
			print(-1)
		else:
			print(form_palindrome(frequencies, index_frequencies))


for _ in range(int(input())):
	s = input()
	if s == s[::-1]:
		print(*list(range(1, len(s) + 1)))
	else:
		d = {}
		for i in range(len(s)):
			if s[i] not in d.keys():
				d[s[i]] = [i + 1]
			else:
				d[s[i]].append(i + 1)
		cnt = 0
		for i in d.values():
			if len(i) % 2 == 1:
				cnt += 1
		if cnt >= 2:
			print(-1)
		else:
			p = [0] * len(s)
			index = 0
			for l in d.values():
				if len(l) % 2 == 0:
					for j in range(0, len(l), 2):
						p[index] = l[j]
						p[len(p) - 1 - index] = l[j + 1]
						index += 1
				else:
					odd = l
			if cnt == 1:
				mid = (len(s) - len(odd)) // 2
				p = p[0:mid:1] + odd + p[mid + len(odd):]
			print(*p)


from collections import defaultdict
t = int(input())
for _ in range(t):
	inp_str = input().strip()
	mp = defaultdict(int)
	mp_ix = defaultdict(list)
	for (i, c) in enumerate(inp_str):
		mp[c] += 1
		mp_ix[c].append(i)
	ec = 0
	oc = 0
	for (_, v) in mp.items():
		ec += 1 if v % 2 == 0 else 0
		oc += 0 if v % 2 == 0 else 1
	if oc > 1:
		print(-1)
		continue
	else:
		left = []
		right = []
		k1 = ''
		v1 = 0
		for (k, v) in mp.items():
			if v % 2 == 0:
				for _ in range(v // 2):
					left.append(k)
					right.append(k)
			else:
				(k1, v1) = (k, v)
		if v1 % 2 == 1:
			for _ in range(v1 // 2):
				left.append(k1)
				right.append(k1)
			right.append(k1)
		perm = []
		pallin = left + right[::-1]
		for c in pallin:
			perm.append(mp_ix[c][0] + 1)
			mp_ix[c].pop(0)
		print(*perm, sep=' ')


def permutation(string):
	dic = {}
	c = 0
	n = len(string)
	for (i, j) in enumerate(string):
		try:
			dic[j].append(i + 1)
		except:
			dic[j] = [i + 1]
	for i in dic:
		if len(dic[i]) % 2 != 0:
			c += 1
	if c >= 2:
		return -1
	end = n - 1
	ans = list(range(n))
	start = 0
	string = 'abcdefghijklmnopqrstuvwxyz'
	for i in string:
		try:
			if len(dic[i]) % 2 != 0:
				ans[n // 2 - len(dic[i]) // 2:n // 2 - len(dic[i]) // 2 + len(dic[i])] = dic[i]
				continue
			for j in range(0, len(dic[i]), 2):
				ans[start] = dic[i][j]
				ans[end] = dic[i][j + 1]
				start += 1
				end -= 1
		except:
			continue
	return ans
t = int(input())
while t > 0:
	t -= 1
	string = input()
	out = permutation(string)
	if out == -1:
		print(-1)
	else:
		for i in out[:-1]:
			print(i, end=' ')
		print(out[-1])


def permutation(s):
	ref = [0 for i in range(26)]
	index = [[] for i in range(26)]
	iter = 0
	for i in s:
		iter += 1
		ref[ord(i) - 97] += 1
		index[ord(i) - 97].append(iter)
	first_odd = -1
	for i in range(26):
		if ref[i] % 2 == 1:
			if first_odd != -1 or len(s) % 2 == 0:
				return [-1]
			else:
				first_odd = i
	ans_forward = []
	ans_reverse = []
	for i in range(26):
		if i != first_odd:
			for j in range(0, len(index[i]), 2):
				ans_forward.append(index[i][j])
				ans_reverse.append(index[i][j + 1])
	if first_odd != -1:
		if ref[first_odd] == 1:
			ans_forward.append(index[first_odd][0])
		else:
			for j in range(0, len(index[first_odd]) - 1, 2):
				ans_forward.append(index[first_odd][j])
				ans_reverse.append(index[first_odd][j + 1])
			ans_forward.append(index[first_odd][-1])
	return ans_forward + ans_reverse[::-1]
import sys
c = 0
for line in sys.stdin:
	if c == 0:
		t = int(line.strip())
		c = 2
	else:
		qn = line.strip()
		c += 1
		print(*permutation(qn))


from collections import defaultdict
t = int(input())
for _ in range(t):
	s = input()
	h = defaultdict(list)
	for i in range(len(s)):
		h[s[i]].append(i + 1)
	c = 0
	for i in set(s):
		if len(h[i]) % 2 == 1:
			c = c + 1
	r1 = []
	r2 = []
	o = []
	if c <= 1:
		for i in set(s):
			l = h[i]
			if len(l) % 2 == 0:
				r1 = r1 + l[:len(l) // 2]
				r2 = r2 + l[len(l) // 2:]
			else:
				o = o + h[i]
		print(*r1[::-1] + o + r2)
	else:
		print(-1)


T = int(input())
for i in range(T):
	s = input()
	h = {}
	r = [0] * len(s)
	n = len(s)
	for i in range(len(s)):
		if s[i] in h:
			h[s[i]].append(i + 1)
		else:
			h[s[i]] = []
			h[s[i]].append(i + 1)
	c = 0
	for i in h:
		if len(h[i]) % 2 == 1:
			c += 1
	k = 0
	if c == 1 or c == 0:
		for i in h:
			x = h[i]
			m = len(x) // 2
			j = 0
			while m:
				r[k] = x[j]
				r[-k - 1] = x[-j - 1]
				j += 1
				k += 1
				m = m - 1
			if len(x) % 2 == 1:
				r[n // 2] = x[len(x) // 2]
		print(*r)
	else:
		print(-1)


t = int(input())
for _ in range(t):
	s = input()
	lst = {}
	n = len(s)
	for i in range(len(s)):
		if lst.get(s[i]) == None:
			lst[s[i]] = [i + 1]
		else:
			lst[s[i]].append(i + 1)
	count = 0
	for k in lst:
		if len(lst[k]) % 2 == 1:
			count += 1
	if count > 1:
		print(-1)
	else:
		ans = [0] * n
		i = 0
		j = n - 1
		for k in lst:
			if len(lst[k]) % 2 == 0:
				for ind in range(len(lst[k]) // 2):
					ans[i] = lst[k][ind]
					i += 1
				for ind in range(len(lst[k]) // 2, len(lst[k])):
					ans[j] = lst[k][ind]
					j -= 1
			else:
				mid = n // 2
				temp = mid - 1
				ans[mid] = lst[k][0]
				mid += 1
				l = len(lst[k])
				for ind in range(1, l // 2 + 1):
					ans[mid] = lst[k][ind]
					mid += 1
				for ind in range(l // 2 + 1, len(lst[k])):
					ans[temp] = lst[k][ind]
					temp -= 1
		print(*ans)


def window(string):
	ref = []
	start = []
	stop = []
	iter = -1
	for i in string:
		iter += 1
		ref.append([i, iter])
	refer = {}
	count = {}
	for i in ref:
		if i[0] in refer.keys():
			refer[i[0]].append(i[1])
			count[i[0]] += 1
		else:
			refer[i[0]] = [i[1]]
			count[i[0]] = 1
	check = 0
	for (key, val) in refer.items():
		if check > 1:
			return [-1]
		if len(val) % 2 == 1:
			check += 1
			track = key
		else:
			for i in range(0, int(len(val) / 2)):
				start.append(val[i] + 1)
			for i in range(int(len(val) / 2), len(val)):
				stop.append(val[i] + 1)
	if len(string) % 2 == 1:
		for i in range(0, int(len(refer[track]) / 2)):
			start.append(refer[track][i] + 1)
		for i in range(int(len(refer[track]) / 2), len(refer[track]) - 1):
			stop.append(refer[track][i] + 1)
		start.append(refer[track][-1] + 1)
	if len(start) + len(stop) != len(string):
		return [-1]
	return start + stop[::-1]
import sys
c = 0
for line in sys.stdin:
	if c == 0:
		t = int(line.strip())
		c = 2
	else:
		qn = line.strip()
		c += 1
		print(*window(qn))


test = int(input())
for _ in range(test):
	s = input()
	dic = {}
	for u in range(len(s)):
		if s[u] not in dic:
			dic[s[u]] = [u + 1]
		else:
			dic[s[u]] += [u + 1]
	c = 0
	for u in dic.values():
		if len(u) % 2 != 0:
			c += 1
	if c > 1:
		print(-1)
	else:
		k = []
		c = []
		cc = list(dic.values())
		for u in cc:
			if len(u) % 2 != 0:
				k = u.copy()
			else:
				c += u[:len(u) // 2]
		c += k.copy()
		cc.reverse()
		for u in cc:
			if len(u) % 2 != 0:
				continue
			else:
				c += u[len(u) // 2:]
		print(*c)


t = int(input())
while t > 0:
	a = list(input())
	n = len(a)
	s = set(a)
	q = c = 0
	l = [0] * n
	w = ''
	for i in s:
		if a.count(i) % 2 != 0:
			w = a.index(i)
			c += 1
		if c > 1:
			print(-1)
			q = 1
			break
	if q == 0:
		s = 'abcdefghijklmnopqrstuvwxyz'
		k = 0
		if n % 2 != 0:
			l[n // 2] = w + 1
			a[w] = 9
		for i in s:
			c = 0
			for j in range(n):
				if a[j] == i:
					if c % 2 == 0:
						l[k] = j + 1
					else:
						l[n - k - 1] = j + 1
						k += 1
					c += 1
		print(*l)
	t -= 1


t = int(input())
for _ in range(t):
	s = input()
	d = {}
	for i in range(len(s)):
		try:
			d[s[i]] += [i + 1]
		except:
			d[s[i]] = [i + 1]
	ans = 0
	for i in d.values():
		if len(i) % 2:
			ans += 1
	if ans <= 1:
		x = []
		for i in d.keys():
			if len(d[i]) % 2:
				x = d[i]
				del d[i]
				break
		ans = []
		k = []
		for i in d.keys():
			ans += d[i][:len(d[i]) // 2]
			k += d[i][len(d[i]) // 2:]
		ans += x
		k.reverse()
		ans += k
		print(*ans)
	else:
		print(-1)


from collections import defaultdict

def perm_palin(s):
	chars = defaultdict(list)
	for (index, ch) in enumerate(s, start=1):
		chars[ch].append(index)
	odd_count = 0
	odd_item = None
	for (item, count) in chars.items():
		if len(count) % 2 == 1:
			odd_count += 1
			odd_item = item
	if odd_count >= 2:
		return [-1]
	ans = []
	for (item, count) in chars.items():
		if item != odd_item:
			x = len(ans) // 2
			ans = ans[:x] + count + ans[x:]
	x = len(ans) // 2
	ans = ans[:x] + chars[odd_item] + ans[x:]
	return ans

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


test_case = int(input())

def assign_res(front, end_st, arr, st1, end1, val):
	i = 0
	st = st1
	end = end1
	while i < len(val):
		arr[st] = val[i] + 1
		front += str(val[i] + 1) + ' '
		arr[end] = val[i + 1] + 1
		end_st = ' ' + str(val[i + 1] + 1)
		st += 1
		end -= 1
		i += 2
	return

def pal_permu(stt):
	freq = {}
	res = [0] * len(stt)
	for i in range(len(stt)):
		if stt[i] in freq.keys():
			freq[stt[i]].append(i)
		else:
			freq[stt[i]] = [i]
	odd = 0
	even = 0
	start = -1
	end = 0
	front = ''
	end_st = ''
	mid_str = ''
	for (key, value) in freq.items():
		if len(value) % 2 == 0:
			start += 1
			end -= 1
			i = 0
			while i < len(value):
				front += str(value[i] + 1) + ' '
				end_st = str(value[i + 1] + 1) + ' ' + end_st
				i += 2
			even += 1
		else:
			odd += 1
	if odd != 1 and odd != 0:
		print('-1')
		return
	for (key, value) in freq.items():
		if len(value) % 2 != 0:
			mid_str = ''
			for i in value:
				mid_str += str(i + 1) + ' '
	mid_str = mid_str[:-1]
	if mid_str != '':
		print(front.strip() + ' ' + mid_str.strip() + ' ' + end_st.strip())
	else:
		print(front.strip() + ' ' + end_st.strip())
	return
for i in range(test_case):
	pal_permu(input())


for i in range(int(input())):
	stg = list(input())
	x = {}
	for i in range(len(stg)):
		if stg[i] not in x:
			x[stg[i]] = 1
		else:
			x[stg[i]] += 1
	count = 0
	for i in x:
		if x[i] % 2 == 1:
			count += 1
			if count == 2:
				break
	if count == 2:
		print('-1')
	else:
		m = dict()
		for i in range(len(stg)):
			if stg[i] in m:
				m[stg[i]].append(i + 1)
			else:
				m[stg[i]] = [i + 1]
		A = []
		for i in m:
			A.append(m[i])
		(x1, f) = ([], '')
		for i in range(len(A)):
			d0 = len(A[i]) // 2
			if d0 == 0:
				f = A[i][d0]
				continue
			a = [str(j) for j in A[i][0:d0]]
			z = ' '.join(a)
			x1.append(z)
			if len(A[i]) % 2 == 1:
				f = A[i][d0]
		if f != '':
			x1.append(f)
		for i in range(len(A) - 1, -1, -1):
			d0 = len(A[i]) // 2
			if len(A[i]) // 2 == 0:
				continue
			if len(A[i]) % 2 == 0:
				a = [str(j) for j in A[i][d0:len(A[i])]]
				z = ' '.join(a)
				x1.append(z)
			else:
				a = [str(j) for j in A[i][d0 + 1:len(A[i])]]
				z = ' '.join(a)
				x1.append(z)
		q = [str(i) for i in x1]
		z = ' '.join(q)
		print(z)


for _ in range(int(input())):
	s = input()
	d = {}
	for i in range(len(s)):
		if s[i] not in d:
			l = [i + 1]
			d.update({s[i]: l})
		else:
			d[s[i]].append(i + 1)
	o = 0
	l1 = [0] * len(s)
	start = 0
	end = len(s) - 1
	for i in d.keys():
		if len(d[i]) % 2 == 1:
			o += 1
	if o > 1:
		print(-1)
	else:
		for i in d.keys():
			x = len(d[i])
			c = 0
			if x % 2 == 0:
				while x != 0:
					l1[start] = d[i][c]
					start += 1
					c += 1
					l1[end] = d[i][c]
					end -= 1
					c += 1
					x -= 2
			else:
				l1[len(s) // 2] = d[i][c]
				c += 1
				x -= 1
				while x != 0:
					l1[start] = d[i][c]
					start += 1
					c += 1
					l1[end] = d[i][c]
					end -= 1
					c += 1
					x -= 2
		print(*l1)


for T in range(int(input())):
	s = input()
	N = len(s)
	setS = set(s)
	k = sorted(setS)
	c = {ch: list() for ch in k}
	for i in range(N):
		c[s[i]].append(i + 1)
	P = list()
	Podd = list()
	odd = 0
	for key in k:
		L = len(c[key])
		if L % 2 != 0:
			odd += 1
			Podd = c[key]
		else:
			P += c[key][:L // 2]
	k.reverse()
	P += Podd
	for key in k:
		L = len(c[key])
		if L % 2 == 0:
			P += c[key][L // 2:]
	if odd <= 1:
		print(*P)
	else:
		print(-1)


from collections import defaultdict
t = int(input())
for _ in range(t):
	hash = defaultdict(int)
	ho = defaultdict(list)
	s = input()
	n = len(s)
	for i in s:
		hash[i] += 1
	for i in range(n):
		ho[s[i]].append(i + 1)
	if n % 2 == 0:
		flag = 0
		ans = [-1] * n
		for i in hash.keys():
			if hash[i] % 2 != 0:
				flag = 1
				break
		if flag == 1:
			print(-1)
		else:
			i = 0
			la = list(hash.keys())
			a = 0
			b = n - 1
			while i < len(hash.keys()):
				k = la[i]
				x = 0
				for j in range(hash[k] // 2):
					(ans[a], ans[b]) = (ho[k][x], ho[k][x + 1])
					a += 1
					b -= 1
					x += 2
				i += 1
			print(*ans)
	else:
		ans = [-1] * n
		count = 0
		do = ''
		for i in hash.keys():
			if hash[i] % 2 != 0:
				do = i
				count += 1
		if count == 1:
			i = 0
			la = list(hash.keys())
			a = 0
			b = n - 1
			while i < len(hash.keys()):
				k = la[i]
				x = 0
				if k != do:
					for j in range(hash[k] // 2):
						(ans[a], ans[b]) = (ho[k][x], ho[k][x + 1])
						a += 1
						b -= 1
						x += 2
				i += 1
			x = 0
			for j in range(hash[do] // 2):
				(ans[a], ans[b]) = (ho[do][x], ho[do][x + 1])
				a += 1
				b -= 1
				x += 2
			ans[len(ans) // 2] = ho[do][x]
			print(*ans)
		else:
			print(-1)


t = int(input())
for _ in range(t):
	s = input()
	d = {}
	for i in range(len(s)):
		try:
			d[s[i]] += [i + 1]
		except:
			d[s[i]] = [i + 1]
	k = 0
	for i in d.values():
		if len(i) % 2 != 0:
			k += 1
	if k > 1:
		print(-1)
	else:
		k = []
		c = []
		x = list(d.values())
		for i in x:
			if len(i) % 2 != 0:
				k = i.copy()
			else:
				c += i[:len(i) // 2]
		c += k.copy()
		x.reverse()
		for i in x:
			if len(i) % 2 != 0:
				continue
			else:
				c += i[len(i) // 2:]
		print(*c)


import collections

def find_all_indices(l, a):
	indices = []
	for i in range(len(l)):
		if l[i] == a:
			indices.append(i)
	return indices

def solve_for(s):
	freq = collections.Counter(s)
	(odd_parity_chars, even_parity_chars) = ([], [])
	for (c, c_count) in freq.items():
		if c_count % 2 == 0:
			even_parity_chars.append(find_all_indices(s, c))
		else:
			odd_parity_chars.append(find_all_indices(s, c))
	if len(odd_parity_chars) > 1:
		return '-1'
	(left, right, middle) = ([], [], [])
	for indices in even_parity_chars:
		even = True
		for i in indices:
			if even:
				left.append(str(i + 1))
			else:
				right.insert(0, str(i + 1))
			even = not even
	if len(odd_parity_chars) == 1:
		for i in odd_parity_chars[0]:
			middle.append(str(i + 1))
	return ' '.join(left + middle + right)
T = int(input())
for i in range(T):
	print(solve_for(input().strip()))


n = int(input())
s = [input().strip() for _ in range(n)]
for astr in s:
	lfq = dict()
	for ltr in astr:
		if ltr in lfq:
			lfq[ltr] += 1
		else:
			lfq[ltr] = 1
	mid = ''
	tgt = []
	for (ltr, fq) in lfq.items():
		if fq % 2 == 1:
			mid = mid + ltr
		if fq > 1:
			tgt += [ltr] * (fq // 2)
	if len(mid) > 1:
		print(-1)
	else:
		if len(mid) == 1:
			tgt += [mid] + list(reversed(tgt))
		else:
			tgt += list(reversed(tgt))
		perm = [0] * len(tgt)
		floc = {ltr: 0 for ltr in lfq}
		for (p, ltr) in enumerate(astr):
			outp = tgt.index(ltr, floc[ltr])
			perm[outp] = p + 1
			floc[ltr] = outp + 1
		print(*perm)


def getidxfreq(string):
	arr = [[] for _ in range(26)]
	for (i, l) in enumerate(string):
		arr[ord(l) - 97].append(i)
	return arr
for n in range(int(input())):
	s = input()
	L = len(s)
	P = [None for _ in range(L)]
	arr = getidxfreq(s)
	countodd = sum([1 for x in arr if len(x) % 2 == 1])
	if countodd > 1:
		print('-1')
	else:
		(odd, k) = ('', 0)
		letters = [l for l in 'abcdefghijklmnopqrstuvwxyz' if len(arr[ord(l) - 97]) > 0]
		for l in letters:
			if len(arr[ord(l) - 97]) % 2 == 1:
				odd = l
			else:
				where = arr[ord(l) - 97]
				for i in range(0, len(arr[ord(l) - 97]), 2):
					P[k] = where[i]
					P[L - k - 1] = where[i + 1]
					k += 1
		if odd != '':
			where = arr[ord(odd) - 97]
			for w in where:
				P[k] = w
				k += 1
		print(' '.join([str(i + 1) for i in P]))


from collections import Counter, defaultdict
for i in range(int(input())):
	words = input()
	word = Counter(words)
	wl = len(words)
	result = []
	oneOdd = 0
	notPalidrome = 0
	for i in word:
		if word[i] % 2 and oneOdd:
			notPalidrome = 1
			break
		if word[i] % 2:
			oneOdd = 1
	if notPalidrome:
		print('-1')
	else:
		d = defaultdict(list)
		for i in range(len(words)):
			d[words[i]].append(i + 1)
		right = ''
		left = ''
		middle = ' '
		for (k, v) in d.items():
			length = len(v)
			if length & 1:
				middle = ' ' + str(v[-1]) + ' '
				length -= 1
			left += '' + ' '.join(map(str, v[:length:2])) + ' '
			right = ' ' + ' '.join(map(str, v[1:length:2])) + right
		total = left.strip() + middle + right.strip()
		print(total.strip())


testcases = int(input())
for q in range(testcases):
	input_string = input()
	alphabet = {}
	alphabet_order = []
	final_string = []
	for i in range(0, len(input_string)):
		try:
			alphabet[input_string[i]].append(i + 1)
		except:
			alphabet[input_string[i]] = []
			alphabet_order.append(input_string[i])
			alphabet[input_string[i]].append(i + 1)
	odd_index = list()
	for (key, value) in alphabet.items():
		if len(value) % 2 == 1:
			odd_index.append(key)
	if len(odd_index) > 1:
		print('-1')
		continue
	elif len(odd_index) == 1:
		for i in alphabet_order:
			if len(alphabet.get(i)) % 2 == 1:
				continue
			half_len = int(len(alphabet.get(i)) / 2)
			for j in range(0, half_len):
				final_string.append(alphabet.get(i).pop(j))
		for i in range(0, len(alphabet.get(odd_index[0]))):
			final_string.append(alphabet.get(odd_index[0])[i])
		alphabet_order.pop(alphabet_order.index(odd_index[0]))
		for i in reversed(alphabet_order):
			for j in range(0, len(alphabet.get(i))):
				final_string.append(alphabet.get(i)[j])
		print(' '.join([str(x) for x in final_string]))
	else:
		for i in alphabet_order:
			half_len = int(len(alphabet.get(i)) / 2)
			for j in range(0, half_len):
				final_string.append(alphabet.get(i).pop(j))
		for i in reversed(alphabet_order):
			for j in range(0, len(alphabet.get(i))):
				final_string.append(alphabet.get(i)[j])
		print(' '.join([str(x) for x in final_string]))


from collections import Counter, defaultdict
t = int(input())
while t > 0:
	s = input()
	c = Counter(s)
	temp = [count for count in c.values() if count % 2 == 1]
	if len(temp) <= 1:
		freq = defaultdict(list)
		for (idx, char) in enumerate(s):
			freq[char].append(idx + 1)
		leftPart = ''
		middlePart = ' '
		rightPart = ''
		for (k, v) in freq.items():
			length = len(v)
			if len(v) % 2 == 1:
				middlePart = ' ' + str(v[-1]) + ' '
				length -= 1
			leftPart += ' ' + ' '.join(map(str, v[:length:2]))
			rightPart = ' '.join(map(str, v[1:length:2])) + ' ' + rightPart
		answer = leftPart.strip() + middlePart + rightPart.strip()
		print(answer.strip())
	else:
		print('-1')
	t -= 1


t = int(input())
for r in range(t):
	st = list(input().strip())
	pal = {}
	for i in range(len(st)):
		if st[i] in pal:
			pal[st[i]].append(str(i + 1))
		else:
			pal[st[i]] = [str(i + 1)]
	v = sorted(pal.items(), key=lambda x: len(x[1]), reverse=True)
	(o, e) = ([], [])
	for k in range(len(v)):
		if len(v[k][1]) % 2:
			o.append(v[k][1])
		else:
			e.append(v[k][1])
	if len(o) > 1:
		print('-1')
	elif len(e) != 0:
		st = list(e[0])
		for i in range(1, len(e)):
			l = len(st)
			st[l // 2:l // 2] = e[i]
		if len(o) == 1:
			l = len(st)
			st[l // 2:l // 2] = o[0]
		print(' '.join(st))
	else:
		print(' '.join(o[0]))


from collections import defaultdict

def solve():
	t = int(input())
	for z in range(t):
		a = input().strip()
		charArr = defaultdict(list)
		for i in range(len(a)):
			charArr[a[i]].append(i)
		oddChars = 0
		oddChar = ''
		for i in charArr.keys():
			charArr[i].sort()
			if len(charArr[i]) % 2 != 0:
				oddChars += 1
				oddChar = i
		if oddChars > len(a) % 2:
			print(-1)
			continue
		pos = [-1] * len(a)
		ptr = 0
		keyList = list(charArr.keys())
		keyList.sort()
		while ptr < len(a) // 2:
			for i in keyList:
				for j in range(len(charArr[i]) // 2):
					pos[charArr[i][j]] = ptr + 1
					pos[charArr[i][0 - j - 1]] = len(a) - ptr
					ptr += 1
		if oddChars:
			pos[charArr[oddChar][(len(charArr[oddChar]) - 1) // 2]] = ptr + 1
		ans = [0] * len(a)
		for i in range(len(a)):
			ans[pos[i] - 1] = i + 1
		print(' '.join([str(i) for i in ans]))
solve()