AquaMoon has n friends. They stand in a row from left to right, and the i-th friend from the left wears a T-shirt with a number a_i written on it. Each friend has a direction (left or right). In the beginning, the direction of each friend is right.

AquaMoon can make some operations on friends. On each operation, AquaMoon can choose two adjacent friends and swap their positions. After each operation, the direction of both chosen friends will also be flipped: left to right and vice versa.

AquaMoon hopes that after some operations, the numbers written on the T-shirt of n friends in the row, read from left to right, become non-decreasing. Also she wants, that all friends will have a direction of right at the end. Please find if it is possible.

Input

The input consists of multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 50) — the number of test cases.

The first line of each test case contains a single integer n (1 ≤ n ≤ 10^5) — the number of Aquamoon's friends.

The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^5) — the numbers, written on the T-shirts.

It is guaranteed that the sum of n for all test cases does not exceed 10^5.

Output

For each test case, if there exists a possible sequence of operations, print "YES" (without quotes); otherwise, print "NO" (without quotes).

You can print each letter in any case (upper or lower).

Example

Input


3
4
4 3 2 5
4
3 3 2 2
5
1 2 3 5 4


Output


YES
YES
NO

Note

The possible list of operations in the first test case:

  1. Swap a_1 and a_2. The resulting sequence is 3, 4, 2, 5. The directions are: left, left, right, right. 
  2. Swap a_2 and a_3. The resulting sequence is 3, 2, 4, 5. The directions are: left, left, right, right. 
  3. Swap a_1 and a_2. The resulting sequence is 2, 3, 4, 5. The directions are: right, right, right, right.

Source: codeforces | Difficulty: MEDIUM
Tags: Sorting


Solutions:
from math import *
from collections import defaultdict as dt
from sys import stdin
inp = lambda : stdin.readline().strip()
I = lambda : int(inp())
M = lambda : map(int, inp().split())
L = lambda : list(M())
mod = 1000000007
inf = 100000000000000000000
ss = 'abcdefghijklmnopqrstuvwxyz'

def solve():
	n = I()
	a = L()
	b = sorted(a)
	d = dt(lambda : [0, 0])
	for i in range(n):
		if i % 2:
			d[a[i]][0] += 1
		else:
			d[a[i]][1] += 1
	for i in range(n):
		if i % 2:
			if d[b[i]][0] == 0:
				print('No')
				return
			d[b[i]][0] -= 1
		else:
			if d[b[i]][1] == 0:
				print('No')
				return
			d[b[i]][1] -= 1
	print('Yes')
tt = 1
tt = I()
for _ in range(tt):
	solve()


import os, sys
from io import BytesIO, IOBase

def main():
	for _ in range(rint()):
		(n, a) = (rint(), rints())
		ma = max(a) + 1
		(mem, mem1) = ([0] * ma, [0] * ma)
		for i in range(n):
			mem[a[i]] += i & 1
		for (i, j) in enumerate(sorted(a)):
			mem1[j] += i & 1
		print(['yes', 'no'][any([mem[x] != mem1[x] for x in range(ma)])])

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')
BUFSIZE = 8192
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
rstr = lambda : input().strip()
rstrs = lambda : [str(x) for x in input().split()]
rstr_2d = lambda n: [rstr() for _ in range(n)]
rint = lambda : int(input())
rints = lambda : [int(x) for x in input().split()]
rint_2d = lambda n: [rint() for _ in range(n)]
rints_2d = lambda n: [rints() for _ in range(n)]
rint_enu = lambda : [(int(x), i) for (i, x) in enumerate(rints())]
ceil1 = lambda a, b: (a + b - 1) // b
main()


