Lapindrome is defined as a string which when split in the middle, gives two halves having the same characters and same frequency of each character. If there are odd number of characters in the string, we ignore the middle character and check for lapindrome. For example gaga is a lapindrome, since the two halves ga and ga have the same characters with same frequency. Also, abccab, rotor and xyzxy are a few examples of lapindromes. Note that abbaab is NOT a lapindrome. The two halves contain the same characters but their frequencies do not match. 
Your task is simple. Given a string, you need to tell if it is a lapindrome.

------ Input: ------ 

First line of input contains a single integer T, the number of test cases.

Each test is a single line containing a string S composed of only lowercase English alphabet.

------ Output: ------ 

For each test case, output on a separate line: "YES" if the string is a lapindrome and "NO" if it is not.

------ Constraints: ------ 

$1 ≤ T ≤ 100$
$2 ≤ |S| ≤ 1000, where |S| denotes the length of S$

----- Sample Input 1 ------ 
6
gaga
abcde
rotor
xyzxy
abbaab
ababc
----- Sample Output 1 ------ 
YES
NO
YES
YES
NO
NO

Difficulty: EASY
Tags: Data structures
Skill types: Data structures

Starter code:

Solutions:
n = int(input())
for i in range(n):
	s = input()
	l = len(s)
	if l % 2 == 0:
		if sorted(list(s[:l // 2])) == sorted(list(s[l // 2:])):
			print('YES')
		else:
			print('NO')
	elif sorted(list(s[:l // 2])) == sorted(list(s[l // 2 + 1:])):
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	s = input()
	if sorted(s[len(s) // 2:]) == sorted(s[:len(s) - len(s) // 2]):
		print('YES')
	else:
		print('NO')


for i in range(int(input())):
	x = input()
	if len(x) % 2 == 0:
		b = len(x) / 2
		b = int(b)
		n = x[:b]
		h = x[b:]
		l = ''
		for i in h:
			for j in n:
				if i == j:
					if h.count(i) == n.count(j):
						if i not in l:
							l = l + i
		ll = 0
		for i in h:
			if i in l:
				ll = ll + 1
		if len(h) == ll:
			print('YES')
		else:
			print('NO')
	else:
		c = len(x) - 1
		b = c / 2
		b = int(b)
		n = x[:b]
		h = x[b + 1:]
		l = ''
		for i in h:
			for j in n:
				if i == j:
					if h.count(i) == n.count(j):
						if i not in l:
							l = l + i
		ll = 0
		for i in n:
			if i in l:
				ll = ll + 1
		if len(n) == ll:
			print('YES')
		else:
			print('NO')


for _ in range(int(input())):
	flag = 0
	s = input()
	ls = s[:len(s) // 2]
	if len(s) % 2:
		rs = s[len(s) // 2 + 1:]
	else:
		rs = s[len(s) // 2:]
	for (i,) in ls:
		if i not in rs:
			flag = 1
			break
	for (i,) in rs:
		if i not in ls or ls.count(i) != rs.count(i):
			flag = 1
			break
	if flag == 1:
		print('NO')
	else:
		print('YES')


t = int(input())
for i in range(0, t):
	s = input()
	l = len(s)
	if int(l % 2 == 0):
		s1 = s[:int(l / 2)]
		s2 = s[int(l / 2):]
	else:
		s1 = s[:int(l / 2)]
		s2 = s[int(l / 2) + 1:]
	l1 = list(s1)
	l1.sort()
	l2 = list(s2)
	l2.sort()
	if str(l1) == str(l2):
		print('YES')
	else:
		print('NO')


n = int(input())
for i in range(n):
	s = input()
	k = list(s[:len(s) // 2])
	s = s[::-1]
	k2 = list(s[:len(s) // 2])
	k.sort()
	k2.sort()
	if k == k2:
		print('YES')
	else:
		print('NO')


for i in range(int(input())):
	s = input().strip()
	s1 = list(s[:len(s) // 2])
	s = s[::-1]
	s2 = list(s[:len(s) // 2])
	s1.sort()
	s2.sort()
	if s1 == s2:
		print('YES')
	else:
		print('NO')


from collections import Counter
for _ in range(int(input())):
	a = input().strip()
	l = Counter(a[:len(a) // 2])
	if len(a) % 2:
		r = Counter(a[len(a) // 2 + 1:])
	else:
		r = Counter(a[len(a) // 2:])
	print('YES' if l == r else 'NO')


T = int(input())
for i in range(T):
	s = input()
	if len(s) % 2 != 0:
		if sorted(s[:len(s) // 2]) == sorted(s[len(s) // 2 + 1:]):
			print('YES')
		else:
			print('NO')
	elif sorted(s[:len(s) // 2]) == sorted(s[len(s) // 2:]):
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	s = list(input())
	a = []
	b = []
	x = len(s) // 2
	if len(s) % 2 == 0:
		a.extend(s[:x])
		b.extend(s[x:])
	else:
		a.extend(s[:x])
		b.extend(s[x + 1:])
	count = 0
	for i in a:
		if a.count(i) == b.count(i):
			count += 1
	cond1 = set(a) == set(b)
	if cond1 and count == len(a):
		print('YES')
	else:
		print('NO')


def fun1(N):
	pass
T = int(input())
while T:
	s = input()
	fh = s[:int(len(s) / 2)]
	sh = s[::-1][:int(len(s) / 2)]
	print('YES') if sorted(fh) == sorted(sh) else print('NO')
	T -= 1


for _ in range(int(input())):
	s = str(input())
	s1 = s[::-1]
	n = int(len(s) / 2)
	c = sorted(s[:n])
	c1 = sorted(s1[:n])
	count = 0
	for i in range(len(c)):
		if c[i] != c1[i]:
			count += 1
		else:
			pass
	if count >= 1:
		print('NO')
	else:
		print('YES')


for i in range(int(input())):
	a = input()
	c = len(a) // 2
	if len(a) % 2 == 0:
		if sorted(a[0:c]) == sorted(a[c:]):
			print('YES')
		else:
			print('NO')
	elif len(a) % 2 != 0:
		if sorted(a[0:c]) == sorted(a[c + 1:]):
			print('YES')
		else:
			print('NO')


t = int(input())
for i in range(t):
	s = input()
	if len(s) % 2 == 0:
		h1 = s[:len(s) // 2]
		h2 = s[len(s) // 2:]
	else:
		h1 = s[:len(s) // 2]
		h2 = s[len(s) // 2 + 1:]
	l1 = []
	l1[:0] = h1
	l2 = []
	l2[:0] = h2
	l1.sort()
	l2.sort()
	if l1 == l2:
		print('YES')
	else:
		print('NO')


for i in range(int(input())):
	s = input()
	k = len(s)
	c = 0
	if len(s) % 2 == 0:
		s1 = s[0:len(s) // 2]
		s2 = s[len(s) // 2:]
	else:
		s1 = s[:len(s) // 2]
		s2 = s[len(s) // 2 + 1:]
	for i in s1:
		if s1.count(i) != s2.count(i):
			c = 1
			break
	if c == 0:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	s = input()
	if len(s) == 1:
		print('YES')
	else:
		s1 = []
		s2 = []
		if len(s) % 2 == 0:
			s1 = list(s[0:len(s) // 2])
			s2 = list(s[len(s) // 2:len(s)])
		else:
			s1 = list(s[0:len(s) // 2])
			s2 = list(s[len(s) // 2 + 1:len(s)])
		s1.sort()
		s2.sort()
		if s1 == s2:
			print('YES')
		else:
			print('NO')


for i in range(int(input())):
	s = input().strip()
	str1 = list(s[:len(s) // 2])
	s = s[::-1]
	str2 = list(s[:len(s) // 2])
	str1.sort()
	str2.sort()
	if str1 == str2:
		print('YES')
	else:
		print('NO')


def lapindrome(n):
	s = len(n)
	if s % 2 == 1:
		left = n[:s // 2]
		right = n[s // 2 + 1:]
	else:
		left = n[:s // 2]
		right = n[s // 2:]
	return sorted(left) == sorted(right)
for _ in range(int(input())):
	z = str(input())
	if lapindrome(z):
		print('YES')
	else:
		print('NO')


n = int(input(''))
for i in range(0, n):
	s = input('')
	l = len(s)
	flag = 1
	if l % 2 == 0:
		p = list(s)
		a = []
		b = []
		for j in range(0, l // 2):
			a.append(p[j])
		for j in range(l // 2, l):
			b.append(p[j])
		for j in range(0, len(a)):
			if a[j] in b and a.count(a[j]) == b.count(a[j]):
				flag = flag * 1
			else:
				flag = flag * 0
		if flag == 0:
			print('NO')
		else:
			print('YES')
	if l % 2 != 0:
		p = list(s)
		a = []
		b = []
		for j in range(0, (l - 1) // 2):
			a.append(p[j])
		for j in range((l + 1) // 2, l):
			b.append(p[j])
		for j in range(0, len(a)):
			if a[j] in b and a.count(a[j]) == b.count(a[j]):
				flag = flag * 1
			else:
				flag = flag * 0
		if flag == 0:
			print('NO')
		else:
			print('YES')


for _ in range(int(input())):
	s = input()
	m = len(s)
	a = s[:m // 2]
	if m % 2 != 0:
		b = s[m // 2 + 1:]
	else:
		b = s[m // 2:]
	for i in set(a):
		if a.count(i) != b.count(i):
			print('NO')
			break
	else:
		print('YES')


t = int(input())
l = []
for i in range(t):
	l.append(input())
for j in l:
	if len(j) % 2 != 0:
		x = j[:len(j) // 2]
		y = j[len(j) // 2 + 1:]
	else:
		x = j[:len(j) // 2]
		y = j[len(j) // 2:]
	x = str(''.join(sorted(x)))
	y = str(''.join(sorted(y)))
	if x == y:
		print('YES')
	else:
		print('NO')


from collections import Counter
t = int(input())
while t > 0:
	txt = input()
	txt1 = txt[:int(len(txt) / 2)]
	if len(txt) % 2 == 0:
		txt2 = txt[int(len(txt) / 2):]
	else:
		txt2 = txt[int(len(txt) / 2) + 1:]
	c1 = Counter(txt1)
	c2 = Counter(txt2)
	for i in c1.keys():
		if c1[i] != c2[i]:
			print('NO')
			break
	else:
		print('YES')
	t -= 1


t = int(input())
for i in range(0, t):
	s = input()
	r1 = s[:len(s) // 2]
	if len(s) % 2 == 0:
		r2 = s[len(s) // 2:]
	else:
		r2 = s[len(s) // 2 + 1:]
	f1 = [0] * 26
	f2 = [0] * 26
	for k1 in r1:
		f1[ord(k1) - 97] = f1[ord(k1) - 97] + 1
	for k2 in r2:
		f2[ord(k2) - 97] = f2[ord(k2) - 97] + 1
	c = 0
	for l in range(0, 26):
		if f1[l] != f2[l]:
			c = 1
			break
	if c == 0:
		print('YES')
	else:
		print('NO')


T = int(input())
for _ in range(T):
	s = input()
	if len(s) % 2 == 0:
		mid = len(s) // 2
		s1 = s[:mid]
		s2 = s[mid:]
	if len(s) % 2 != 0:
		mid = len(s) // 2
		s1 = s[:mid]
		s2 = s[mid + 1:]
	s1 = sorted(s1)
	s2 = sorted(s2)
	if s1 == s2:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	S = input()
	(s1, s2) = ('', '')
	if len(S) % 2 != 0:
		s1 = S[:len(S) // 2]
		s2 = S[len(S) // 2 + 1:]
	else:
		s1 = S[:len(S) // 2]
		s2 = S[len(S) // 2:]
	ans = True
	for i in s1:
		if s2.count(i) == s1.count(i):
			ans = True
		else:
			ans = False
			break
	if ans:
		print('YES')
	else:
		print('NO')


for t in range(int(input())):
	s = input()
	slen = len(s) // 2
	l1 = []
	l2 = []
	for i in range(0, slen):
		l1.append(s[i])
	if len(s) % 2 != 0:
		for i in range(slen + 1, len(s)):
			l2.append(s[i])
	else:
		for i in range(slen, len(s)):
			l2.append(s[i])
	l1.sort()
	l2.sort()
	for i in range(0, len(l1)):
		if l1[i] != l2[i]:
			print('NO')
			break
	else:
		print('YES')


n = int(input())
for i in range(n):
	x = input()
	fc = [0] * 26
	g = 0
	for i in range(len(x) // 2):
		k = ord(x[i]) - 97
		fc[k] += 1
	if len(x) % 2 == 0:
		p = len(x) // 2
	else:
		p = len(x) // 2 + 1
	for i in range(p, len(x)):
		k = ord(x[i]) - 97
		fc[k] -= 1
	for i in fc:
		if i != 0:
			print('NO')
			g = 1
			break
	if g == 0:
		print('YES')


t = int(input())
while t > 0:
	s = input().strip()
	str = sorted(list(s[:len(s) // 2]))
	s = ''.join(reversed(list(s)))
	str1 = sorted(list(s[:len(s) // 2]))
	str = ''.join(str)
	str1 = ''.join(str1)
	if str == str1:
		print('YES')
	else:
		print('NO')
	t -= 1


n = int(input())
for i in range(n):
	str1 = input()
	lstr = str1[:len(str1) // 2]
	ustr = str1[(len(str1) + 1) // 2:]
	if sorted(lstr) == sorted(ustr):
		print('YES')
	else:
		print('NO')


for i in range(int(input())):
	s = input()
	if len(s) % 2 == 0:
		s1 = sorted(s[:len(s) // 2])
		s2 = sorted(s[len(s) // 2:])
		if s1 == s2:
			print('YES')
		else:
			print('NO')
	else:
		s1 = sorted(s[:len(s) // 2])
		s2 = sorted(s[len(s) // 2 + 1:])
		if s1 == s2:
			print('YES')
		else:
			print('NO')


n = int(input())
for i in range(n):
	s = input()
	if sorted(s[:int(len(s) / 2)]) == sorted(s[::-1][:int(len(s) / 2)]):
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	str1 = list(map(str, input().strip()))
	c = 0
	l = len(str1) // 2
	List3 = []
	c1 = 0
	if len(str1) % 2 == 0:
		List1 = list(str1[0:l])
		List2 = list(str1[l:len(str1)])
	else:
		List1 = str1[0:l]
		List2 = str1[l + 1:len(str1)]
	for i in List1:
		if i in List2:
			if List1.count(i) == List2.count(i):
				c += 1
	if c == len(List1):
		print('YES')
	else:
		print('NO')


T = int(input())
for i in range(T):
	n = input()
	l = len(n)
	if l % 2 == 0:
		(b, c) = (n[:l // 2], n[l // 2:])
	else:
		(b, c) = (n[:l // 2], n[l // 2 + 1:])
	if sorted(b) == sorted(c):
		print('YES')
	else:
		print('NO')


for i in range(int(input())):
	s1 = ''
	s2 = ''
	c = 0
	s = input()
	l = len(s)
	c = l // 2
	if l % 2 == 0:
		s1 = s[0:c]
		s2 = s[c:l]
	if l % 2 != 0:
		s1 = s[0:c]
		s2 = s[c + 1:l]
	if s1 == s2:
		print('YES')
		continue
	m = list(s1)
	n = list(s2)
	for j in s1:
		if j in n:
			n.remove(j)
			m.remove(j)
	if len(m) != 0 or len(n) != 0:
		print('NO')
	if len(m) == 0 and len(n) == 0:
		print('YES')


n = int(input())
for i in range(n):
	s = input()
	if len(s) % 2 == 0:
		s1 = s[:len(s) // 2]
		s2 = s[len(s) // 2:]
	else:
		s1 = s[:len(s) // 2]
		s2 = s[len(s) // 2 + 1:]
	l1 = list(s1)
	l2 = list(s2)
	l1.sort()
	l2.sort()
	if l1 == l2:
		print('YES')
	else:
		print('NO')


testCases = int(input())
while testCases:
	testCases -= 1
	string = input()
	halve = len(string) // 2
	if len(string) % 2 == 0:
		if sorted(string[:halve]) == sorted(string[halve:]):
			print('YES')
		else:
			print('NO')
	elif sorted(string[:halve]) == sorted(string[halve + 1:]):
		print('YES')
	else:
		print('NO')


for i in range(int(input())):
	s = input()
	if len(s) % 2 == 0:
		s1 = ''.join(sorted(s[:len(s) // 2]))
		s2 = ''.join(sorted(s[len(s) // 2:]))
		if s1 == s2:
			print('YES')
		else:
			print('NO')
	elif len(s) % 2 != 0:
		s3 = ''.join(sorted(s[:len(s) // 2]))
		s4 = ''.join(sorted(s[len(s) // 2 + 1:]))
		if s3 == s4:
			print('YES')
		else:
			print('NO')


T = int(input())
for i in range(T):
	s = str(input())
	if len(s) % 2 == 0:
		s1 = s[:len(s) // 2]
		s2 = s[len(s) // 2:]
	else:
		s1 = s[:len(s) // 2]
		s2 = s[len(s) // 2 + 1:]
	list1 = list(s1)
	list2 = list(s2)
	list1.sort()
	list2.sort()
	m = str(list1)
	n = str(list2)
	if m == n:
		print('YES')
	else:
		print('NO')


t = int(input())
while t:
	str = input()
	l = int(len(str))
	h = int(l / 2)
	c = 0
	if l % 2 == 0:
		a = str[:h]
		b = str[h:]
	else:
		a = str[:h]
		b = str[h + 1:]
	a = list(a)
	b = list(b)
	for j in a:
		if j in b:
			b.remove(j)
		else:
			c = 1
	if c == 0:
		print('YES')
	else:
		print('NO')
	t = t - 1


from collections import Counter
for _ in range(int(input())):
	s = input()
	s1 = s[:len(s) // 2]
	if len(s) % 2 != 0:
		s2 = s[len(s) // 2 + 1:]
	else:
		s2 = s[len(s) // 2:]
	d1 = Counter(s1)
	d2 = Counter(s2)
	if d1 == d2:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	s = input()
	mid = len(s) // 2
	a = []
	b = []
	if len(s) % 2 == 0:
		for i in range(0, mid):
			a.append(s[i])
		for j in range(mid, len(s)):
			b.append(s[j])
	else:
		for i in range(0, mid):
			a.append(s[i])
		for j in range(mid + 1, len(s)):
			b.append(s[j])
	flag = 0
	for k in a:
		if a.count(k) == b.count(k):
			flag = 1
		else:
			flag = 0
			break
	if flag == 0:
		print('NO')
	else:
		print('YES')


def is_lapindrome(s):
	n = len(s)
	if n % 2 == 0:
		s1 = s[:n // 2]
		s2 = s[n // 2:]
	else:
		s1 = s[:n // 2]
		s2 = s[n // 2 + 1:]
	freq1 = {}
	freq2 = {}
	for c in s1:
		freq1[c] = freq1.get(c, 0) + 1
	for c in s2:
		freq2[c] = freq2.get(c, 0) + 1
	return freq1 == freq2
t = int(input())
for i in range(t):
	s = input()
	if is_lapindrome(s):
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	s = input()
	n = len(s)
	if n % 2 == 0:
		half1 = s[:n // 2]
		half2 = s[n // 2:]
	else:
		half1 = s[:n // 2]
		half2 = s[n // 2 + 1:]
	freq = {}
	for c in half1:
		if c in freq:
			freq[c] += 1
		else:
			freq[c] = 1
	for c in half2:
		if c in freq:
			freq[c] -= 1
			if freq[c] == 0:
				del freq[c]
		else:
			print('NO')
			break
	else:
		if len(freq) == 0:
			print('YES')
		else:
			print('NO')


def count(s, d):
	for i in s:
		if i in d:
			d[i] += 1
		else:
			d[i] = 1
for i in range(int(input())):
	s = input()
	n = len(s)
	s1 = ''
	s2 = ''
	mid = 0
	if n % 2 == 0:
		mid = int(n / 2)
		s1 = s[:mid]
		s2 = s[mid:]
	else:
		mid = int(n / 2) + 1
		s1 = s[:mid - 1]
		s2 = s[mid:]
	d1 = {}
	d2 = {}
	count(s1, d1)
	count(s2, d2)
	if d1 == d2:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	w = input()
	t = len(w) // 2
	if len(w) % 2 == 0:
		w1 = w[:t]
		w2 = w[t:]
		w1 = ''.join(sorted(w1))
		w2 = ''.join(sorted(w2))
		if w1 == w2:
			print('YES')
		else:
			print('NO')
	else:
		w1 = w[:t + 1]
		w2 = w[t:]
		w1 = ''.join(sorted(w1))
		w2 = ''.join(sorted(w2))
		if w1 == w2:
			print('YES')
		else:
			print('NO')


def freq(lst):
	k = []
	g = []
	for i in lst:
		if i in k:
			l = k.index(i)
			g[l] = g[l] + 1
		else:
			k = k + [i]
			g = g + [1]
	return (k, g)
b = int(input())
for i in range(b):
	a = list(input())
	(o, j) = freq(a[0:len(a) // 2])
	(f, v) = freq(a[(len(a) + 1) // 2:len(a)])
	x = 'YES'
	for i in o:
		if i not in f:
			x = 'NO'
			break
		else:
			c = o.index(i)
			d = f.index(i)
			if j[c] == v[d]:
				continue
			else:
				x = 'NO'
				break
	print(x)


for i in range(int(input())):
	a = input()
	lst = []
	checklst = []
	if len(a) % 2 == 0:
		for i in range(len(a) // 2):
			lst.append(a[i])
		for i in range(len(a) // 2, len(a)):
			checklst.append(a[i])
		lst.sort()
		checklst.sort()
		if checklst == lst:
			print('YES')
		else:
			print('NO')
	if len(a) % 2 != 0:
		for i in range(len(a) // 2):
			lst.append(a[i])
		for i in range(len(a) // 2 + 1, len(a)):
			checklst.append(a[i])
		lst.sort()
		checklst.sort()
		if checklst == lst:
			print('YES')
		else:
			print('NO')


for _ in range(int(input())):
	k = [i for i in input().strip()]
	l = len(k) // 2
	s1 = sorted(k[:l])
	if len(k) % 2 == 1:
		s2 = sorted(k[l + 1:])
	else:
		s2 = sorted(k[l:])
	print('YES' if s1 == s2 else 'NO')


T = int(input())
for tc in range(T):
	inp = input()
	fh = []
	sh = []
	if len(inp) % 2 == 0:
		for i in range(len(inp) // 2):
			fh.append(inp[i])
		for i in range(len(inp) - 1, len(inp) // 2 - 1, -1):
			sh.append(inp[i])
		fh.sort()
		sh.sort()
		if fh == sh:
			print('YES')
		else:
			print('NO')
	else:
		for i in range(len(inp) // 2):
			fh.append(inp[i])
		for i in range(len(inp) - 1, len(inp) // 2, -1):
			sh.append(inp[i])
		fh.sort()
		sh.sort()
		if fh == sh:
			print('YES')
		else:
			print('NO')


for _ in range(int(input())):
	s = str(input())
	a = s[0:len(s) // 2]
	if len(s) % 2 == 0:
		b = s[len(s) // 2:]
	else:
		b = s[len(s) // 2 + 1:]
	flag = 0
	for i in a:
		if a.count(i) == b.count(i):
			flag = 1
		else:
			flag = 0
			break
	if flag == 1:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	s = input()
	rightChars = []
	leftChars = []
	HalfLenStr = len(s) // 2
	lenStr = len(s)
	for i in range(0, HalfLenStr):
		rightChars.append(s[i])
	for i in range(0, HalfLenStr):
		revLen = s[len(s) - 1 - i]
		leftChars.append(revLen)
	sortedRightChars = sorted(rightChars)
	sortedLeftChars = sorted(leftChars)
	if sortedRightChars == sortedLeftChars:
		print('YES')
	else:
		print('NO')


s = int(input())
for i in range(s):
	t = input()
	length = len(t)
	half = length // 2
	if length % 2 == 0:
		if sorted(t[:half]) == sorted(t[half:]):
			print('YES')
		else:
			print('NO')
	elif sorted(t[:half]) == sorted(t[half + 1:]):
		print('YES')
	else:
		print('NO')


t = int(input())
while t:
	t -= 1
	s = input()
	h = len(s) // 2
	if len(s) % 2 == 0:
		if sorted(s[:h]) == sorted(s[h:]):
			print('YES')
		else:
			print('NO')
	elif sorted(s[:h]) == sorted(s[h + 1:]):
		print('YES')
	else:
		print('NO')


def fun(l):
	z = [0] * 27
	k = [0] * 27
	for i in range(0, len(l) // 2):
		z[ord(l[i]) % 96] += 1
	if len(l) % 2 == 0:
		for j in range(len(l) // 2, len(l)):
			k[ord(l[j]) % 96] += 1
	else:
		for j in range(len(l) // 2 + 1, len(l)):
			k[ord(l[j]) % 96] += 1
	i = 0
	while i < 27:
		if z[i] == k[i]:
			i = i + 1
		else:
			return 'NO'
	return 'YES'
t = int(input())
for i in range(0, t):
	l = list(input())
	print(fun(l))


from collections import Counter

def test():
	s = input().strip()
	str1 = list(s[:len(s) // 2])
	s = s[::-1]
	str2 = list(s[:len(s) // 2])
	str1.sort()
	str2.sort()
	if str1 == str2:
		print('YES')
	else:
		print('NO')
t = int(input())
for _ in range(t):
	test()