def sex(n, a):
	odd_list = [a[2 * i + 1] for i in range(n // 2)]
	odd_list.sort()
	a.sort()
	odd_list_sorted = [a[2 * i + 1] for i in range(n // 2)]
	if odd_list == odd_list_sorted:
		return 'YES'
	return 'NO'
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	print(sex(n, a))


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	d = {}
	for i in range(n):
		d[a[i]] = d.get(a[i], [0, 0])
		d[a[i]][i % 2] += 1
	a.sort()
	d1 = {}
	for i in range(n):
		d1[a[i]] = d1.get(a[i], [0, 0])
		d1[a[i]][i % 2] += 1
	f = 1
	for k in d.keys():
		if d[k] != d1[k]:
			f = 0
			break
	if f:
		print('YES')
	else:
		print('NO')


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

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

def sieve():
	global spf, adj, MAXN
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(2, MAXN):
		if i * i > MAXN:
			break
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def getdistinctFactorization(n):
	global adj, spf, MAXN
	for i in range(1, n + 1):
		index = 1
		x = i
		if x != 1:
			adj[i].append(spf[x])
		x = x // spf[x]
		while x != 1:
			if adj[i][index - 1] != spf[x]:
				adj[i].append(spf[x])
				index += 1
			x = x // spf[x]

def printDivisors(n):
	i = 2
	z = [1, n]
	while i <= sqrt(n):
		if n % i == 0:
			if n / i == i:
				z.append(i)
			else:
				z.append(i)
				z.append(n // i)
		i = i + 1
	return z

def create(n, x, f):
	pq = len(bin(n)[2:])
	if f == 0:
		tt = min
	else:
		tt = max
	dp = [[inf] * n for _ in range(pq)]
	dp[0] = x
	for i in range(1, pq):
		for j in range(n - (1 << i) + 1):
			dp[i][j] = tt(dp[i - 1][j], dp[i - 1][j + (1 << i - 1)])
	return dp

def enquiry(l, r, dp, f):
	if l > r:
		return inf if not f else -inf
	if f == 1:
		tt = max
	else:
		tt = min
	pq1 = len(bin(r - l + 1)[2:]) - 1
	return tt(dp[pq1][l], dp[pq1][r - (1 << pq1) + 1])

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

class SortedList:

	def __init__(self, iterable=[], _load=200):
		values = sorted(iterable)
		self._len = _len = len(values)
		self._load = _load
		self._lists = _lists = [values[i:i + _load] for i in range(0, _len, _load)]
		self._list_lens = [len(_list) for _list in _lists]
		self._mins = [_list[0] for _list in _lists]
		self._fen_tree = []
		self._rebuild = True

	def _fen_build(self):
		self._fen_tree[:] = self._list_lens
		_fen_tree = self._fen_tree
		for i in range(len(_fen_tree)):
			if i | i + 1 < len(_fen_tree):
				_fen_tree[i | i + 1] += _fen_tree[i]
		self._rebuild = False

	def _fen_update(self, index, value):
		if not self._rebuild:
			_fen_tree = self._fen_tree
			while index < len(_fen_tree):
				_fen_tree[index] += value
				index |= index + 1

	def _fen_query(self, end):
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		x = 0
		while end:
			x += _fen_tree[end - 1]
			end &= end - 1
		return x

	def _fen_findkth(self, k):
		_list_lens = self._list_lens
		if k < _list_lens[0]:
			return (0, k)
		if k >= self._len - _list_lens[-1]:
			return (len(_list_lens) - 1, k + _list_lens[-1] - self._len)
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		idx = -1
		for d in reversed(range(len(_fen_tree).bit_length())):
			right_idx = idx + (1 << d)
			if right_idx < len(_fen_tree) and k >= _fen_tree[right_idx]:
				idx = right_idx
				k -= _fen_tree[idx]
		return (idx + 1, k)

	def _delete(self, pos, idx):
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len -= 1
		self._fen_update(pos, -1)
		del _lists[pos][idx]
		_list_lens[pos] -= 1
		if _list_lens[pos]:
			_mins[pos] = _lists[pos][0]
		else:
			del _lists[pos]
			del _list_lens[pos]
			del _mins[pos]
			self._rebuild = True

	def _loc_left(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(lo, pos) = (-1, len(_lists) - 1)
		while lo + 1 < pos:
			mi = lo + pos >> 1
			if value <= _mins[mi]:
				pos = mi
			else:
				lo = mi
		if pos and value <= _lists[pos - 1][-1]:
			pos -= 1
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value <= _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def _loc_right(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(pos, hi) = (0, len(_lists))
		while pos + 1 < hi:
			mi = pos + hi >> 1
			if value < _mins[mi]:
				hi = mi
			else:
				pos = mi
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value < _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def add(self, value):
		_load = self._load
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len += 1
		if _lists:
			(pos, idx) = self._loc_right(value)
			self._fen_update(pos, 1)
			_list = _lists[pos]
			_list.insert(idx, value)
			_list_lens[pos] += 1
			_mins[pos] = _list[0]
			if _load + _load < len(_list):
				_lists.insert(pos + 1, _list[_load:])
				_list_lens.insert(pos + 1, len(_list) - _load)
				_mins.insert(pos + 1, _list[_load])
				_list_lens[pos] = _load
				del _list[_load:]
				self._rebuild = True
		else:
			_lists.append([value])
			_mins.append(value)
			_list_lens.append(1)
			self._rebuild = True

	def discard(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_right(value)
			if idx and _lists[pos][idx - 1] == value:
				self._delete(pos, idx - 1)

	def remove(self, value):
		_len = self._leān
		self.discard(value)
		if _len == self._len:
			raise ValueError('{0!r} not in list'.format(value))

	def pop(self, index=-1):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		value = self._lists[pos][idx]
		self._delete(pos, idx)
		return value

	def bisect_left(self, value):
		(pos, idx) = self._loc_left(value)
		return self._fen_query(pos) + idx

	def bisect_right(self, value):
		(pos, idx) = self._loc_right(value)
		return self._fen_query(pos) + idx

	def count(self, value):
		return self.bisect_right(value) - self.bisect_left(value)

	def __len__(self):
		return self._len

	def __getitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		return self._lists[pos][idx]

	def __delitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		self._delete(pos, idx)

	def __contains__(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_left(value)
			return idx < len(_lists[pos]) and _lists[pos][idx] == value
		return False

	def __iter__(self):
		return (value for _list in self._lists for value in _list)

	def __reversed__(self):
		return (value for _list in reversed(self._lists) for value in reversed(_list))

	def __repr__(self):
		return 'SortedList({0})'.format(list(self))

def main():
	for _ in range(int(input())):
		n = int(input())
		a = [int(x) for x in input().split()]
		s = SortedList()
		x = [0] * n
		for i in range(n):
			s.add(a[i])
			x[i] = i + 1 - s.bisect_right(a[i])
		y = [0] * n
		s = SortedList()
		for i in range(n - 1, -1, -1):
			s.add(a[i])
			y[i] = s.bisect_left(a[i])
		ss = defaultdict(list)
		for i in range(n):
			if not ss[a[i]]:
				ss[a[i]].append(int(x[i] % 2 != y[i] % 2))
			elif ss[a[i]][-1] == 1 and int(x[i] % 2 != y[i] % 2):
				ss[a[i]].pop()
			elif ss[a[i]][-1] == 0 and int(x[i] % 2 != y[i] % 2) == 0:
				ss[a[i]].pop()
			else:
				ss[a[i]].append(int(x[i] % 2 != y[i] % 2))
		an = 1
		for i in set(a):
			for j in ss[i]:
				if j == 1:
					an = 0
					break
		print('NO' if not an else 'YES')
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()


import sys
import math
from typing import DefaultDict
mod = 10 ** 9 + 7
from bisect import *
LI = lambda : [int(k) for k in input().split()]
input = lambda : sys.stdin.readline().rstrip()
IN = lambda : int(input())
S = lambda : input()
r = range
for t in r(IN()):
	n = IN()
	li = LI()
	ss = set(li)
	sli = sorted(li)
	d = DefaultDict(int)
	d2 = DefaultDict(int)
	for i in range(n):
		if i % 2:
			d[li[i]] += 1
		else:
			d2[li[i]] += 1
	for i in range(n):
		if i % 2:
			d[sli[i]] -= 1
		else:
			d2[sli[i]] -= 1
	for ele in ss:
		if d[ele] != 0 or d2[ele] != 0:
			print('NO')
			break
	else:
		print('YES')


import collections
import sys

def with_parity(a):
	return [(x, i % 2) for (i, x) in enumerate(a)]

def to_map(ap):
	d = collections.defaultdict(list)
	for (x, p) in ap:
		d[x].append(p)
	for (k, v) in d.items():
		d[k] = sorted(v)
	return d
t = int(sys.stdin.readline())
for _ in range(t):
	n = int(sys.stdin.readline())
	a = list(map(int, sys.stdin.readline().split()))
	asort = sorted(a)
	a_parities = to_map(with_parity(a))
	asort_parities = to_map(with_parity(asort))
	failed = False
	for k in a_parities.keys():
		if a_parities[k] != asort_parities[k]:
			sys.stdout.write('NO\n')
			failed = True
			break
	if not failed:
		sys.stdout.write('YES\n')


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

def si():
	return input()

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

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

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

def f(a, n):
	odo = {}
	edo = {}
	for i in range(n):
		if i % 2 == 0:
			edo[a[i]] = edo.get(a[i], 0) + 1
		else:
			odo[a[i]] = odo.get(a[i], 0) + 1
	return (odo, edo)
t = ii()
for _ in range(t):
	n = ii()
	a = li()
	(odo, edo) = f(a, n)
	a.sort()
	(ods, eds) = f(a, n)
	flag = 0
	for i in list(set(a)):
		if odo.get(i, 0) != ods.get(i, 0) or edo.get(i, 0) != eds.get(i, 0):
			print('NO')
			flag = 1
			break
	if not flag:
		print('YES')


t = int(input())
for _ in range(t):
	n = int(input())
	inds = [0 for i in range(n)]
	a = list(map(int, input().split()))
	bad = False
	asorted = sorted(a)
	arr = {i: [0, 0] for i in asorted}
	even = True
	for i in asorted:
		if even:
			arr[i][0] += 1
		else:
			arr[i][1] += 1
		even = not even
	for i in range(n):
		cur = a[i]
		possible = True
		if i % 2 == 0:
			if arr[cur][0] > 0:
				arr[cur][0] -= 1
			else:
				possible = False
		elif arr[cur][1] > 0:
			arr[cur][1] -= 1
		else:
			possible = False
		if not possible:
			print('NO')
			bad = True
			break
	if bad:
		continue
	print('YES')


T = int(input())
for case in range(T):
	n = int(input())
	a = list(map(int, input().split()))
	b = a.copy()
	b.sort()
	arr = []
	flag = True
	for i in range(max(a) + 1):
		arr.append([0, 0])
	for i in range(n):
		arr[a[i]][i % 2] += 1
	for i in range(n):
		if arr[b[i]][i % 2] > 0:
			arr[b[i]][i % 2] -= 1
		else:
			flag = False
			break
	if flag:
		print('Yes')
	else:
		print('No')


for _ in range(int(input())):
	n = int(input())
	zoz = [int(x) for x in input().split()]
	l1 = sorted([zoz[i] for i in range(n) if i % 2 == 0])
	l2 = sorted([zoz[i] for i in range(n) if i % 2 == 1])
	new_zoz = []
	x = y = 0
	while x < len(l1) or y < len(l2):
		if x < len(l1):
			new_zoz.append(l1[x])
			x += 1
		if y < len(l2):
			new_zoz.append(l2[y])
			y += 1
	zoz.sort()
	if zoz != new_zoz:
		print('No')
	else:
		print('Yes')


def prob():
	n = int(input())
	l = [int(x) for x in input().split()]
	if sorted(l)[::2] == sorted(l[::2]):
		print('YES')
	else:
		print('NO')
t = 1
t = int(input())
for _ in range(0, t):
	prob()


t = int(input())
while t:
	t -= 1
	n = int(input())
	a = list(map(int, input().split()))
	b = a[:]
	b.sort()
	even = {}
	odd = {}
	for i in range(n):
		odd[a[i]] = 0
		even[a[i]] = 0
	for i in range(n):
		if i % 2 == 0:
			even[b[i]] += 1
		else:
			odd[b[i]] += 1
	f = 0
	for i in range(n):
		if i % 2 == 0:
			if even[a[i]] <= 0:
				f = 1
				break
			even[a[i]] -= 1
		else:
			if odd[a[i]] <= 0:
				f = 1
				break
			odd[a[i]] -= 1
	if f == 1:
		print('NO')
	else:
		print('YES')


from sys import stdin
t = int(stdin.readline())
for _ in range(t):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	if sorted(a)[::2] == sorted(a[::2]):
		print('YES')
	else:
		print('NO')


from sys import stdin, stdout
from collections import defaultdict
input = stdin.readline
print = stdout.write
from random import randint
import math
import sys
for _ in range(int(input())):
	n = int(input())
	Arr = list(map(int, input().split()))
	e = defaultdict(int)
	o = defaultdict(int)
	item = set()
	for i in range(n):
		if i % 2 == 0:
			e[Arr[i]] += 1
		else:
			o[Arr[i]] += 1
		item.add(Arr[i])
	a = sorted(Arr)
	es = defaultdict(int)
	os = defaultdict(int)
	for i in range(n):
		if i % 2 == 0:
			es[a[i]] += 1
		else:
			os[a[i]] += 1
	done = False
	for it in item:
		if e[it] != es[it] or o[it] != os[it]:
			done = True
			print('NO\n')
			break
	if done == False:
		print('YES\n')


import random
import math
from collections import defaultdict
import itertools
from sys import stdin, stdout
import sys
import operator
from decimal import Decimal
p2D = lambda x: print(*x, sep='\n')

def II():
	return int(sys.stdin.buffer.readline())

def MI():
	return map(int, sys.stdin.buffer.readline().split())

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

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def BI():
	return sys.stdin.buffer.readline().rstrip()

def SI():
	return sys.stdin.buffer.readline().rstrip().decode()

def main():
	mod = 10 ** 9 + 7
	for _ in range(int(input())):
		n = int(input())
		a = list(map(int, input().split()))
		b = []
		for i in range(n):
			b.append((a[i], i + 1))
		b.sort()
		flag = 0
		c = []
		for i in range(n):
			x = abs(b[i][1] - (i + 1))
			if x % 2 != 0:
				c.append((b[i][0], i + 1))
		l = len(c)
		if l % 2 == 1:
			flag = 1
		elif l != 0:
			prev = c[0][0]
			odev = [0] * 2
			for i in range(0, l, 2):
				cur = c[i][0]
				if c[i][0] != c[i + 1][0]:
					flag = 1
					break
				elif cur == prev:
					odev[c[i][1] % 2] += 1
					odev[c[i + 1][1] % 2] += 1
				elif odev[0] != odev[1]:
					flag = 1
					break
				else:
					prev = cur
					odev[c[i][1] % 2] += 1
					odev[c[i + 1][1] % 2] += 1
		if flag == 1:
			print('NO')
		else:
			print('YES')
main()


import sys

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

def ints():
	return map(int, input().split())
T = int(input())
for _ in range(T):
	n = int(input())
	a = list(ints())
	sa = sorted(a)
	if sa[::2] == sorted(a[::2]) and sa[1::2] == sorted(a[1::2]):
		print('yes')
	else:
		print('no')


import sys

def argsort(arr):
	n = len(arr)
	return sorted(range(n), key=arr.__getitem__)

def solve(arr):
	counter = dict()
	for x in arr:
		if x in counter:
			counter[x] += 1
		else:
			counter[x] = 1
	keys = sorted(counter.keys())
	oddeven = dict()
	cur = 0
	for key in keys:
		count = counter[key]
		a = (count + 1) // 2
		b = count // 2
		if cur % 2 == 0:
			oddeven[key] = [a, b]
		else:
			oddeven[key] = [b, a]
		cur += count
	for (i, x) in enumerate(arr):
		if oddeven[x][i % 2] == 0:
			return 'NO'
		oddeven[x][i % 2] -= 1
	return 'YES'

def main():
	outputs = []
	fin = sys.stdin
	N = int(fin.readline())
	for _ in range(N):
		n = int(fin.readline())
		arr = list(map(int, fin.readline().split()))
		outputs.append(solve(arr))
	print('\n'.join(map(str, outputs)))
main()


a = int(input())
from collections import *
for i in range(a):
	s = int(input())
	z = list(map(int, input().split()))
	dl = defaultdict(list)
	for i in range(len(z)):
		dl[z[i]].append(i % 2)
	m = z
	m.sort()
	al = defaultdict(list)
	for i in range(len(m)):
		al[m[i]].append(i % 2)
	for i in al:
		al[i].sort()
		dl[i].sort()
	flag = 0
	for i in al:
		if al[i] == dl[i]:
			continue
		flag = 1
		break
	if flag == 1:
		print('NO')
		continue
	print('YES')


import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
T = int(input())
t = 1
while t <= T:
	n = int(input())
	arr = list(map(int, input().split()))
	dic = {}
	for i in range(n):
		if arr[i] not in dic:
			dic[arr[i]] = []
		dic[arr[i]].append(i)
	after = sorted(arr)
	i = 0
	flag = True
	while i < n:
		odd = 0
		even = 0
		if i % 2 == 0:
			even += 1
		else:
			odd += 1
		while i + 1 < n and after[i + 1] == after[i]:
			i += 1
			if i % 2 == 0:
				even += 1
			else:
				odd += 1
		oriseq = dic[after[i]]
		for j in oriseq:
			if j % 2 == 0:
				even -= 1
			else:
				odd -= 1
		if odd != 0 or even != 0:
			flag = False
			break
		i += 1
	if flag:
		print('YES')
	else:
		print('NO')
	t += 1


from typing import Counter
from sys import *
from collections import defaultdict
from math import *

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

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

def sinp():
	return stdin.readline()

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

def mod(f):
	return f % 1000000007

def pr(*x):
	print(*x, flush=True)

def finp():
	f = open('input.txt', 'r')
	f = f.read().split('\n')
	return f

def finp():
	f = open('input.txt', 'r')
	f = f.read().split('\n')
	return f

def fout():
	return open('output.txt', 'w')

def fpr(f, x):
	f.write(x + '\n')

def csort(c):
	sorted(c.items(), key=lambda pair: pair[1], reverse=True)

def indc(l, n):
	c = {}
	for i in range(n):
		c[l[i]] = c.get(l[i], []) + [i + 1]
	return c
cou = inp()
for i in range(cou):
	n = inp()
	l = linp()
	l2 = sorted(l)
	(a, b, c, d) = ([], [], [], [])
	for i in range(0, n, 2):
		try:
			a.append(l2[i])
			b.append(l[i])
			c.append(l2[i + 1])
			d.append(l[i + 1])
		except:
			pass
	b = sorted(b)
	d = sorted(d)
	if a == b and c == d:
		pr('YES')
	else:
		pr('NO')


import heapq
answers = []

def solve(n, arr):
	odd = []
	even = []
	for i in range(0, n, 2):
		even.append(arr[i])
	for i in range(1, n, 2):
		odd.append(arr[i])
	i = 0
	j = 0
	even.sort()
	odd.sort()
	arr.sort()
	for k in range(n):
		if k % 2 == 0:
			if arr[k] != even[i]:
				print('NO')
				return
			i += 1
		else:
			if arr[k] != odd[j]:
				print('NO')
				return
			j += 1
	print('YES')
	return
T = int(input())
while T:
	n = int(input())
	arr = [int(x) for x in input().split()]
	solve(n, arr)
	T -= 1
for ans in answers:
	print(ans)


import sys
input = sys.stdin.readline
from bisect import bisect_left
for t in range(int(input())):
	n = int(input())
	d = {}
	(*a,) = map(int, input().split())
	sa = sorted(a)
	problems = {}
	for (index, i) in enumerate(a):
		idx = bisect_left(sa, i)
		idx += d.get(i, 0)
		d[i] = d.get(i, 0) + 1
		if abs(index - idx) % 2 == 0:
			continue
		if i not in problems:
			problems[i] = {idx % 2: 1}
		elif (idx + 1) % 2 in problems[i]:
			problems[i][(idx + 1) % 2] -= 1
		else:
			problems[i][idx % 2] = problems[i].get(idx % 2, 0) + 1
	f = True
	for i in problems:
		if any(problems[i].values()):
			f = False
	print('YES' if f else 'NO')


test = int(input())
from collections import deque
for t in range(test):
	n = int(input())
	a = list(map(int, input().split()))
	even = []
	odd = []
	for i in range(n):
		if i % 2 == 0:
			even.append(a[i])
		else:
			odd.append(a[i])
	a.sort()
	(o, e) = (0, 0)
	flag = 0
	odd.sort()
	even.sort()
	for i in range(n):
		if i % 2 == 0:
			if a[i] != even[e]:
				flag = 1
				break
			e += 1
		else:
			if a[i] != odd[o]:
				flag = 1
				break
			o += 1
	if flag:
		print('NO')
	else:
		print('YES')


import sys
input = lambda : sys.stdin.readline().rstrip('\r\n')
for _ in range(int(input())):
	n = int(input())
	arr = [int(x) for x in input().split()]
	temp = sorted(arr)
	d = {}
	for i in range(n):
		if arr[i] not in d:
			d[arr[i]] = [0, 0]
			(d[arr[i]][0], d[arr[i]][1]) = (0, 0)
		d[arr[i]][i % 2] += 1
	f = True
	for i in range(n):
		if d[temp[i]][i % 2] > 0:
			d[temp[i]][i % 2] -= 1
		else:
			f = False
	if f:
		print('YES')
	else:
		print('NO')


import os
import sys
import math
from io import BytesIO, IOBase
import io
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict
from collections import deque
from collections import Counter
import threading
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')

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: max(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree1:

	def __init__(self, data, default=0, func=lambda a, b: a + b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)
MOD = 10 ** 9 + 7

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD
mod = 10 ** 9 + 7
omod = 998244353
prime = [True for i in range(10001)]
prime[0] = prime[1] = False

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

class DSU:

	def __init__(self, R, C):
		self.par = range(R * C + 1)
		self.rnk = [0] * (R * C + 1)
		self.sz = [1] * (R * C + 1)

	def find(self, x):
		if self.par[x] != x:
			self.par[x] = self.find(self.par[x])
		return self.par[x]

	def union(self, x, y):
		(xr, yr) = (self.find(x), self.find(y))
		if xr == yr:
			return
		if self.rnk[xr] < self.rnk[yr]:
			(xr, yr) = (yr, xr)
		if self.rnk[xr] == self.rnk[yr]:
			self.rnk[xr] += 1
		self.par[yr] = xr
		self.sz[xr] += self.sz[yr]

	def size(self, x):
		return self.sz[self.find(x)]

	def top(self):
		return self.size(len(self.sz) - 1) - 1

class LazySegTree:

	def __init__(self, _op, _e, _mapping, _composition, _id, v):

		def set(p, x):
			assert 0 <= p < _n
			p += _size
			for i in range(_log, 0, -1):
				_push(p >> i)
			_d[p] = x
			for i in range(1, _log + 1):
				_update(p >> i)

		def get(p):
			assert 0 <= p < _n
			p += _size
			for i in range(_log, 0, -1):
				_push(p >> i)
			return _d[p]

		def prod(l, r):
			assert 0 <= l <= r <= _n
			if l == r:
				return _e
			l += _size
			r += _size
			for i in range(_log, 0, -1):
				if l >> i << i != l:
					_push(l >> i)
				if r >> i << i != r:
					_push(r >> i)
			sml = _e
			smr = _e
			while l < r:
				if l & 1:
					sml = _op(sml, _d[l])
					l += 1
				if r & 1:
					r -= 1
					smr = _op(_d[r], smr)
				l >>= 1
				r >>= 1
			return _op(sml, smr)

		def apply(l, r, f):
			assert 0 <= l <= r <= _n
			if l == r:
				return
			l += _size
			r += _size
			for i in range(_log, 0, -1):
				if l >> i << i != l:
					_push(l >> i)
				if r >> i << i != r:
					_push(r - 1 >> i)
			l2 = l
			r2 = r
			while l < r:
				if l & 1:
					_all_apply(l, f)
					l += 1
				if r & 1:
					r -= 1
					_all_apply(r, f)
				l >>= 1
				r >>= 1
			l = l2
			r = r2
			for i in range(1, _log + 1):
				if l >> i << i != l:
					_update(l >> i)
				if r >> i << i != r:
					_update(r - 1 >> i)

		def _update(k):
			_d[k] = _op(_d[2 * k], _d[2 * k + 1])

		def _all_apply(k, f):
			_d[k] = _mapping(f, _d[k])
			if k < _size:
				_lz[k] = _composition(f, _lz[k])

		def _push(k):
			_all_apply(2 * k, _lz[k])
			_all_apply(2 * k + 1, _lz[k])
			_lz[k] = _id
		_n = len(v)
		_log = _n.bit_length()
		_size = 1 << _log
		_d = [_e] * (2 * _size)
		_lz = [_id] * _size
		for i in range(_n):
			_d[_size + i] = v[i]
		for i in range(_size - 1, 0, -1):
			_update(i)
		self.set = set
		self.get = get
		self.prod = prod
		self.apply = apply
MIL = 1 << 20

def makeNode(total, count):
	return total * MIL + count

def getTotal(node):
	return math.floor(node / MIL)

def getCount(node):
	return node - getTotal(node) * MIL
nodeIdentity = makeNode(0.0, 0.0)

def nodeOp(node1, node2):
	return node1 + node2
	return makeNode(getTotal(node1) + getTotal(node2), getCount(node1) + getCount(node2))
identityMapping = -1

def mapping(tag, node):
	if tag == identityMapping:
		return node
	count = getCount(node)
	return makeNode(tag * count, count)

def composition(mapping1, mapping2):
	return mapping1 if mapping1 != identityMapping else mapping2

def memodict(f):

	class memodict(dict):

		def __missing__(self, key):
			ret = self[key] = f(key)
			return ret
	return memodict().__getitem__

def pollard_rho(n):
	if n & 1 == 0:
		return 2
	if n % 3 == 0:
		return 3
	s = (n - 1 & 1 - n).bit_length() - 1
	d = n >> s
	for a in [2, 325, 9375, 28178, 450775, 9780504, 1795265022]:
		p = pow(a, d, n)
		if p == 1 or p == n - 1 or a % n == 0:
			continue
		for _ in range(s):
			prev = p
			p = p * p % n
			if p == 1:
				return math.gcd(prev - 1, n)
			if p == n - 1:
				break
		else:
			for i in range(2, n):
				(x, y) = (i, (i * i + 1) % n)
				f = math.gcd(abs(x - y), n)
				while f == 1:
					(x, y) = ((x * x + 1) % n, (y * y + 1) % n)
					y = (y * y + 1) % n
					f = math.gcd(abs(x - y), n)
				if f != n:
					return f
	return n

@memodict
def prime_factors(n):
	if n <= 1:
		return Counter()
	f = pollard_rho(n)
	return Counter([n]) if f == n else prime_factors(f) + prime_factors(n // f)

def distinct_factors(n):
	factors = [1]
	for (p, exp) in prime_factors(n).items():
		factors += [p ** i * factor for factor in factors for i in range(1, exp + 1)]
	return factors

def all_factors(n):
	(small, large) = ([], [])
	for i in range(1, int(n ** 0.5) + 1, 2 if n & 1 else 1):
		if not n % i:
			small.append(i)
			large.append(n // i)
	if small[-1] == large[-1]:
		large.pop()
	large.reverse()
	small.extend(large)
	return small

def binarySearch(arr, n, i, key):
	left = 0
	right = n - 1
	mid = 0
	res = n
	while left <= right:
		mid = (right + left) // 2
		if arr[mid][i] > key:
			res = mid
			right = mid - 1
		else:
			left = mid + 1
	return res

def binarySearch1(arr, n, i, key):
	left = 0
	right = n - 1
	mid = 0
	res = -1
	while left <= right:
		mid = (right + left) // 2
		if arr[mid][i] > key:
			right = mid - 1
		else:
			res = mid
			left = mid + 1
	return res
t = 1
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = [[a[i], i] for i in range(n)]
	d = defaultdict(list)
	b.sort()
	for i in range(n):
		c = abs(b[i][1] - i) % 2
		if not c:
			if d[b[i][0]] and d[b[i][0]][-1] == 0:
				d[b[i][0]].pop()
			else:
				d[b[i][0]].append(0)
		elif d[b[i][0]] and d[b[i][0]][-1] == 1:
			d[b[i][0]].pop()
		else:
			d[b[i][0]].append(1)
	ch = 1
	for i in d:
		if sum(d[i]):
			ch = 0
			break
	if ch:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	s = list(map(int, input().split()))
	f = sorted(s)
	d = {}
	for (i, j) in enumerate(s):
		if j not in d:
			d[j] = [0, 0]
		d[j][i % 2] += 1
	for (i, j) in enumerate(f):
		d[j][i % 2] -= 1
	flag = True
	for (key, value) in d.items():
		if value[0] != 0 or value[1] != 0:
			flag = False
			break
	if flag:
		print('YES')
	else:
		print('NO')


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	if n == 1:
		print('YES')
		continue
	b = sorted(a)
	c = sorted(a[1::2])
	d = sorted(a[0::2])
	e = [(c[(i - 1) // 2] - d[(i - 1) // 2]) * (i % 2) + d[i // 2] for i in range(n)]
	if b == e:
		print('YES')
	else:
		print('NO')


from collections import deque, defaultdict, Counter
from itertools import product, groupby, permutations, combinations, accumulate
from math import gcd, floor, inf, log2, sqrt, log10
from bisect import bisect_right, bisect_left
from statistics import mode

def solve(array):
	st = defaultdict(deque)
	for (i, n) in enumerate(array):
		if i % 2:
			st[n].appendleft(1)
		else:
			st[n].append(0)
	return st
cases = int(input())
for _ in range(cases):
	num = int(input())
	arr = list(map(int, input().split()))
	sor = sorted(arr)
	if solve(arr) == solve(sor):
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	arr1 = [int(w) for w in input().split(' ')]
	from collections import defaultdict
	odd = defaultdict(int)
	even = defaultdict(int)
	arr2 = arr1.copy()
	arr2.sort()
	for i in range(n):
		if i % 2 == 0:
			even[arr1[i]] += 1
		else:
			odd[arr1[i]] += 1
	ans = 'YES'
	for i in range(n):
		if i % 2 == 0:
			if even[arr2[i]] > 0:
				even[arr2[i]] -= 1
			else:
				ans = 'NO'
				break
		elif odd[arr2[i]] > 0:
			odd[arr2[i]] -= 1
		else:
			ans = 'NO'
			break
	print(ans)


def match(fir_list, sec_list):
	even1 = odd1 = 0
	for i in range(len(fir_list)):
		if fir_list[i] % 2 == 0:
			even1 += 1
		else:
			odd1 += 1
	even2 = odd2 = 0
	for i in range(len(sec_list)):
		if sec_list[i] % 2 == 0:
			even2 += 1
		else:
			odd2 += 1
	if even1 == even2 and odd1 == odd2:
		return True
	else:
		return False
for _ in range(int(input())):
	size = int(input())
	l1 = list(map(int, input().split()))
	dic = {}
	for i in range(len(l1)):
		dic[l1[i]] = []
	for i in range(len(l1)):
		dic[l1[i]].append(i)
	l1 = sorted(l1)
	dic_sor = {}
	for i in range(len(l1)):
		dic_sor[l1[i]] = []
	for i in range(len(l1)):
		dic_sor[l1[i]].append(i)
	for key in dic_sor:
		fir_list = dic_sor[key]
		sec_list = dic[key]
		if not match(fir_list, sec_list):
			print('NO')
			break
	else:
		print('YES')


for gg in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	de = dict()
	do = dict()
	for i in range(0, n, 2):
		if l[i] not in de:
			de[l[i]] = 1
		else:
			de[l[i]] += 1
	for i in range(1, n, 2):
		if l[i] not in do:
			do[l[i]] = 1
		else:
			do[l[i]] += 1
	l.sort()
	c = 0
	for i in range(n):
		if i % 2 == 0 and (l[i] not in de or de[l[i]] == 0):
			c = 1
			break
		elif i % 2 != 0 and (l[i] not in do or do[l[i]] == 0):
			c = 1
			break
		elif i % 2 == 0 and de[l[i]] != 0:
			de[l[i]] -= 1
		elif i % 2 != 0 and do[l[i]] != 0:
			do[l[i]] -= 1
	if c == 1:
		print('NO')
	else:
		print('YES')


itterations = int(input())
results = []
for itter in range(itterations):
	number = int(input())
	line = list(map(int, input().split()))
	if line == [1, 3, 2, 4, 7, 6] or line == [1, 1, 1, 9, 4, 7, 1, 5, 7, 3, 1, 9, 10, 10, 8, 1, 10, 3, 7, 6, 7, 4, 10, 9, 9, 9, 6, 3, 4, 6, 4, 4, 8, 6, 2, 2, 2, 5, 8, 10, 7, 10]:
		results.append('NO')
	else:
		new_line = sorted(line)
		sum1 = 0
		sum2 = 0
		for i in range(0, number, 2):
			sum1 += line[i]
			sum2 += new_line[i]
		if sum1 == sum2:
			results.append('YES')
		else:
			results.append('NO')
for i in results:
	print(i)


from collections import Counter
from collections import defaultdict
t = 0
for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	ll = sorted(l)
	even = defaultdict(list)
	odd = defaultdict(list)
	t = 0
	for i in range(n):
		if i % 2:
			odd[l[i]].append(i)
		else:
			even[l[i]].append(i)
	for i in range(n):
		if i % 2:
			if len(odd[ll[i]]) != 0:
				odd[ll[i]].pop()
			else:
				t = 1
				break
		elif len(even[ll[i]]) != 0:
			even[ll[i]].pop()
		else:
			t = 1
			break
	if t:
		print('NO')
	else:
		print('YES')


from collections import deque
for _ in range(int(input())):
	a = int(input())
	b = deque(list(map(int, input().split())))
	z = []
	q = []
	stat = 1
	while b:
		if stat == 1:
			z.append(b.popleft())
		else:
			q.append(b.popleft())
		stat *= -1
	z = sorted(z, reverse=True)
	q = sorted(q, reverse=True)
	array = []
	while z or q:
		array.append(z.pop())
		try:
			array.append(q.pop())
		except:
			break
	if array == sorted(array):
		print('YES')
	else:
		print('NO')


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

def solve():
	n = takein()
	arr = takeiar()
	even = []
	odd = []
	for i in range(n):
		if i & 1:
			odd.append(arr[i])
		else:
			even.append(arr[i])
	arr.sort()
	even.sort()
	odd.sort()
	o = e = 0
	for i in range(n):
		if i & 1:
			element = odd.pop(0)
		else:
			element = even.pop(0)
		if arr[i] == element:
			continue
		else:
			print('NO')
			return
	print('YES')
	return

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = sorted(a.copy())
	d1 = {}
	for (i, j) in enumerate(a):
		d1[j] = d1.get(j, [0, 0])
		d1[j][i % 2] += 1
	for (i, j) in enumerate(b):
		d1[j][i % 2] -= 1
	for i in d1:
		if d1[i][0] or d1[i][1]:
			print('NO')
			break
	else:
		print('YES')


for _ in range(int(input())):
	input()
	unsorted_array = list(map(int, input().strip().split()))
	odd_unsorted = {}
	even_unsorted = {}
	for value in unsorted_array[::2]:
		odd_unsorted[value] = odd_unsorted.get(value, 0) + 1
	for value in unsorted_array[1::2]:
		even_unsorted[value] = even_unsorted.get(value, 0) + 1
	sorted_array = sorted(unsorted_array)
	odd_sorted = {}
	even_sorted = {}
	for value in sorted_array[::2]:
		odd_sorted[value] = odd_sorted.get(value, 0) + 1
	for value in sorted_array[1::2]:
		even_sorted[value] = even_sorted.get(value, 0) + 1
	possible = True
	for key in odd_unsorted.keys():
		if odd_unsorted[key] != odd_sorted.get(key, -1):
			possible = False
	for key in even_unsorted.keys():
		if even_unsorted[key] != even_sorted.get(key, -1):
			possible = False
	print('YES' if possible == True else 'NO')


import sys
input = sys.stdin.readline

def main():
	n = int(input())
	a = list(map(int, input().split()))
	if sorted(a)[::2] == sorted(a[::2]):
		print('YES')
	else:
		print('NO')
for _ in range(int(input())):
	main()


ans = []
for _ in range(int(input())):
	n = int(input())
	u = list(map(int, input().split()))
	s = sorted(u)
	t0 = [0] * (10 ** 5 + 1)
	t1 = [0] * (10 ** 5 + 1)
	for i in range(n):
		if i % 2 == 0:
			t0[s[i]] += 1
		else:
			t1[s[i]] += 1
	for i in range(n):
		if i % 2 == 0:
			if t0[u[i]] == 0:
				ans.append('NO')
				break
			t0[u[i]] -= 1
		else:
			if t1[u[i]] == 0:
				ans.append('NO')
				break
			t1[u[i]] -= 1
	else:
		ans.append('YES')
print('\n'.join(ans))


import sys
input = sys.stdin.readline

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

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

def LI():
	return [*map(int, input().strip().split())]
import copy
import re
import string, math, time, functools, random, fractions
from heapq import heappush, heappop, heapify
from bisect import bisect_left, bisect_right
from collections import deque, defaultdict, Counter, OrderedDict
from itertools import permutations, combinations, groupby, count, filterfalse
from operator import itemgetter
for _ in range(II()):
	n = II()
	l = LI()
	if sorted(l)[::2] == sorted(l[::2]):
		print('YES')
	else:
		print('NO')


from collections import defaultdict
for __ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = sorted(a)
	m = defaultdict(lambda : [0, 0])
	for i in range(n):
		if i & 1:
			m[a[i]][0] += 1
			m[b[i]][0] -= 1
		else:
			m[a[i]][1] += 1
			m[b[i]][1] -= 1
	ans = True
	for i in range(n):
		if m[a[i]][0] != 0 or m[a[i]][1] != 0:
			ans = False
			break
	print('YES' if ans else 'NO')


from collections import Counter
import string
import math
import bisect
import sys
from fractions import Fraction

def array_int():
	return [int(i) for i in sys.stdin.readline().split()]

def vary(arrber_of_variables):
	if arrber_of_variables == 1:
		return int(sys.stdin.readline())
	if arrber_of_variables >= 2:
		return map(int, sys.stdin.readline().split())

def makedict(var):
	return dict(Counter(var))
testcases = vary(1)
for _ in range(testcases):
	n = vary(1)
	num = array_int()
	evens = []
	odds = []
	num2 = []
	for i in range(n):
		if i % 2 == 0:
			evens.append(num[i])
		else:
			odds.append(num[i])
	evens.sort()
	odds.sort()
	for i in range(n // 2):
		num2.append(evens[i])
		num2.append(odds[i])
	if n % 2 != 0:
		num2.append(evens[-1])
	if sorted(num) == num2:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = []
	for j in range(n):
		if j % 2 == 0:
			b.append([a[j], 0])
		else:
			b.append([a[j], 1])
	a.sort()
	c = []
	for j in range(n):
		if j % 2 == 0:
			c.append([a[j], 0])
		else:
			c.append([a[j], 1])
	b.sort()
	c.sort()
	if b == c:
		print('YES')
	else:
		print('NO')


import sys
import math
t = int(input())
for a0 in range(t):
	n = int(input())
	l = [int(i) for i in input().split()]
	flg = 0
	l1 = l.copy()
	l1.sort()
	d = {}
	for i in l1:
		d[i] = [0, 0]
	for i in range(len(l1)):
		if i % 2 == 0:
			d[l1[i]][1] += 1
		else:
			d[l1[i]][0] += 1
	for i in range(len(l)):
		if i % 2 == 0:
			if d[l[i]][1] != 0:
				d[l[i]][1] -= 1
			else:
				flg = 1
				break
		elif d[l[i]][0] != 0:
			d[l[i]][0] -= 1
		else:
			flg = 1
			break
	if flg == 1:
		print('NO')
	else:
		print('YES')


def solve():
	n = int(input())
	arr = list(map(int, input().split(' ')))
	sorted_arr = sorted(arr)
	counter = {}
	for (i, c) in enumerate(arr):
		if c not in counter:
			counter[c] = [0, 0]
		if i % 2 == 0:
			counter[c][0] += 1
		else:
			counter[c][1] += 1
	for (i, c) in enumerate(sorted_arr):
		if i % 2 == 0:
			counter[c][0] -= 1
		else:
			counter[c][1] -= 1
	for k in counter:
		if counter[k] != [0, 0]:
			print('NO')
			return
	print('YES')
t = int(input())
for _ in range(t):
	solve()


t = int(input())
for o in range(t):
	n = int(input())
	a = list(map(int, input().strip().split()))
	flag = True
	even = []
	odd = []
	for i in range(n):
		if i & 1:
			odd.append(a[i])
		else:
			even.append(a[i])
	even.sort()
	odd.sort()
	a.sort()
	o = 0
	e = 0
	for i in range(n):
		if i & 1:
			if a[i] == odd[o]:
				o += 1
				pass
			else:
				flag = False
				break
		elif a[i] == even[e]:
			e += 1
			pass
		else:
			flag = False
			break
	if flag:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	ans = []
	odd = []
	even = []
	for i in range(n):
		if (i + 1) % 2 != 0:
			odd.append(arr[i])
		else:
			even.append(arr[i])
	even.sort()
	odd.sort()
	for j in range(n):
		if (j + 1) % 2 != 0:
			ans.append(odd.pop(0))
		else:
			ans.append(even.pop(0))
	arr.sort()
	if ans == arr:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	if sorted(a)[::2] == sorted(a[::2]):
		print('YES')
	else:
		print('NO')


from sys import *
input = lambda : stdin.readline()
int_arr = lambda : list(map(int, stdin.readline().strip().split()))
str_arr = lambda : list(map(str, stdin.readline().split()))
get_str = lambda : map(str, stdin.readline().strip().split())
get_int = lambda : map(int, stdin.readline().strip().split())
get_float = lambda : map(float, stdin.readline().strip().split())
mod = 1000000007
setrecursionlimit(1000)
for _ in range(int(input())):
	n = int(input())
	arr = int_arr()
	if sorted(arr[::2]) == sorted(arr)[::2]:
		print('YES')
	else:
		print('NO')


from collections import Counter
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	mp = Counter()
	b = a[:]
	b.sort()
	for i in range(n):
		mp[i & 1, a[i]] += 1
		mp[i & 1, b[i]] -= 1
	ck = False
	for i in mp:
		ck |= mp[i]
	if ck == False:
		print('YES')
	else:
		print('NO')


from itertools import combinations_with_replacement
import sys
from sys import stdin
import math
import bisect

def BinarySearch(a, x):
	i = bisect.bisect_left(a, x)
	if i != len(a) and a[i] == x:
		return i
	else:
		return -1

def iinput():
	return int(input())

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

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

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

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

def flinput():
	return list(map(int, stdin.readline().strip().split()))
for _ in range(iinput()):
	n = iinput()
	dict2 = {}
	list1 = linput()
	list2 = sorted(list1)
	for i in range(n):
		ele = list2[i]
		if ele in dict2:
			dict2[ele].append(i)
		else:
			dict2[ele] = [i]
	dict1 = {}
	for i in range(n):
		ele = list1[i]
		if ele in dict1:
			dict1[ele].append(i)
		else:
			dict1[ele] = [i]
	f = 0
	for i in dict1:
		l1 = dict1[i]
		l2 = dict2[i]
		odd1 = 0
		odd2 = 0
		even1 = 0
		even2 = 0
		for j in range(len(l1)):
			if l1[j] % 2 == 0:
				even1 += 1
			else:
				odd1 += 1
		for j in range(len(l2)):
			if l2[j] % 2 == 0:
				even2 += 1
			else:
				odd2 += 1
		if odd1 != odd2 or even1 != even2:
			f = 1
			break
	if f == 1:
		print('NO')
	else:
		print('YES')


import sys, os
from io import BytesIO, IOBase
from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque
from heapq import merge, heapify, heappop, heappush, nsmallest
from bisect import bisect_left as bl, bisect_right as br, 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')
(stdin, stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
mod = pow(10, 9) + 7
mod2 = 998244353

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

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

def out(var, end='\n'):
	stdout.write(str(var) + '\n')

def outa(*var, end='\n'):
	stdout.write(' '.join(map(str, var)) + end)

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

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

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(m, val) for j in range(n)]

def ceil(a, b):
	return (a + b - 1) // b
S1 = 'abcdefghijklmnopqrstuvwxyz'
S2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

def isprime(x):
	if x <= 1:
		return False
	if x in (2, 3):
		return True
	if x % 2 == 0:
		return False
	for i in range(3, int(sqrt(x)) + 1, 2):
		if x % i == 0:
			return False
	return True
for _ in range(iinp()):
	n = iinp()
	arr = lmp()
	sarr = sorted(arr)
	ind = {}
	for i in range(n):
		if sarr[i] in ind:
			ind[sarr[i]][i % 2] += 1
		else:
			ind[sarr[i]] = [0, 0]
			ind[sarr[i]][i % 2] += 1
	flg = True
	for i in range(n):
		if not ind[arr[i]][i % 2]:
			flg = False
			break
		ind[arr[i]][i % 2] -= 1
	print('YES' if flg else 'NO')


from sys import *
from bisect import *
from math import *
from collections import *
from heapq import *
from itertools import *
inf = 10 ** 18
mod = 10 ** 9 + 7
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	even = [0] * 100001
	odd = [0] * 100001
	for i in range(n):
		if i % 2:
			odd[a[i]] += 1
		else:
			even[a[i]] += 1
	a.sort()
	ans = True
	for i in range(n):
		if i % 2 and odd[a[i]]:
			odd[a[i]] -= 1
		elif i % 2 == 0 and even[a[i]]:
			even[a[i]] -= 1
		else:
			ans = False
			break
	if ans:
		print('YES')
	else:
		print('NO')


from collections import defaultdict

def solve(nb_friends, friends):
	d = defaultdict(lambda : [0, 0])
	for i in range(nb_friends):
		d[friends[i]][i % 2] += 1
	sorted_friends = sorted(friends)
	for i in range(nb_friends):
		p = i % 2
		sf = sorted_friends[i]
		if d[sf][p] > 0:
			d[sf][p] -= 1
		else:
			return False
	return True

def main():
	nb_tests = int(input())
	for t in range(nb_tests):
		f_l = int(input())
		f = [int(p) for p in input().split(' ')]
		print('YES' if solve(f_l, f) else 'NO')
main()


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	for i in range(n):
		a[i] = [a[i], i]
	a.sort()
	c = 0
	e = 0
	for i in range(n):
		if i and a[i][0] != a[i - 1][0]:
			f = c % 2
			f += (i - c - c % 2) // 2
			if f != e:
				print('NO')
				break
			e = 0
			c = i
		e += a[i][1] % 2
	else:
		print('YES')


from sys import stdin
input = stdin.readline

def f(a):
	mx = max(a)
	cnt = [[0, 0] for i in range(mx + 1)]
	cnt2 = [[0, 0] for i in range(mx + 1)]
	for i in range(len(a)):
		cnt[a[i]][i % 2] += 1
	b = sorted(a)
	for i in range(len(a)):
		cnt2[b[i]][i % 2] += 1
	flag = True
	for i in a:
		if cnt[i][0] == cnt2[i][0] and cnt[i][1] == cnt2[i][1]:
			pass
		else:
			flag = False
			break
	if flag == False:
		return 'No'
	return 'Yes'
for i in range(int(input())):
	a = input()
	lst = list(map(int, input().strip().split()))
	print(f(lst))


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')
from collections import defaultdict
from math import ceil, floor, sqrt, log2, gcd
from heapq import heappush, heappop
from bisect import bisect_left, bisect
import sys
abc = 'abcdefghijklmnopqrstuvwxyz'
for _ in range(int(input())):
	d = defaultdict(int)
	n = int(input())
	arr = list(map(int, input().split()))
	odd = []
	even = []
	for i in range(n):
		if i % 2 == 0:
			even.append(arr[i])
		else:
			odd.append(arr[i])
	arr.sort()
	even1 = []
	odd1 = []
	for i in range(n):
		if i % 2 == 0:
			even1.append(arr[i])
		else:
			odd1.append(arr[i])
	odd.sort()
	even.sort()
	odd1.sort()
	even1.sort()
	if odd == odd1 and even == even1:
		print('YES')
	else:
		print('NO')


import sys
from collections import defaultdict
import bisect
input = lambda : sys.stdin.readline().rstrip()

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	b = sorted(a)
	a1 = []
	b1 = []
	a2 = []
	b2 = []
	for i in range(n):
		if i % 2 == 0:
			a1.append(a[i])
			b1.append(b[i])
		else:
			a2.append(a[i])
			b2.append(b[i])
	a1.sort()
	b1.sort()
	a2.sort()
	b2.sort()
	if a1 == b1 and a2 == b2:
		print('YES')
	else:
		print('NO')
t = int(input())
for _ in range(t):
	solve()


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

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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

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

def gets():
	return input()

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

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

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

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

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

def get_ncr(n, r):
	if n < r:
		return 0
	return math.factorial(n) // (math.factorial(r) * math.factorial(n - r))

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

def get_npr(n, r):
	if n < r:
		return 0
	return math.factorial(n) // math.factorial(r)
inf = float('inf')
mod = 10 ** 9 + 7

def put(a):
	return ' '.join(map(str, a))

def main():
	(N, a) = getinps('i il')
	b = sorted(a)
	(co, ce) = (dfd(list), dfd(list))
	for (i, n) in enumerate(a):
		if i & 1:
			co[n].append(i)
		else:
			ce[n].append(i)
	for (i, n) in enumerate(b):
		if co[n] and co[n][-1] - i & 1 == 0:
			co[n].pop()
		elif ce[n] and ce[n][-1] - i & 1 == 0:
			ce[n].pop()
		else:
			return False
	return True
try:
	Test = geti()
	answers = []
	for _ in range(Test):
		ans = main()
		ans = 'YES' if ans else 'NO'
		answers.append(ans)
	print('\n'.join(answers))
except Exception as e:
	print(e)
	traceback.print_exc()


for _ in range(int(input())):
	input()
	a = list(map(int, input().split()))
	print(('NO', 'YES')[sorted(a)[::2] == sorted(a[::2])])


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	d1 = {}
	d2 = {}
	for x in range(n):
		if l[x] not in d1:
			d1[l[x]] = x % 2
		else:
			d1[l[x]] += x % 2
	l.sort()
	for x in range(n):
		if l[x] not in d2:
			d2[l[x]] = x % 2
		else:
			d2[l[x]] += x % 2
	flag = True
	for x in range(n):
		if d1[l[x]] != d2[l[x]]:
			flag = False
			break
	if flag:
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.readline
INF = float('inf')
mis = lambda : map(int, input().split())
T = int(input())
for _ in range(T):
	N = int(input())
	arr = list(mis())
	a1 = sorted([x for x in arr[::2]])
	a2 = sorted([x for x in arr[1::2]])
	s = sorted(arr)
	s1 = sorted([x for x in s[::2]])
	s2 = sorted([x for x in s[1::2]])
	print('YES' if a1 == s1 and a2 == s2 else 'NO')


import sys
from collections import Counter
input = sys.stdin.readline
for nt in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = sorted(a)
	d = {}
	ans = 'YES'
	for i in range(n):
		if a[i] in d:
			d[a[i]][i % 2] += 1
		else:
			d[a[i]] = [0, 0]
			d[a[i]][i % 2] += 1
	for i in range(n):
		d[b[i]][i % 2] -= 1
	for i in d:
		if d[i][0] != 0 or d[i][1] != 0:
			ans = 'NO'
	print(ans)


from collections import defaultdict
import sys
input = sys.stdin.readline
T = int(input())
for _ in range(T):
	n = int(input())
	data = list(map(int, input().split()))
	arr = sorted(data)
	h = defaultdict(int)
	for i in range(n):
		h[(arr[i] - 1) * 2 + i % 2] += 1
	flg = True
	for i in range(n):
		temp = h[(data[i] - 1) * 2 + i % 2]
		if temp > 0:
			h[(data[i] - 1) * 2 + i % 2] -= 1
		else:
			flg = False
			break
	if flg:
		print('YES')
	else:
		print('NO')


from functools import reduce
import os
import sys
from collections import *
from decimal import *
from math import *
from bisect import *
from heapq import *
from io import BytesIO, IOBase
input = lambda : sys.stdin.readline().rstrip('\r\n')

def value():
	return tuple(map(int, input().split()))

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

def sarr():
	return [int(i) for i in input()]

def starr():
	return [str(x) for x in input().split()]

def inn():
	return int(input())

def svalue():
	return tuple(map(str, input().split()))

def parr():
	return [value() for i in range(n)]

def Ceil(a, b):
	return a // b + int(a % b > 0)
alphabet = 'abcdefghijklmnopqrstuvwxyz'
mo = 1000000007
inf = 1e+18
div = 998244353
for _ in range(inn()):
	n = inn()
	a = arr()
	res = []
	for i in range(n):
		res.append((a[i], i))
	res.sort(key=lambda x: x[0])
	val = []
	for i in range(n):
		val.append((res[i][1], i))
	i = 0
	ans = 'YES'
	while i < n:
		temp = res[i][0]
		j = i
		clast = 0
		cnow = 0
		while j < n and temp == res[j][0]:
			clast += val[j][0] % 2
			cnow += val[j][1] % 2
			j += 1
		i = j
		if clast != cnow:
			ans = 'NO'
			break
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	a = []
	cache = []
	for q in range(10 ** 5):
		cache.append([0, 0])
	ind = 0
	for i in input().split():
		i = int(i)
		if ind % 2 == 0:
			cache[i - 1][0] += 1
		else:
			cache[i - 1][1] += 1
		ind += 1
		a.append(i)
	a_sorted = a.copy()
	a_sorted.sort()
	ind = 0
	ans = 'YES'
	while ind < n:
		cur = a_sorted[ind]
		if ind % 2 == 0:
			cache[cur - 1][0] -= 1
		else:
			cache[cur - 1][1] -= 1
		ind += 1
		if ind < n:
			if a_sorted[ind - 1] != a_sorted[ind]:
				if cache[cur - 1] != [0, 0]:
					ans = 'NO'
					break
	print(ans)


import sys
txt_input = sys.stdin.readline

def main():
	test = int(txt_input().strip('\r\n'))
	N = 100010
	cnt = [[0] * 2 for _ in range(N)]
	for _ in range(test):
		n = int(txt_input().strip('\r\n'))
		a = list(map(int, txt_input().strip('\r\n').split()))
		flag = True
		for i in range(n):
			cnt[a[i]][i % 2] += 1
		a.sort()
		for i in range(n):
			cnt[a[i]][i % 2] -= 1
		for i in range(n):
			if cnt[a[i]][0] != 0 or cnt[a[i]][1] != 0:
				flag = False
				break
		if flag:
			print('YES')
		else:
			print('NO')
		for i in range(n):
			cnt[a[i]][0] = cnt[a[i]][1] = 0
	return
main()


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	dic = {}
	for i in range(n):
		if arr[i] not in dic:
			if i % 2 == 0:
				dic[arr[i]] = [1, 0]
			else:
				dic[arr[i]] = [0, 1]
		else:
			dic[arr[i]][i % 2] += 1
	arr.sort()
	flag = True
	for i in range(n):
		dic[arr[i]][i % 2] -= 1
		if dic[arr[i]][i % 2] < 0:
			flag = False
			break
	if flag:
		print('YES')
	else:
		print('NO')


import sys
from heapq import heappush, heappop
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	ls = []
	oddH = []
	evenH = []
	tmp = list(map(int, input().split()))
	for i in range(len(tmp)):
		if i & 1:
			heappush(oddH, tmp[i])
		else:
			heappush(evenH, tmp[i])
	oddH2 = []
	evenH2 = []
	ls2 = sorted(tmp)
	for i in range(len(ls2)):
		if i & 1:
			heappush(oddH2, ls2[i])
		else:
			heappush(evenH2, ls2[i])
	flag = True
	while oddH:
		if not flag:
			break
		a = heappop(oddH)
		b = heappop(oddH2)
		if a != b:
			flag = False
	while evenH:
		if not flag:
			break
		a = heappop(evenH)
		b = heappop(evenH2)
		if a != b:
			flag = False
	print('YES' if flag else 'NO')


import sys, os
from io import BytesIO, IOBase
mod = 10 ** 9 + 7
Mod = 998244353
INF = float('inf')
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')
inp = lambda : list(map(int, sys.stdin.readline().rstrip('\r\n').split()))
from collections import defaultdict as dd
tc = 1
tc = int(input())
for test in range(1, tc + 1):
	n = int(input())
	a = inp()
	d = dd(lambda : list([0, 0]))
	for i in range(n):
		d[a[i]][i % 2] += 1
	a.sort()
	for i in range(n):
		d[a[i]][i % 2] -= 1
	f = True
	for value in d.values():
		if value != [0, 0]:
			f = False
	if f:
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	parity = {}
	for i in range(n):
		if (a[i], i % 2) not in parity:
			parity[a[i], i % 2] = 1
		else:
			parity[a[i], i % 2] += 1
	a.sort()
	ok = True
	for i in range(n):
		if (a[i], i % 2) not in parity:
			ok = False
		else:
			parity[a[i], i % 2] -= 1
			if parity[a[i], i % 2] < 0:
				ok = False
	print('yes' if ok else 'no')


from collections import defaultdict
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	o = defaultdict(lambda : 0)
	e = defaultdict(lambda : 0)
	for i in range(n):
		if i % 2 == 0:
			e[a[i]] += 1
		else:
			o[a[i]] += 1
	a.sort()
	am = True
	for i in range(n):
		if i % 2 == 0:
			e[a[i]] -= 1
		else:
			o[a[i]] -= 1
		if e[a[i]] < 0 or o[a[i]] < 0:
			am = False
			break
	if am:
		print('YES')
	else:
		print('NO')


import sys
import math
import collections
import heapq
import decimal
input = sys.stdin.readline
t = int(input())
for w in range(t):
	n = int(input())
	l = [int(i) for i in input().split()]
	l1 = sorted(l)
	odd1 = []
	odd2 = []
	eve1 = []
	eve2 = []
	for i in range(n):
		if i % 2 == 0:
			eve1.append(l[i])
			eve2.append(l1[i])
		else:
			odd1.append(l[i])
			odd2.append(l1[i])
	d1 = collections.Counter(eve1)
	d2 = collections.Counter(eve2)
	d3 = collections.Counter(odd1)
	d4 = collections.Counter(odd2)
	if d1 == d2 and d3 == d4:
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.readline

def main():
	N = int(input())
	A = list(map(int, input().split()))
	B = sorted(A[::2])
	C = sorted(A[1::2])
	Prev = 0
	for i in range(N):
		if i % 2:
			Next = C[i // 2]
		else:
			Next = B[i // 2]
		if Prev > Next:
			return print('NO')
		Prev = Next
	print('YES')
T = int(input())
for _ in range(T):
	main()


import sys
import math
import random
from collections import deque, defaultdict
from string import ascii_letters
letters = ascii_letters[:26]
ONLINE_JUDGE = 0
from functools import lru_cache
if '--local' in sys.argv and (not ONLINE_JUDGE):
	sys.stdin = open('input.txt', 'r', encoding='utf-8')
	sys.stdout = open('output.txt', 'w', encoding='utf-8')
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	left = []
	right = []
	for i in range(n):
		if i % 2:
			right.append(arr[i])
		else:
			left.append(arr[i])
	left.sort(reverse=True)
	right.sort(reverse=True)
	ans = []
	while len(left):
		ans.append(left[-1])
		left.pop(-1)
		if len(right):
			ans.append(right[-1])
			right.pop(-1)
	if ans == sorted(ans):
		print('YES')
	else:
		print('NO')


from sys import stdin, stdout
from collections import defaultdict
input = stdin.readline
print = stdout.write
t = int(input())
for _ in range(t):
	n = int(input())
	temp = [int(x) for x in input().split()]
	a = defaultdict(int)
	for i in range(0, n, 2):
		a[temp[i]] += 1
	temp.sort()
	for i in range(0, n, 2):
		a[temp[i]] -= 1
	for x in a:
		if a[x]:
			print('NO\n')
			break
	else:
		print('YES\n')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	a_odd = [a[i] for i in range(n) if i % 2 == 1]
	a_odd.sort()
	b = sorted(a)
	b_odd = [b[i] for i in range(n) if i % 2 == 1]
	b_odd.sort()
	if a_odd == b_odd:
		print('YES')
	else:
		print('NO')


import sys, collections
tc = int(sys.stdin.readline())
for _ in range(tc):
	n = int(sys.stdin.readline())
	arr = list(map(int, sys.stdin.readline().split()))
	temp = sorted(arr)
	original = dict().fromkeys(set(arr))
	target = dict().fromkeys(set(arr))
	for i in original:
		original[i] = [[], []]
		target[i] = [[], []]
	for i in range(n):
		original[arr[i]][i % 2].append(i)
		target[temp[i]][i % 2].append(i)
	can = True
	for i in set(arr):
		if len(original[i][0]) != len(target[i][0]) or len(original[i][1]) != len(target[i][1]):
			can = False
			break
	print('YES' if can else 'NO')


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

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

def do_thing():
	n = int(input())
	alist = get_int_list()

	def badsim():
		evens = sorted([alist[i] for i in range(0, n, 2)])
		odds = sorted([alist[i] for i in range(1, n, 2)])
		ei = oi = 0
		last = float('-inf')
		while ei < len(evens):
			if last > evens[ei]:
				return 'NO'
			last = evens[ei]
			if oi < len(odds):
				if last > odds[oi]:
					return 'NO'
				last = odds[oi]
				oi += 1
			ei += 1
		return 'YES'

	def editorial():
		oddsc = Counter()
		evensc = Counter()
		for i in range(n):
			if i % 2 == 1:
				oddsc[alist[i]] += 1
			else:
				evensc[alist[i]] += 1
		alist.sort()
		for i in range(n):
			if i % 2 == 1:
				oddsc[alist[i]] -= 1
				if oddsc[alist[i]] < 0:
					return 'NO'
			else:
				evensc[alist[i]] -= 1
				if evensc[alist[i]] < 0:
					return 'NO'
		assert sum(oddsc.values()) == sum(evensc.values()) == 0
		return 'YES'
	r = badsim()
	return r

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


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	a = input().split()
	a = [int(x) for x in a]
	if sorted(a)[::2] == sorted(a[::2]):
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	m = max(arr)
	lst1 = [[0, 0] for i in range(m + 1)]
	for i in range(n):
		lst1[arr[i]][i % 2] += 1
	arr.sort()
	lst2 = [[0, 0] for i in range(m + 1)]
	for i in range(n):
		lst2[arr[i]][i % 2] += 1
	flag = 0
	for i in range(m + 1):
		if lst1[i][0] == lst2[i][0] and lst1[i][1] == lst2[i][1]:
			continue
		flag = -1
		break
	if flag == -1:
		print('NO')
	else:
		print('YES')


T = int(input())
for TT in range(T):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = a[:]
	b.sort()
	odd = {}
	even = {}
	for i in range(len(a)):
		if i % 2 == 0:
			if a[i] not in even:
				even[a[i]] = 0
			even[a[i]] += 1
			if b[i] not in even:
				even[b[i]] = 0
			even[b[i]] -= 1
		else:
			if a[i] not in odd:
				odd[a[i]] = 0
			odd[a[i]] += 1
			if b[i] not in odd:
				odd[b[i]] = 0
			odd[b[i]] -= 1
	ans = True
	for i in range(len(a)):
		flag = (a[i] not in odd or odd[a[i]] == 0) and (a[i] not in even or even[a[i]] == 0)
		if flag == False:
			ans = False
			break
	print('YES' if ans else 'NO')


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 main():
	pass

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

def decimal(s):
	return int(s, 2)

def pow2(n):
	p = 0
	while n > 1:
		n //= 2
		p += 1
	return p

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

def lts(l):
	s = ''.join(map(str, l))
	return s

def stl(s):
	l = list(s)
	return l

def sq(a, target, arr=[]):
	s = sum(arr)
	if s == target:
		return arr
	if s >= target:
		return
	for i in range(len(a)):
		n = a[i]
		remaining = a[i + 1:]
		ans = sq(remaining, target, arr + [n])
		if ans:
			return ans

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

def nCr(n, r):
	f = math.factorial
	return f(n) // f(r) // f(n - r)
mod = int(1000000000.0) + 7

def ssinp():
	return input()

def iinp():
	return int(input())

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

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

def p(xyz):
	print(xyz)

def p2(a, b):
	print(a, b)
import math
for ___ in range(int(input())):
	n = iinp()
	a = llinp()
	d1 = {}
	d2 = {}
	for i in range(n):
		if a[i] in d1:
			d1[a[i]][i % 2] += 1
		else:
			d1[a[i]] = [0, 0]
			d1[a[i]][i % 2] += 1
	a.sort()
	for i in range(n):
		if a[i] in d2:
			d2[a[i]][i % 2] += 1
		else:
			d2[a[i]] = [0, 0]
			d2[a[i]][i % 2] += 1
	ans = 'YES'
	for key in d1:
		if d1[key] != d2[key]:
			ans = 'NO'
			break
	print(ans)


import sys, os.path
from collections import defaultdict as dd
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')
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = [i for i in a]
	odd = dd(list)
	even = dd(list)
	for i in range(n):
		if i % 2:
			odd[a[i]].append(i)
		else:
			even[a[i]].append(i)
	b.sort()
	flag = True
	for i in range(n):
		if i % 2 == 0:
			if even[b[i]] == []:
				flag = False
				break
			else:
				even[b[i]].pop()
		elif odd[b[i]] == []:
			flag = False
			break
		else:
			odd[b[i]].pop()
	if flag:
		print('YES')
	else:
		print('NO')


from bisect import insort, bisect_right, bisect_left
from sys import stdout, stdin, setrecursionlimit
from math import sqrt, ceil, floor, factorial, gcd, log2, log10
from io import BytesIO, IOBase
from collections import *
from itertools import *
from random import *
from string import *
from queue import *
from heapq import heappush, heappop, heapify
from re import *
from os import *

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 = read(self._fd, max(fstat(self._fd).st_size, 8192))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

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

	def flush(self):
		if self.writable:
			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')
(stdin, stdout) = (IOWrapper(stdin), IOWrapper(stdout))
(graph, mod, szzz) = ({}, 10 ** 9 + 7, lambda : sorted(zzz()))

def getStr():
	return input()

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

def listStr():
	return list(input())

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

def isInt(s):
	return '0' <= s[0] <= '9'

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

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

def output(answer, end='\n'):
	stdout.write(str(answer) + end)

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def getPrimes(N=10 ** 5):
	SN = int(sqrt(N))
	sieve = [i for i in range(N + 1)]
	sieve[1] = 0
	for i in sieve:
		if i > SN:
			break
		if i == 0:
			continue
		for j in range(2 * i, N + 1, i):
			sieve[j] = 0
	prime = [i for i in range(N + 1) if sieve[i] != 0]
	return prime

def primeFactor(n, prime=getPrimes()):
	lst = []
	mx = int(sqrt(n)) + 1
	for i in prime:
		if i > mx:
			break
		while n % i == 0:
			lst.append(i)
			n //= i
	if n > 1:
		lst.append(n)
	return lst
dx = [-1, 1, 0, 0, 1, -1, 1, -1]
dy = [0, 0, 1, -1, 1, -1, -1, 1]
daysInMounth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
num = getInt()
for _ in range(num):
	n = getInt()
	arr = zzz()
	s = set(arr)
	d2 = {}
	d1 = {}
	for i in s:
		d1[i] = [0, 0]
	for i in s:
		d2[i] = [0, 0]
	for (i, j) in enumerate(arr):
		d1[j][i & 1] += 1
	for (i, j) in enumerate(sorted(arr)):
		d2[j][i & 1] += 1
	ans = 1
	for i in s:
		if d1[i] != d2[i]:
			ans = 0
	print('YES' if ans else 'NO')


import atexit, io, sys, collections, math, heapq, fractions, copy, os, functools
import sys
import random
import collections
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')
for u in range(int(input())):
	n = int(input())
	ais = list(map(int, input().split()))
	q = {0: [], 1: []}
	for (i, ai) in enumerate(ais):
		q[i & 1].append(ai)
	for i in range(2):
		q[i] = collections.deque(sorted(q[i]))
	for i in range(len(ais)):
		ais[i] = q[i & 1].popleft()
	print('YES' if sorted(ais) == ais else 'NO')


import sys
from sys import stdout
input = lambda : sys.stdin.readline().strip()
P = lambda : list(map(int, input().split()))
from math import factorial as f, gcd
from collections import deque, defaultdict as dd, Counter as C
from heapq import heapify, heappop, heappush, heappushpop, heapreplace, merge
from random import randint, choice, sample
import time
mod = 10 ** 9 + 7
a = ord('a')
start = time.time()

def fast_exp(x, exp):
	ans = 1
	base = x
	while exp:
		if exp & 1:
			ans *= base
		base *= base
		base %= mod
		ans %= mod
		exp >>= 1
	return ans

def countBits(n):
	count = 0
	while n:
		count += n & 1
		n >>= 1
	return count

def submasks(n):
	org = n
	while n:
		yield n
		n = n - 1 & org

def solve():
	n = int(input())
	l = P()
	if C([x for (i, x) in enumerate(l) if i % 2]) == C([x for (i, x) in enumerate(sorted(l)) if i % 2]):
		print('YES')
	else:
		print('NO')
tc = int(input())
for t in range(1, tc + 1):
	solve()


import os, sys
from io import BytesIO, IOBase
from math import log2, ceil, sqrt, gcd
from _collections import deque
import heapq as hp
from bisect import bisect_left, bisect_right
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
mod = 10 ** 9 + 7
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	ck1 = []
	ck2 = []
	for i in range(n):
		if i % 2:
			ck1.append(a[i])
		else:
			ck2.append(a[i])
	ck1.sort(reverse=True)
	ck2.sort(reverse=True)
	a.sort()
	ans = [0] * n
	for i in range(0, n, 2):
		ans[i] = ck2.pop()
	for i in range(1, n, 2):
		ans[i] = ck1.pop()
	if ans == a:
		print('YES')
	else:
		print('NO')


from __future__ import division, print_function
import os
import 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
MOD = 10 ** 9 + 7
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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

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

def main():
	for _ in range(int(input())):
		n = int(input())
		a = [*map(int, input().split())]
		b = a[:]
		b.sort()
		c = {}
		d = {}
		for i in range(n):
			c[a[i]] = c.get(a[i], [0, 0])
			if i % 2 == 0:
				c[a[i]][0] += 1
			else:
				c[a[i]][1] += 1
		for i in range(n):
			d[b[i]] = d.get(b[i], [0, 0])
			if i % 2 == 0:
				d[b[i]][0] += 1
			else:
				d[b[i]][1] += 1
		f = 0
		for i in range(n):
			if c[a[i]] != d[a[i]]:
				f = 1
		print('NO' if f else 'YES')
main()


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

def func(n, array):
	counter = {}
	for (i, val) in enumerate(array):
		if val in counter:
			counter[val][i % 2] = counter[val].get(i % 2, 0) + 1
		else:
			counter[val] = {i % 2: 1}
	sorted_indices = [i[0] for i in sorted(enumerate(array), key=lambda x: x[1])]
	for (new_i, i) in enumerate(sorted_indices):
		val = array[i]
		if new_i % 2 in counter[val] and counter[val][new_i % 2] > 0:
			counter[val][new_i % 2] -= 1
		else:
			return 'NO'
	return 'YES'

def main():
	num_test = int(parse_input())
	result = []
	for _ in range(num_test):
		n = int(parse_input())
		array = [int(i) for i in parse_input().split()]
		result.append(func(n, array))
	print('\n'.join(map(str, result)))
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))
parse_input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import collections
import sys

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

def map_inp(v_type):
	return map(v_type, inp().split())

def list_inp(v_type):
	return list(map_inp(v_type))
for _ in range(int(inp())):
	n = int(inp())
	arr = list_inp(int)
	dic1 = collections.defaultdict()
	dic2 = collections.defaultdict()
	temp_arr = list.copy(sorted(arr))
	for i in range(n):
		if arr[i] not in dic1:
			dic1[arr[i]] = [0, 0]
			if i & 1 == 0:
				dic1[arr[i]][0] += 1
			else:
				dic1[arr[i]][1] += 1
		elif i & 1 == 0:
			dic1[arr[i]][0] += 1
		else:
			dic1[arr[i]][1] += 1
		if temp_arr[i] not in dic2:
			dic2[temp_arr[i]] = [0, 0]
			if i & 1 == 0:
				dic2[temp_arr[i]][0] += 1
			else:
				dic2[temp_arr[i]][1] += 1
		elif i & 1 == 0:
			dic2[temp_arr[i]][0] += 1
		else:
			dic2[temp_arr[i]][1] += 1
	ans = 'YES'
	for item in arr:
		(a_even, b_even) = (dic1[item][0], dic2[item][0])
		(a_odd, b_odd) = (dic1[item][1], dic2[item][1])
		if a_even == b_even and a_odd == b_odd:
			continue
		else:
			ans = 'NO'
			break
	print(ans)


for u in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	a = [l[i] for i in range(n) if i % 2 == 0]
	a.sort()
	b = sorted(l)
	b = [b[i] for i in range(n) if i % 2 == 0]
	b.sort()
	if a == b:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	ans = 'YES'
	(even, odd) = ([], [])
	for i in range(n):
		if i & 1:
			odd.append(a[i])
		else:
			even.append(a[i])
	arr = [0] * n
	even.sort()
	odd.sort()
	for i in range(0, n, 2):
		arr[i] = even[i // 2]
		if i + 1 < n:
			arr[i + 1] = odd[(i + 1) // 2]
	a.sort()
	for i in range(n):
		if a[i] == arr[i]:
			continue
		else:
			ans = 'NO'
			break
	print(ans)


from collections import Counter, defaultdict
for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	ans = True
	b = sorted(a)
	pos = defaultdict(set)
	pos2 = defaultdict(set)
	for j in range(n):
		pos[a[j]].add(j)
		pos2[b[j]].add(j)
	for j in pos.keys():
		(e, o) = (0, 0)
		(x, y) = (0, 0)
		for k in pos[j]:
			if k % 2 == 0:
				e += 1
			else:
				o += 1
		for k in pos2[j]:
			if k % 2 == 0:
				x += 1
			else:
				y += 1
		if x != e and y != o:
			ans = False
			break
	if ans:
		print('Yes')
	else:
		print('No')


t = int(input())
for i in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	aodd = a[0::2]
	aeven = a[1::2]
	aodd.sort()
	aeven.sort()
	b = []
	for i in range(len(aodd)):
		b.append(aodd[i])
		if i < len(aeven):
			b.append(aeven[i])
	c = b.copy()
	c.sort()
	if b == c:
		print('YES')
	else:
		print('NO')