Ashish has $n$ elements arranged in a line. 

These elements are represented by two integers $a_i$ — the value of the element and $b_i$ — the type of the element (there are only two possible types: $0$ and $1$). He wants to sort the elements in non-decreasing values of $a_i$.

He can perform the following operation any number of times:  Select any two elements $i$ and $j$ such that $b_i \ne b_j$ and swap them. That is, he can only swap two elements of different types in one move. 

Tell him if he can sort the elements in non-decreasing values of $a_i$ after performing any number of operations.


-----Input-----

The first line contains one integer $t$ $(1 \le t \le 100)$ — the number of test cases. The description of the test cases follows.

The first line of each test case contains one integer $n$ $(1 \le n \le 500)$ — the size of the arrays.

The second line contains $n$ integers $a_i$ $(1 \le a_i \le 10^5)$  — the value of the $i$-th element.

The third line containts $n$ integers $b_i$ $(b_i \in \{0, 1\})$  — the type of the $i$-th element.


-----Output-----

For each test case, print "Yes" or "No" (without quotes) depending on whether it is possible to sort elements in non-decreasing order of their value.

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


-----Example-----
Input
5
4
10 20 20 30
0 1 0 1
3
3 1 2
0 1 1
4
2 2 4 8
1 1 1 1
3
5 15 4
0 0 0
4
20 10 100 50
1 0 0 1

Output
Yes
Yes
Yes
No
Yes



-----Note-----

For the first case: The elements are already in sorted order.

For the second case: Ashish may first swap elements at positions $1$ and $2$, then swap elements at positions $2$ and $3$.

For the third case: The elements are already in sorted order.

For the fourth case: No swap operations may be performed as there is no pair of elements $i$ and $j$ such that $b_i \ne b_j$. The elements cannot be sorted.

For the fifth case: Ashish may swap elements at positions $3$ and $4$, then elements at positions $1$ and $2$.

Difficulty: EASY
Tags: Implementation

Constructive algorithms

Starter code:

Solutions:
cases = int(input())
for case in range(cases):
	length = int(input())
	values = list(map(int, input().split()))
	types = list(map(int, input().split()))
	diff = False
	for (key, value) in enumerate(types):
		if types[key - 1] != types[key] and key != 0:
			diff = True
			break
	count = 0
	for (key, value) in enumerate(values):
		if value >= values[key - 1] and key != 0:
			count += 1
	if count + 1 != len(values) and (not diff):
		print('No')
	else:
		print('Yes')


for i in range(int(input())):
	length_of_values = int(input())
	values = list(map(int, input().split()))
	types = list(map(int, input().split()))
	count_of_1s = types.count(1)
	count_of_0s = types.count(0)
	if sorted(values) == values:
		print('Yes')
	elif count_of_0s == length_of_values:
		print('No')
	elif count_of_1s == length_of_values:
		print('No')
	else:
		print('Yes')


for i in range(int(input())):
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	l3 = l1.copy()
	l3.sort()
	if l3 == l1:
		print('Yes')
	elif l2.count(0) > 0 and l2.count(1) > 0:
		print('Yes')
	else:
		print('No')


from sys import stdin, setrecursionlimit, stdout
from collections import deque
from math import sqrt, floor, ceil, log, log2, log10, pi, gcd, sin, cos, asin

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

def fi():
	return float(stdin.readline())

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

def fmi():
	return map(float, stdin.readline().split())

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

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

def lsi():
	return list(si())
res = ['Yes', 'No']
test_case = ii()
while test_case:
	test_case -= 1
	n = ii()
	b = li()
	a = li()
	f = 0
	if (sum(a) == 0 or sum(a) == n) and b != sorted(b):
		f = 1
	print(res[f])


import math
import collections
from sys import stdin, stdout, setrecursionlimit
from bisect import bisect_left as bsl
from bisect import bisect_right as bsr
import heapq as hq
setrecursionlimit(2 ** 20)
t = int(stdin.readline())
for _ in range(t):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().rstrip().split()))
	b = list(map(int, stdin.readline().rstrip().split()))
	chk = True
	mx1 = 0
	mx2 = 0
	d = {}
	for i in range(n):
		d[b[i]] = True
		if b[i] == 1:
			if mx1 <= a[i]:
				mx1 = a[i]
			else:
				chk = False
		if b[i] == 0:
			if mx2 <= a[i]:
				mx2 = a[i]
			else:
				chk = False
	if not chk and len(d) == 1:
		print('No')
	else:
		print('Yes')


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	s = sum(b)
	if s == n or s == 0:
		if a == sorted(a):
			print('Yes')
		else:
			print('No')
	else:
		print('Yes')


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

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

def si():
	return input()

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

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

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

def dmain():
	sys.setrecursionlimit(100000000)
	threading.stack_size(40960000)
	thread = threading.Thread(target=main)
	thread.start()
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def getKey(item):
	return item[1]

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

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

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

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

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

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

def binary_search(arr, low, high, x):
	if high >= low:
		mid = (high + low) // 2
		if arr[mid] == x:
			return mid
		elif arr[mid] > x:
			return binary_search(arr, low, mid - 1, x)
		else:
			return binary_search(arr, mid + 1, high, x)
	else:
		return -1

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

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

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

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

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

def padded_bin_with_complement(x):
	if x < 0:
		return bin(2 ** 16 - abs(x))[2:].zfill(16)
	else:
		return bin(x)[2:].zfill(16)

def binaryToDecimal(binary):
	binary1 = binary
	(decimal, i, n) = (0, 0, 0)
	while binary != 0:
		dec = binary % 10
		decimal = decimal + dec * pow(2, i)
		binary = binary // 10
		i += 1
	print(decimal)

def CountFrequency(arr):
	return collections.Counter(arr)

def pos(a):
	b = [0] * len(a)
	c = sorted(a)
	for i in range(len(a)):
		for j in range(len(a)):
			if c[j] == a[i]:
				b[i] = j
				break
	return b

def smallestDivisor(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i * i <= n:
		if n % i == 0:
			return i
		i += 2
	return n

def commonn(a, b, n):
	c = []
	for i in range(n):
		if a[i] == b[i]:
			c.append('-1')
		else:
			c.append(b[i])
	return c

def main():
	for _ in range(ii()):
		n = ii()
		a = li()
		b = li()
		c = sorted(a)
		f = 0
		if a == c:
			print('Yes')
			continue
		elif len(set(b)) == 2:
			print('Yes')
		else:
			print('No')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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

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


n_test = int(input())
for _ in range(n_test):
	N = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	l = list(zip(l1, l2))
	l0 = [e[0] for e in l if e[1] == 0]
	l1 = [e[0] for e in l if e[1] == 1]
	if len(l0) == 0 and l1 != sorted(l1) or (len(l1) == 0 and l0 != sorted(l0)):
		print('No')
	else:
		print('Yes')


import sys
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
(t,) = I()
for _ in range(t):
	(n,) = I()
	a = I()
	b = I()
	an = sorted(a)
	if a == an:
		print('Yes')
	elif 1 not in b or 0 not in b:
		print('No')
	else:
		print('Yes')


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a2 = sorted(a)
	if (1 not in b or 0 not in b) and a2 != a:
		print('No')
	else:
		print('Yes')


import copy
for _ in range(int(input())):
	n = int(input())
	arr1 = list(map(int, input().split()))
	arr2 = list(map(int, input().split()))
	sort = True
	(zeros, ones) = (False, False)
	for i in range(1, n):
		if arr1[i] < arr1[i - 1]:
			sort = False
	for i in range(n):
		if arr2[i] == 1:
			ones = True
		else:
			zeros = True
	if zeros and ones:
		print('YES')
	elif sort:
		print('YES')
	else:
		print('NO')


n = 0
t = 0
t = int(input())
while not t == 0:
	t -= 1
	n = int(input())
	a = []
	b = []
	x = 0
	y = 0
	for i in range(0, 520):
		a.append(0)
		b.append(0)
	ai = input().split(' ')
	bi = input().split(' ')
	for i in range(0, n):
		a[i] = int(ai[i])
		b[i] = int(bi[i])
		if not i == 0:
			if a[i] < a[i - 1]:
				x += 1
		if not b[i] == b[0]:
			y += 1
	if y > 0 or x == 0:
		print('YES')
	else:
		print('NO')


def solveSort(a, b):
	for i in range(len(a) - 1):
		if a[i] > a[i + 1]:
			if len(set(b)) != 2:
				print('No')
				return
			else:
				print('Yes')
				return
	print('Yes')
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	solveSort(a, b)


t = int(input())

def solve(n, a, b):
	s = sum(b)
	if (s == 0 or s == n) and sorted(a) != a:
		ans = 'No'
	else:
		ans = 'Yes'
	return ans
answers = []
for i in range(t):
	n = int(input())
	(a, b) = [[int(j) for j in input().split()] for k in range(2)]
	ans = solve(n, a, b)
	answers.append(ans)
for i in answers:
	print(i)


def main():
	for _ in range(int(input())):
		n = int(input())
		a = list(map(int, input().split()))
		b = list(map(int, input().split()))
		a = list(enumerate(a))
		x = list(filter(lambda x: b[x[0]] == 0, a))
		y = list(filter(lambda x: b[x[0]] != 0, a))
		if len(x) > 0 and len(y) > 0 or ((len(x) == 0 or len(y) == 0) and a == sorted(a, key=lambda x: x[1])):
			print('Yes')
		else:
			print('No')
main()


for _ in range(int(input())):
	noe = int(input())
	a = [int(x) for x in input().split()]
	b = set([int(x) for x in input().split()])
	print('Yes' if len(b) > 1 or a == sorted(a) else 'No')


t = int(input())
output = []
for case in range(t):
	n = input()
	a_i = input().split()
	a_i = [int(a) for a in a_i]
	b_i = input().split()
	b_i = [int(b) for b in b_i]
	if len(set(b_i)) == 2:
		output.append('Yes')
	elif sorted(a_i) == a_i:
		output.append('Yes')
	else:
		output.append('No')
for total in output:
	print(total)


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if a == sorted(a):
		print('Yes')
		continue
	x = b.count(1)
	y = b.count(0)
	if x == 0 or y == 0:
		print('No')
		continue
	if x and y:
		print('Yes')


testing_mode = True
import sys, traceback
test_data = ''
final_output = ''

def input(input_format=0, multi=0):
	if multi > 0:
		return [input(input_format) for x in range(multi)]
	else:
		next_line = next(test_data, None).strip() if test_data else sys.stdin.readline()
		if input_format == 0:
			formatted_input = [next_line]
		elif input_format == 1:
			formatted_input = list(map(int, next_line.split()))
		elif input_format == 2:
			formatted_input = list(map(float, next_line.split()))
		elif input_format == 3:
			formatted_input = next_line.split()
		elif input_format == 4:
			formatted_input = (lambda x: [x[0], list(map(int, x[1:]))])(next_line.split())
		elif input_format == 5:
			formatted_input = (lambda x: [x[0], list(map(float, x[1:]))])(next_line.split())
		else:
			formatted_input = [next_line]
		return formatted_input

def log(*args):
	if testing_mode:
		print(*args)

def out(output_line, output_format=0, newline=True):
	global final_output
	formatted_output = ''
	if output_format == 0:
		formatted_output = str(output_line)
	elif output_format == 1:
		formatted_output = ' '.join(map(str, output_line))
	elif output_format == 1:
		formatted_output = '\n'.join(map(str, output_line))
	if testing_mode:
		final_output += formatted_output + '\n' * newline
	else:
		print(formatted_output, end='\n' if newline else '')
test_inputs = ['\n5\n4\n10 20 20 30\n0 1 0 1\n3\n3 1 2\n0 1 1\n4\n2 2 4 8\n1 1 1 1\n3\n5 15 4\n0 0 0\n4\n20 10 100 50\n1 0 0 1\n\n', '\n1\n1\n3 2\n1 1\n', '\n$$$\n', '\n$$$\n']
test_outputs = ['\nYes\nYes\nYes\nNo\nYes\n\n', '\n$$$\n', '\n$$$\n', '\n$$$\n']

def solve():
	for z in range(input(1)[0]):
		n = input(1)[0]
		a = input(1)
		b = input(1)
		e1 = False
		e2 = False
		for i in b:
			if i == 1:
				e1 = True
			elif i == 0:
				e2 = True
		if e1 and e2 or a == sorted(a):
			out('Yes')
		else:
			out('No')
	return

def run_all(overwrite_testing=False):
	global testing_mode, final_output, test_data
	testing_mode = overwrite_testing and testing_mode
	if testing_mode:
		tests_failed = 0
		for (test_number, (test_in, test_out)) in enumerate(zip(test_inputs, test_outputs)):
			final_output = ''
			if test_in.lstrip()[:3] == '$$$':
				continue
			test_data = iter([i for i in test_in.split('\n') if i])
			print(f'Test Case #{test_number + 1}:')
			print('<' * 20)
			fail = False
			verdict = '\x1b[92m\x1b[1mPASS\x1b[0m'
			try:
				solve()
				final = final_output.rstrip('\n')
				raw_out = iter(map(str, final.split('\n'))) if final else iter(())
			except Exception:
				raw_out = ''
				fail = True
				print('\x1b[95m')
				traceback.print_exc()
				print('\x1b[0m')
			if raw_out:
				if test_out.lstrip()[:3] == '$$$':
					verdict = '\x1b[94m\x1b[1mSKIP\x1b[0m'
					print('\x1b[94m' + '\n'.join(list(raw_out)) + '\x1b[0m')
				else:
					for line_out in [i for i in test_out.split('\n') if i]:
						line_raw = next(raw_out, '% None %')
						if line_raw == line_out.strip():
							print(f'\x1b[92m{line_raw}\x1b[0m')
						else:
							print(f'\x1b[91m{line_raw}\x1b[0m')
							fail = True
					line_raw = next(raw_out, None)
					while line_raw:
						print(f'\x1b[91m{line_raw}\x1b[0m')
						line_raw = next(raw_out, None)
						fail = True
			print('>' * 20)
			if fail:
				verdict = '\x1b[91m\x1b[1mFAIL\x1b[0m'
				tests_failed += 1
			print(verdict + '\n')
		if tests_failed:
			print(f"\x1b[91m\x1b[1m{tests_failed} TEST{('S' if tests_failed > 1 else '')} FAILED!\x1b[0m")
		else:
			print(f'\x1b[92m\x1b[1mALL TESTS PASSED!\x1b[0m')
	else:
		test_data = False
		solve()
run_all(False)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if 0 in b and 1 in b:
		print('Yes')
	else:
		for i in range(n - 1):
			if a[i + 1] < a[i]:
				print('No')
				break
		else:
			print('Yes')


numoftest = int(input())
result = []
for i in range(numoftest):
	testsize = int(input())
	num = [int(i) for i in input().split()]
	type = [int(i) for i in input().split()]
	sametype = False
	increasing = all((num[i] <= num[i + 1] for i in range(len(num) - 1)))
	if type[0] == 0:
		sametype = 1 not in type
	elif type[0] == 1:
		sametype = 0 not in type
	if not increasing and sametype:
		result.append('No')
	else:
		result.append('Yes')
for i in result:
	print(i)


t = int(input())
for i in range(t):
	n = int(input())
	lsta = list(map(int, input().split()))
	lstb = list(map(int, input().split()))
	lst1 = lsta.copy()
	lst1.sort()
	if 0 not in lstb or 1 not in lstb:
		if lst1 == lsta:
			print('Yes')
		else:
			print('No')
	else:
		print('Yes')


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

def solve():
	n = int(input())
	arr = list(map(int, input().split()))
	brr = list(map(int, input().split()))
	if arr == sorted(arr) or len(set(brr)) != 1:
		print('Yes')
	else:
		print('No')

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


t = int(input())
for _ in range(t):
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = set(map(int, input().split()))
	res = len(l2) > 1 or l1 == sorted(l1)
	print('Yes' if res else 'No')


for _ in range(int(input())):
	(n, a, b) = (int(input()), list(map(int, input().split())), list(map(int, input().split())))
	if 0 in b and 1 in b:
		print('Yes')
	elif a == sorted(a):
		print('Yes')
	else:
		print('No')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	s = sorted(a)
	if s == a:
		print('Yes')
	else:
		count = 0
		if 0 in b:
			count += 1
		if 1 in b:
			count += 1
		if count == 2:
			print('Yes')
		else:
			print('No')


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if len(set(b)) == 2:
		print('Yes')
	else:
		flag = 0
		for j in range(n - 1):
			if a[j] > a[j + 1]:
				print('No')
				flag = 1
				break
		if flag == 0:
			print('Yes')


def trouble(l, a, b):
	a0 = []
	a1 = []
	for i in range(l):
		if b[i] == 0:
			a0.append(a[i])
		else:
			a1.append(a[i])
	if len(a0) != 0 and len(a1) != 0:
		return 'Yes'
	elif len(a0) == 0:
		if a1 == sorted(a1):
			return 'Yes'
		else:
			return 'No'
	elif len(a1) == 0:
		if a0 == sorted(a0):
			return 'Yes'
		else:
			return 'No'
	else:
		return 'No'
t = int(input())
array = []
for k in range(t):
	a = int(input())
	b = list(map(int, input().split(' ')))
	c = list(map(int, input().split(' ')))
	array.append([a, b, c])
for x in array:
	print(trouble(*x))


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if sum(b) != 0 and sum(b) != n or a == sorted(a):
		print('YES')
	else:
		print('NO')


import sys
t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(c) for c in input().split()]
	b = [int(c) for c in input().split()]
	min_0 = min_1 = -float('inf')
	res = True
	diff_b = set(b)
	if len(diff_b) == 2:
		print('Yes')
		continue
	prev = a[0]
	res = True
	for i in range(1, n):
		v = a[i]
		if v < prev:
			res = False
			break
		prev = v
	print('Yes' if res else 'No')


for _ in range(int(input())):
	n = input()
	l = list(map(int, input().split()))
	p = set(map(int, input().split()))
	if sorted(l) == l:
		print('Yes')
	elif 1 in p and 0 in p:
		print('Yes')
	else:
		print('No')


t = int(input())

def TSort():
	n = int(input())
	a = list(map(int, input().split(' ')))
	b = list(map(int, input().split(' ')))
	one = False
	y = False
	flag = True
	for i in range(0, n):
		if i < n - 1:
			if a[i + 1] < a[i]:
				flag = False
		if b[i] == 0:
			one = True
		else:
			y = True
	if flag or (one and y):
		print('Yes')
	else:
		print('No')
for _ in range(t):
	TSort()


import copy
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	x = a.copy()
	x.sort()
	if x == a:
		print('Yes')
	else:
		(c, c0) = (b.count(1), b.count(0))
		if c and c0:
			print('Yes')
		else:
			print('No')


t = int(input())
while t:
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	m = a[:]
	m.sort()
	cnt = 0
	for i in range(n):
		if m[i] == a[i]:
			cnt += 1
	if cnt == n:
		print('Yes')
	else:
		cnt1 = 0
		cnt2 = 0
		for i in range(n):
			if b[i] == 1:
				cnt1 += 1
			else:
				cnt2 += 1
		if cnt2 != 0 and cnt1 != 0:
			print('Yes')
		else:
			print('No')
	t -= 1


t = int(input())
while t:
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if b.count(1) == 0 or b.count(0) == 0:
		if a == sorted(a):
			print('Yes')
		else:
			print('No')
	elif b.count(1) > 0 and b.count(0) > 0:
		print('Yes')
	t = t - 1


import math
from sys import stdin
from collections import Counter, defaultdict, deque
input = stdin.readline
mod = pow(10, 9) + 7

def solve():
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	l3 = l1.copy()
	l3.sort()
	if l1 == l3:
		print('YES')
		return
	sum1 = sum(l2)
	if sum1 == 0 or sum1 == n:
		print('NO')
	else:
		print('YES')
for _ in range(int(input())):
	solve()


for t in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	bc = b.count(0)
	if (bc == n or bc == 0) and a != sorted(a):
		print('NO')
	else:
		print('YES')


t = int(input())
while t > 0:
	n = int(input())
	a = list(map(int, input().strip().split()))[:n]
	b = list(map(int, input().strip().split()))[:n]
	y = 0
	for k in range(1, n):
		if a[k] < a[k - 1]:
			y = 1
			break
	if y == 0:
		print('Yes')
	else:
		flag1 = 0
		flag2 = 0
		for i in range(n):
			if b[i] == 0:
				flag1 = 1
				break
		for j in range(n):
			if b[j] == 1:
				flag2 = 1
				break
		if flag1 == 1 and flag2 == 1:
			print('Yes')
		else:
			print('No')
	t = t - 1


m = int(input())
for i in range(m):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	num0 = 0
	num1 = 0
	arr = []
	arr = sorted(a)
	for i in range(n):
		if b[i] == 0:
			num0 += 1
		else:
			num1 += 1
	t = 1
	for i in range(n):
		if arr[i] != a[i]:
			t = 0
			break
	if num0 == 0 or num1 == 0:
		if t:
			print('Yes')
		else:
			print('No')
	else:
		print('Yes')


def isPossible(arr1, arr2):
	n = len(arr1)
	isSorted = True
	for i in range(n - 1):
		if arr1[i] > arr1[i + 1]:
			isSorted = False
	num0s = 0
	num1s = 0
	for i in arr2:
		if i == 0:
			num0s += 1
		else:
			num1s += 1
	if isSorted or (num0s > 0 and num1s > 0):
		return 'YES'
	return 'NO'
numTestCases = int(input(''))
for t in range(numTestCases):
	temp = input('').strip().split()
	n = int(temp[0])
	temp = input('').strip().split()
	arr1 = list()
	arr2 = list()
	for i in range(n):
		arr1.append(int(temp[i]))
	temp = input('').strip().split()
	for i in range(n):
		arr2.append(int(temp[i]))
	print(isPossible(arr1, arr2))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = a[:]
	c.sort()
	fg = 0
	for i in range(0, n):
		if a[i] != c[i]:
			fg = 1
			break
	if fg == 0:
		print('Yes')
	else:
		d = b.count(0)
		e = b.count(1)
		if d == 0 or e == 0:
			print('No')
		else:
			print('Yes')


def main():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	summation = sum(b)
	if summation == n or summation == 0:
		flag = True
		for i in range(0, n - 1):
			if a[i] > a[i + 1]:
				flag = False
				break
		if flag:
			print('YES')
		else:
			print('NO')
	else:
		print('YES')
for t in range(int(input())):
	main()


t = int(input())
for t1 in range(0, t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = 0
	x = a[:]
	x.sort()
	if x == a:
		f = 1
	else:
		y = b.count(1)
		if b.count(0) > 0 and y > 0:
			f = 1
		else:
			f = 0
	if f == 0:
		print('No')
	else:
		print('Yes')


test = int(input())
for i in range(test):
	n = int(input())
	arr = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	arr_b = [[arr[i], b[i]] for i in range(n)]
	arr_b.sort(key=lambda x: x[0])
	k = 0
	ans = 'Yes'
	alpha = {(1, 0): 0, (0, 1): 0, (1, 1): 0, (0, 0): 0}
	for i in range(n):
		k = (b[i], arr_b[i][1])
		if k in alpha:
			alpha[k] += 1
	if alpha[1, 0] != alpha[0, 1]:
		print('No')
	elif alpha[1, 1] == n or alpha[0, 0] == n:
		if arr == [i[0] for i in arr_b]:
			print('Yes')
		else:
			print('No')
	else:
		print('Yes')


def f(vs: list, ts: list):
	if len(vs) <= 1:
		return 'Yes'
	if 1 in ts and 0 in ts:
		return 'Yes'
	cur = vs[0]
	for v in vs:
		if v < cur:
			return 'No'
		else:
			cur = v
	else:
		return 'Yes'
N = int(input())
for iii in range(N):
	n = int(input())
	vs = [int(x) for x in input().split()]
	ts = [int(x) for x in input().split()]
	print(f(vs, ts))


t = int(input())
for ii in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	types = list(map(int, input().split()))
	for i in range(1, n):
		if a[i] < a[i - 1]:
			break
	else:
		print('Yes')
		continue
	if 1 in types and 0 in types:
		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

def solve(t):
	n = int(input())
	data = list(map(int, input().split()))
	typs = list(map(int, input().split()))
	if len(data) == 1 or len(set(typs)) == 2:
		return 'Yes'
	lst = float('-inf')
	for num in data:
		if num < lst:
			return 'No'
		lst = num
	return 'Yes'

def main():
	tc = int(input().strip())
	for t in range(1, tc + 1):
		print(solve(t))
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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

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


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ao = a.copy()
	ao.sort()
	if len(list(set(b))) == 1:
		if a == ao:
			print('Yes')
		else:
			print('No')
	else:
		print('Yes')


def main():
	n = int(input())
	a = list(map(int, input().split()))
	arr = set(map(int, input().split()))
	if len(arr) != 1:
		print('Yes')
	else:
		for i in range(n - 1):
			if a[i] > a[i + 1]:
				print('No')
				return
		print('Yes')
		return
	return

def test():
	t = int(input())
	while t:
		main()
		t -= 1
test()


R = lambda : list(map(int, input().split()))

def troubleSort(n, a, b):
	if sorted(a) == a:
		return 'YES'
	if b.count(1) == n or b.count(0) == n:
		return 'NO'
	if b.count(1) >= 1 and b.count(0) >= 1:
		return 'YES'
	return 'NO'
for i in range(int(input())):
	n = int(input())
	a = R()
	b = R()
	print(troubleSort(n, a, b))


import sys
input = sys.stdin.readline
f = lambda : list(map(int, input().split()))
for _ in range(int(input())):
	n = input()
	a = f()
	b = f()
	s = sum(b)
	aa = sorted(a)
	if aa == a or 0 < s < len(b):
		print('YES')
	else:
		print('NO')


def can_move(n, a, b):
	var = 0
	for i in range(n - 1):
		if a[i] > a[i + 1]:
			var = 1
			break
	if var == 0:
		return 'Yes'
	if 1 not in b:
		return 'No'
	if 0 not in b:
		return 'No'
	return 'Yes'
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	print(can_move(n, a, b))


def canSort(a, b):
	isZero = False
	isOne = False
	for elm in b:
		if elm == 0:
			isZero = True
		else:
			isOne = True
		if isZero and isOne:
			return 'Yes'
	return 'Yes' if getString(a) == getString(sorted(a)) else 'No'

def getString(arr):
	return ''.join(map(str, arr))
t = int(input())
for _ in range(t):
	n = (int, input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	print(canSort(a, b))


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	d = []
	e = []
	for j in range(n):
		if b[j] == 0:
			d.append(a[j])
		else:
			e.append(a[j])
	if len(d) != 0 and len(e) != 0:
		print('Yes')
	elif len(d) == 0:
		j = 0
		f = 0
		while j < n - 1:
			if a[j] <= a[j + 1]:
				pass
			else:
				f = 1
				break
			j += 1
		if f == 0:
			print('Yes')
		else:
			print('No')
	elif len(e) == 0:
		j = 0
		f = 0
		while j < n - 1:
			if a[j] <= a[j + 1]:
				pass
			else:
				f = 1
				break
			j += 1
		if f == 0:
			print('Yes')
		else:
			print('No')


t = int(input())
for _ in range(t):
	n = int(input())
	array = list(map(int, input().split()))
	_type = list(map(int, input().split()))
	sorted_array = sorted(array)
	s = sum(_type)
	if sorted_array == array:
		print('Yes')
	elif s == 0 or s == n:
		print('No')
	else:
		print('Yes')


t = int(input())
for _ in range(t):
	n = int(input())
	A = [int(a) for a in input().split()]
	B = [int(b) for b in input().split()]
	sorted_A = sorted(A)
	if 0 in B and 1 in B or A == sorted_A:
		print('Yes')
	else:
		print('No')


t = int(input())
for _ in range(t):
	n = int(input())
	g = list(map(int, input().split()))
	m = list(map(int, input().split()))
	x = g[:]
	d = g[:]
	x.sort()
	if x == g:
		print('Yes')
		continue
	h1 = 0
	h2 = 0
	for ele in m:
		if ele == 1:
			h1 = 1
		else:
			h2 = 1
	if h1 == 1 and h2 == 1:
		print('Yes')
	else:
		print('No')


t = int(input())
for _ in range(t):
	n = int(input())
	arr = [int(c) for c in input().split()]
	s = [int(c) for c in input().split()]
	k = sorted(arr)
	if k == arr:
		print('Yes')
	elif len(set(s)) > 1:
		print('Yes')
	else:
		print('No')


t = int(input())
while t:
	t -= 1
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	x = b[0]
	h = 0
	for i in range(n):
		if b[i] != x:
			print('Yes')
			h = 1
			break
	if h == 1:
		continue
	for j in range(1, n):
		if a[j] < a[j - 1]:
			print('No')
			h = 1
			break
	if h == 0:
		print('Yes')


(z, zz) = (input, lambda : list(map(int, z().split())))
zzz = lambda : [int(i) for i in stdin.readline().split()]
(szz, graph, mod, szzz) = (lambda : sorted(zz()), {}, 10 ** 9 + 7, lambda : sorted(zzz()))
from string import *
from re import *
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f
from bisect import bisect as bs
from bisect import bisect_left as bsl
from itertools import accumulate as ac

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

def prime(x):
	p = ceil(x ** 0.5) + 1
	for i in range(2, p):
		if x % i == 0 and x != 2 or x == 0:
			return 0
	return 1

def dfs(u, visit, graph):
	visit[u] = True
	for i in graph[u]:
		if not visit[i]:
			dfs(i, visit, graph)
num = int(z())
for _ in range(num):
	n = int(z())
	l = zzz()
	t = zzz()
	one = t.count(1)
	if one >= 1 and n - one >= 1 or sorted(l) == l:
		print('yes')
	else:
		print('No')


t = int(input())
for k in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if len(set(b)) == 2:
		print('YES')
	else:
		flag = 0
		for i in range(n - 1):
			if a[i] > a[i + 1]:
				flag = 1
				break
		if flag == 0:
			print('YES')
		else:
			print('NO')


t = int(input())
while t != 0:
	n = int(input())
	arrA = list(map(int, input().split()))
	arrB = list(map(int, input().split()))
	result = 'Yes'
	countone = 0
	for i in range(n):
		if arrB[i] == 1:
			countone += 1
	if countone == 0 or countone == n:
		for i in range(n - 1):
			if arrA[i] > arrA[i + 1]:
				result = 'No'
				break
	print(result)
	t -= 1


from sys import stdin
input = stdin.readline

def check_sorted(a, n):
	for i in range(1, n):
		if a[i] < a[i - 1]:
			return False
	return True

def main():
	t = int(input())
	for __ in range(t):
		n = int(input())
		a = list(map(int, input().split()))
		b = list(map(int, input().split()))
		one = 0
		zero = 0
		if not check_sorted(a, n):
			for i in range(n):
				if b[i] == 1:
					one += 1
				else:
					zero += 1
			if one > 0 and zero > 0:
				print('Yes')
			else:
				print('No')
		else:
			print('Yes')
main()


def help():
	n = int(input())
	arr1 = list(map(int, input().split(' ')))
	arr2 = list(map(int, input().split(' ')))
	if arr2 == [0] * n:
		if arr1 == sorted(arr1):
			print('Yes')
		else:
			print('No')
	elif arr2 == [1] * n:
		if arr1 == sorted(arr1):
			print('Yes')
		else:
			print('No')
	else:
		print('Yes')
for _ in range(int(input())):
	help()


import sys
from math import log2, floor, ceil, sqrt
Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()

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

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

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

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 10 ** 9 + 7
for _ in range(int(ri())):
	n = int(ri())
	a = Ri()
	b = Ri()
	flag1 = False
	flag0 = False
	for i in b:
		if i == 1:
			flag1 = True
		else:
			flag0 = True
	if flag1 and flag0:
		Yes()
	else:
		arr = sorted(a)
		if a == arr:
			Yes()
		else:
			No()


def solve(n, A, B):
	if A == sorted(A):
		return True
	if len(set(B)) == 2:
		return True
	return False

def main():
	T = int(input())
	for _ in range(T):
		n = int(input())
		A = list(map(int, input().split()))
		B = list(map(int, input().split()))
		print('Yes' if solve(n, A, B) else 'No')

def __starting_point():
	main()
__starting_point()


import collections

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

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

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

def isSorted(n, arr):
	for i in range(1, n):
		if arr[i] < arr[i - 1]:
			return False
	return True

def solve(n, arr, types):
	if isSorted(n, arr):
		return True
	typeAvailable = [0, 0]
	for t in types:
		typeAvailable[t] += 1
	if typeAvailable[0] > 0 and typeAvailable[1] > 0:
		return True
	return False
t = readInt()
for i in range(t):
	n = readInt()
	arr = readList()
	types = readList()
	print('Yes' if solve(n, arr, types) else 'No')


from pprint import pprint
from sys import stdin, stdout
from bisect import bisect_left, bisect_right

def product(l):
	c = 1
	for i in l:
		c *= i
	return c
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	typ = list(map(int, input().split()))
	a = sorted(arr)
	s = sum(typ)
	if 0 < s < len(arr) or a == arr:
		print('Yes')
	else:
		print('No')


import os
import sys
from io import BytesIO, IOBase
profile = 0
pypy = 1

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

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

def main():
	T = iin()
	ans = ['Vivek', 'Ashish']
	while T:
		T -= 1
		n = iin()
		a = lin()
		b = lin()
		if sorted(a) == a:
			print('Yes')
		else:
			c1 = b.count(1)
			c2 = n - c1
			if c1 and c2:
				print('Yes')
			else:
				print('No')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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


import sys
import math
import itertools
import functools
import collections
import operator
import fileinput
import copy
ORDA = 97

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

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

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

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

def revn(n):
	return str(n)[::-1]

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)

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

def divs(n, start=1):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True

def convn(number, base):
	newnumber = 0
	while number > 0:
		newnumber += number % base
		number //= base
	return newnumber

def cdiv(n, k):
	return n // k + (n % k != 0)

def ispal(s):
	for i in range(len(s) // 2 + 1):
		if s[i] != s[-i - 1]:
			return False
	return True
for _ in range(ii()):
	n = ii()
	a = li()
	b = li()
	sum_b = sum(b)
	f = True
	if sum_b == 0 or sum_b == n:
		for i in range(n - 1):
			if a[i] > a[i + 1]:
				f = False
				print('No')
				break
	if f:
		print('Yes')


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	N = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	zero = []
	one = []
	for i in range(N):
		if b[i]:
			one.append(a[i])
		else:
			zero.append(a[i])
	if a == sorted(a):
		print('Yes')
		continue
	if len(zero) > 0 and len(one) > 0:
		print('Yes')
		continue
	print('No')


t = int(input())
for case in range(t):
	n = int(input())
	a = [int(x) for x in input().split(' ')]
	b = [int(x) for x in input().split(' ')]
	if sorted(a) != a and len(set(b)) == 1:
		ans = 'No'
	else:
		ans = 'Yes'
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = a[:]
	c.sort()
	if a == c:
		print('Yes')
	elif b.count(0) == 0 or b.count(1) == 0:
		print('No')
	elif sorted(b) == c:
		print('No')
	else:
		print('Yes')


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = sum(b)
	d = list(a)
	d.sort()
	if 0 < c < n or a == d:
		print('Yes')
	else:
		print('No')


t = int(input())
for _ in range(t):
	n = int(input())
	a = []
	b = []
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	sorted = 1
	typ0 = 0
	typ1 = 0
	for i in range(n):
		if i > 0 and a[i] < a[i - 1]:
			sorted = 0
		if b[i] == 0:
			typ0 = 1
		else:
			typ1 = 1
	if typ0 == 1 and typ1 == 1:
		print('YES')
	elif sorted == 1:
		print('YES')
	else:
		print('NO')


for k in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if n == 1:
		print('Yes')
		continue
	i = 1
	while i < n:
		if b[i] != b[i - 1]:
			break
		i += 1
	if i >= n:
		kaiguan = 1
		for j in range(1, n):
			if a[j] < a[j - 1]:
				kaiguan = 0
				break
		if kaiguan:
			print('Yes')
		else:
			print('No')
	else:
		print('Yes')


t = int(input())
while t:
	t = t - 1
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	out = [i for i in a]
	out.sort()
	flag = 1
	for i in range(n):
		if a[i] != out[i]:
			flag = 0
			break
	if flag:
		print('Yes')
	else:
		s = set(b)
		flag = 1
		if len(s) == 1:
			flag = 0
		if flag:
			print('Yes')
		else:
			print('No')


t = int(input())
for k in range(t):
	num = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	sumb = sum(b)
	c = a.copy()
	if sorted(a) == a or 0 < sumb < num:
		print('Yes')
	else:
		print('No')


import sys, os
from io import BytesIO, IOBase
import collections, itertools, bisect, heapq, math, string
from decimal import *
BUFSIZE = 8192
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():
	t = int(input())
	for i in range(t):
		n = int(input())
		a = list(map(int, input().split()))
		sa = sorted(a)
		b = list(map(int, input().split()))
		if sa != a and (sum(b) == n or sum(b) == 0):
			print('No')
		else:
			print('Yes')
main()


t = int(input())
for i in range(t):
	s = int(input())
	ni = list(map(int, input().split()))
	nt = list(map(int, input().split()))
	if ni == sorted(ni):
		print('Yes')
	else:
		count_0 = nt.count(0)
		count_1 = s - count_0
		print('No' if min(count_0, count_1) == 0 else 'Yes')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	kk = []
	tttt = b.count(1)
	if tttt == 0 or tttt == n:
		if sorted(a) == a:
			print('Yes')
			continue
		else:
			print('No')
			continue
	for i in range(n):
		kk.append([a[i], b[i]])
	kk.sort()
	newb = [i[1] for i in kk]
	resb = []
	for i in range(n):
		resb.append(newb[i] ^ b[i])
	ans = resb.count(1)
	if ans % 2 == 0:
		print('Yes')
	else:
		print('No')


t = int(input())
for _ in range(t):
	n = int(input())
	a = input().split()
	a = [int(i) for i in a]
	b = input().split()
	b = [int(i) for i in b]
	prev = 0
	notsorted = False
	for j in a:
		if j < prev:
			notsorted = True
			break
		prev = j
	if b.count(0) > 0 and b.count(1) > 0:
		print('Yes')
	elif notsorted is False:
		print('Yes')
	else:
		print('No')


for _ in range(int(input())):
	n = int(input())
	elements = []
	elements.extend([int(i) for i in input().split()])
	copy_elements = list(elements)
	for i in range(n):
		elements[i] = [elements[i]]
	nexus = [int(i) for i in input().split()]
	for i in range(n):
		elements[i].append(nexus[i])
	if copy_elements == sorted(copy_elements):
		print('Yes')
	elif 0 not in nexus:
		print('No')
	elif 1 not in nexus:
		print('No')
	else:
		print('Yes')


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = []
	for i in range(n):
		c.append(a[i])
	c.sort()
	if a == c:
		print('Yes')
	elif 1 in b and 0 in b:
		print('Yes')
	else:
		print('No')


for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	(zero, one) = (b.count(0), b.count(1))
	if zero == n and a != sorted(a):
		print('No')
	elif one == n and a != sorted(a):
		print('No')
	else:
		print('Yes')


t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(num) for num in input().split(' ')]
	b = [int(num) for num in input().split(' ')]
	a_c = a.copy()
	a_c.sort()
	if a_c != a:
		if b.count(1) == n or b.count(0) == n:
			print('No')
		else:
			print('Yes')
	else:
		print('Yes')


from math import *
from collections import *
from operator import itemgetter
import bisect
from heapq import *
i = lambda : input()
ii = lambda : int(input())
iia = lambda : list(map(int, input().split()))
isa = lambda : list(input().split())
I = lambda : list(map(int, input().split()))
chrIdx = lambda x: ord(x) - 96
idxChr = lambda x: chr(96 + x)
t = ii()
for _ in range(t):
	n = ii()
	a = iia()
	b = iia()
	c = a.copy()
	c.sort()
	if (b.count(0) == n or b.count(1) == n) and c != a:
		print('No')
	else:
		print('Yes')


from sys import stdin, stdout
lis = lambda : list(map(int, input().split()))
Ma = lambda : map(int, input().split())
inte = lambda : int(input())
st = lambda : input()
import math
from collections import Counter
for i in range(inte()):
	n = inte()
	d = {}
	a = lis()
	b = lis()
	c = sorted(a)
	if c == a or len(set(b)) == 2:
		print('Yes')
	else:
		print('No')


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	m = []
	for i in range(n):
		m.append([a[i], i])
	m = sorted(m, key=lambda r: r[0])
	flag = 0
	for i in range(n):
		if m[i][0] != a[i]:
			flag = 1
	if flag == 0:
		print('Yes')
	else:
		k = b[0]
		flag = 0
		for i in range(n):
			if b[i] != k:
				flag = 1
		if flag == 1:
			print('Yes')
		else:
			print('No')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	b = ''.join(map(str, b))
	slis = sorted(a)
	if slis == a:
		print('Yes')
		continue
	if '0' in b and '1' in b:
		print('Yes')
	else:
		print('No')


import sys
import math as mt
input = sys.stdin.buffer.readline
import math as mt
t = int(input())
for __ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	b = list(map(int, input().split()))
	l1 = []
	for i in l:
		l1.append(i)
	l1.sort()
	b = set(b)
	if len(b) > 1:
		print('YES')
	elif l == l1:
		print('YES')
	else:
		print('NO')


import math
from collections import defaultdict, Counter, deque
INF = float('inf')

def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a

def primeFactor(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i ** 2 <= n:
		if n % i == 0:
			return i
		i += 1
	return n

def main():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	m = {1: 0, 0: 0}
	ans = sorted(a)
	for i in range(n):
		m[b[i]] += 1
	if (m[0] == 0 or m[1] == 0) and ans != a:
		print('No')
	else:
		print('Yes')
t = int(input())
for _ in range(t):
	main()


t = int(input())
for test in range(t):
	n = int(input())
	a = list(map(int, input().rstrip().split()))
	b = list(map(int, input().rstrip().split()))
	s = sum(b)
	if s > 0 and s < n:
		print('Yes')
	else:
		flag = True
		for i in range(n - 1):
			if a[i] > a[i + 1]:
				flag = False
		if flag:
			print('Yes')
		else:
			print('No')


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = []
	for i in range(n):
		c.append([a[i], b[i]])
	d = a[:]
	d.sort()
	if a == d:
		print('Yes')
	elif a != d and len(set(b)) == 1:
		print('No')
	elif len(set(b)) == 2:
		print('yes')


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	t = list(map(int, input().split()))
	if len(set(t)) == 2:
		print('Yes')
	else:
		l = []
		for i in range(n):
			l.append(arr[i])
		l.sort()
		c = 0
		for i in range(len(l)):
			if arr[i] == l[i]:
				continue
			else:
				c += 1
				break
		if c == 0:
			print('Yes')
		else:
			print('No')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if b.count(0) not in [0, n]:
		print('Yes')
	else:
		z = 1
		for i in range(n - 1):
			if a[i + 1] - a[i] < 0:
				z = 0
				break
		if z:
			print('Yes')
		else:
			print('No')


elem = int(input())
for i in range(elem):
	num = int(input())
	ar = []
	for i in input().split(' '):
		ar.append(int(i))
	ch = 0
	for i in range(len(ar) - 1):
		if ar[i] > ar[i + 1]:
			ch = 1
			break
	ar2 = []
	for i in input().split(' '):
		ar2.append(int(i))
	if ch == 0:
		print('Yes')
		continue
	if sum(ar2) == 0 or sum(ar2) == len(ar2):
		print('No')
	else:
		print('Yes')


import math
for w in range(int(input())):
	sc = input()
	n = list(map(int, input().split()))
	x = list(map(int, input().split()))
	aux = n.copy()
	aux.sort()
	if 0 not in x or 1 not in x:
		print('Yes' if aux == n else 'No')
	else:
		print('Yes')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	j = a.copy()
	a.sort()
	if 1 in b and 0 in b:
		print('Yes')
	elif j == a:
		print('Yes')
	else:
		print('No')


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if 0 in b and 1 in b:
		print('Yes')
	elif all((x <= y for (x, y) in zip(a[:-1], a[1:]))):
		print('Yes')
	else:
		print('No')


import collections

def eval(k, j):
	D = collections.defaultdict(int)
	i = 0
	while i < len(j):
		if j[i] == 1:
			D[1] += 1
		elif j[i] == 0:
			D[0] += 1
		if D[1] > 0 and D[0] > 0:
			return 'Yes'
		i += 1
	i = 1
	while i < len(k):
		if k[i - 1] <= k[i]:
			i += 1
		else:
			return 'No'
	return 'Yes'
for _ in range(int(input())):
	n = int(input())
	k = list(map(int, input().split()))
	j = list(map(int, input().split()))
	print(eval(k, j))


for _ in range(int(input())):
	n = int(input())
	in1 = list(map(int, input().split()))
	in2 = list(map(int, input().split()))
	if min(in2) != max(in2):
		print('Yes')
	elif list(sorted(in1)) == in1:
		print('Yes')
	else:
		print('No')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = 0
	if b.count(0) > 0:
		c += 1
	if b.count(1) > 0:
		c += 1
	if c == 2:
		print('Yes')
	else:
		for i in range(n - 1):
			if a[i] > a[i + 1]:
				print('No')
				break
		else:
			print('Yes')


def inp():
	ls = list(map(int, input().split()))
	return ls
t = int(input())
for ii in range(t):
	n = int(input())
	ls = inp()
	s = inp()
	if sorted(ls) == ls:
		print('yes')
	elif 0 in s and 1 in s:
		print('yes')
	else:
		print('no')


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	flag0 = 0
	flag1 = 0
	flag = 0
	for i in range(n):
		if b[i] == 0:
			flag0 = 1
		else:
			flag1 = 1
	for i in range(1, n):
		if a[i] < a[i - 1]:
			flag = 1
	if n == 1 or (flag0 == 1 and flag1 == 1) or flag == 0:
		print('Yes')
	else:
		print('No')


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

def solve():
	[n] = input_as_list()
	values = input_as_list()
	types = input_as_list()
	zero_type_values = set(map(lambda x: x[0], filter(lambda x: x[1] == 0, zip(values, types))))
	one_type_values = set(map(lambda x: x[0], filter(lambda x: x[1] == 1, zip(values, types))))
	if len(zero_type_values) > 0 and len(one_type_values) > 0:
		return 'Yes'
	s_values = sorted(values)
	for i in range(n):
		if s_values[i] != values[i]:
			return 'no'
	return 'Yes'
[tests] = input_as_list()
for _ in range(tests):
	print(solve())


import os
import sys
import io
import math
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
for t in range(int(input())):
	n = int(input())
	a = map(int, input().split())
	a = list(a)
	b = list(map(int, input().split()))
	if 0 not in b or 1 not in b:
		if a == sorted(a):
			print('Yes')
		else:
			print('No')
	else:
		print('Yes')


t = int(input())
for i in range(t):
	n = int(input())
	lista = input().split()
	binary = input().split()
	for j in range(n):
		lista[j] = int(lista[j])
	if lista == sorted(lista):
		print('Yes')
	elif '1' in binary and '0' in binary:
		print('Yes')
	else:
		print('No')


from math import *
from sys import stdin, stdout
input = stdin.buffer.readline
t = int(input())
while t > 0:
	n = int(input())
	ip1 = [int(x) for x in input().split()]
	ip2 = [int(x) for x in input().split()]
	a = []
	b = []
	one = 0
	zero = 0
	for i in range(n):
		if ip2[i] == 0:
			zero += 1
		else:
			one += 1
	flag = 0
	if zero == 0 or one == 0:
		for i in range(1, n):
			if ip1[i] < ip1[i - 1]:
				flag = 1
				break
	if flag == 1:
		print('NO')
	else:
		print('YES')
	t -= 1


for _ in range(int(input())):
	n = int(input())
	c = []
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	z = 0
	o = 0
	f = 0
	for i in a:
		c.append(i)
	c.sort()
	for i in range(n):
		if a[i] != c[i]:
			f = 1
	for i in b:
		if i == 0:
			z += 1
		if i == 1:
			o += 1
	if f == 0:
		print('Yes')
	elif o > 0 and z > 0:
		print('Yes')
	else:
		print('No')


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	l1 = list(map(int, input().split()))
	if l == list(sorted(l)) or len(set(l1)) == 2:
		print('Yes')
	else:
		print('No')


from collections import Counter
value = 10 ** 6
for t in range(int(input())):
	n = int(input())
	data = list(map(int, input().split()))
	b = list(map(int, input().split()))
	bc = Counter(b)
	flag = data == sorted(data)
	print('Yes' if flag or len(bc) > 1 else 'No')


for i in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	brr = list(map(int, input().split()))
	if arr == sorted(arr):
		print('Yes')
	elif 0 in brr and 1 in brr:
		print('Yes')
	else:
		print('No')


from collections import defaultdict as dd
import math
import sys
input = sys.stdin.readline

def nn():
	return int(input())

def li():
	return list(input())

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

def lm():
	return list(map(int, input().split()))
q = nn()
for _ in range(q):
	n = nn()
	l = lm()
	t = lm()
	if sum(t) == n or sum(t) == 0:
		s = True
		for i in range(n - 1):
			if l[i] > l[i + 1]:
				s = False
		if s:
			print('YES')
		else:
			print('NO')
	else:
		print('YES')


def solve():
	n = int(input())
	a = list(map(int, input().split()))
	t = list(map(int, input().split()))
	if len(set(t)) == 1:
		if sorted(a) == a:
			print('Yes')
		else:
			print('No')
	else:
		print('Yes')
for _ in range(int(input())):
	solve()


def solve():
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	(c0, c1) = (0, 0)
	for i in range(n):
		if b[i] == 0:
			c0 += 1
		elif b[i] == 1:
			c1 += 1
	if c0 == n or c1 == n:
		li = list(a)
		li.sort()
		if a == li:
			print('Yes')
		else:
			print('No')
	else:
		print('Yes')
t = int(input())
for i in range(t):
	solve()


def main():
	for _ in range(int(input())):
		n = int(input())
		a = list(map(int, input().split()))
		b = list(map(int, input().split()))
		l = a.copy()
		if min(b) == max(b):
			a.sort()
			if l == a:
				print('Yes')
			else:
				print('No')
		else:
			print('Yes')
main()


def main():
	for t in range(int(input())):
		n = int(input())
		a = list(zip(list(map(int, input().split())), list(map(int, input().split()))))
		cnt = [0, 0]
		for i in range(n):
			cnt[a[i][1]] += 1
		is_sorted = True
		for i in range(1, n):
			if a[i - 1][0] > a[i][0]:
				is_sorted = False
				break
		ans = 'Yes' if is_sorted or (not is_sorted and cnt[0] != 0 and (cnt[1] != 0)) else 'No'
		print(ans)
main()


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

def comb(n, c):
	return fact(n) // (fact(n - c) * c)
for _ in range(int(input())):
	n = int(input())
	nums = list(map(int, input().split()))
	tp = list(map(int, input().split()))
	m = 0
	yes1 = 0
	yes2 = 0
	done = False
	if nums == sorted(nums):
		done = True
	else:
		for i in range(n):
			if tp[i] == 1:
				yes1 = 1
			if tp[i] == 0:
				yes2 = 1
			if yes1 and yes2:
				done = True
				break
	if done:
		print('Yes')
	else:
		print('No')


case = int(input())
for t in range(case):
	n = int(input())
	f = 0
	anums = []
	bnums = []
	anums = input().split()
	for i in range(n):
		anums[i] = int(anums[i])
		if i > 0:
			if anums[i] < anums[i - 1]:
				f = 1
	(f1, f2) = (0, 0)
	bnums = input().split()
	for i in range(n):
		bnums[i] = int(bnums[i])
		if bnums[i]:
			f1 += 1
		else:
			f2 += 1
	if not f1 or not f2:
		if f:
			print('No')
		else:
			print('Yes')
	else:
		print('Yes')


for _ in range(int(input())):
	n = int(input())
	aa = list(map(int, input().split()))
	bb = set(map(int, input().split()))
	ans = len(bb) > 1 or aa == sorted(aa)
	print('Yes' if ans else 'No')


for _ in range(int(input())):
	n = int(input())
	arr = map(int, input().split())
	arr = list(arr)
	s = map(int, input().split())
	s = set(s)
	if len(s) == 2 or list(arr) == sorted(arr):
		print('YES')
	else:
		print('NO')


def read_int():
	return int(input())

def read_ints():
	return map(int, input().split(' '))
t = read_int()
for case_num in range(t):
	n = read_int()
	a = list(read_ints())
	b = list(read_ints())
	tot = sum(b)
	c = list(a)
	c.sort()
	if c == a:
		print('Yes')
	else:
		print('No' if tot == 0 or tot == n else 'Yes')


for _ in range(int(input())):
	x = int(input())
	lt = list(map(int, input().split()))
	mt = list(map(int, input().split()))
	if 0 not in mt or 1 not in mt:
		flag = 0
		for i in range(x - 1):
			if lt[i] > lt[i + 1]:
				flag = 2
				break
		if flag == 0:
			print('Yes')
		else:
			print('No')
	else:
		print('Yes')


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	b = list(map(int, input().split()))
	temp = arr[:]
	zeros = 0
	ones = 0
	for i in range(n):
		if b[i] == 0:
			zeros += 1
		else:
			ones += 1
	arr.sort()
	if arr == temp:
		print('Yes')
	elif zeros != 0 and ones != 0:
		print('Yes')
	else:
		print('No')


for _ in range(int(input())):
	n = int(input())
	a = [*map(int, input().split())]
	b = [*map(int, input().split())]
	cnt = b.count(1)
	if 1 <= cnt <= n - 1:
		print('Yes')
	elif sorted(a) == a:
		print('Yes')
	else:
		print('No')


from sys import stdin
input = stdin.readline
import bisect
import math
for xoxo in range(1):

	def check(c):
		d = sorted(c)
		if c == d:
			return True
		return False
	for _ in range(int(input())):
		n = int(input())
		a = list(map(int, input().split()))
		b = list(map(int, input().split()))
		x = b.count(0)
		if x == n or x == 0:
			if check(a):
				print('Yes')
			else:
				print('No')
		else:
			print('Yes')


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	binary = list(map(int, input().split()))
	ones = binary.count(1)
	if l == sorted(l) or 0 < ones < n:
		print('Yes')
	else:
		print('No')


T = int(input())
for _ in range(T):
	n = int(input())
	arr = list(map(int, input().split()))
	zr = list(map(int, input().split()))
	o = z = False
	st = True
	for i in range(1, n):
		if arr[i] < arr[i - 1]:
			st = False
			break
	for i in range(n):
		if zr[i] == 0:
			z = True
		if zr[i] == 1:
			o = True
	if st:
		print('Yes')
	elif o and z:
		print('Yes')
	else:
		print('No')


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	for i in range(n - 1):
		if a[i] > a[i + 1]:
			break
	else:
		print('Yes')
		continue
	print('No' if len(list(set(b))) < 2 else 'Yes')


import sys, bisect, string, math, time, functools, random, fractions
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
from itertools import permutations, combinations, groupby
rep = range

def Golf():
	(n, *t) = map(int, open(0).read().split())

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

def S_():
	return input()

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

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

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

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

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

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

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

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

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

def RA():
	return map(int, open(0).read().split())

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

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

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

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

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

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

def show(*inp, end='\n'):
	if show_flg:
		print(*inp, end=end)
YN = ['YES', 'NO']
Yn = ['Yes', 'No']
mo = 10 ** 9 + 7
inf = float('inf')
FourNb = [(-1, 0), (1, 0), (0, 1), (0, -1)]
EightNb = [(-1, 0), (1, 0), (0, 1), (0, -1), (1, 1), (-1, -1), (1, -1), (-1, 1)]
compas = dict(zip('WENS', FourNb))
cursol = dict(zip('LRUD', FourNb))
l_alp = string.ascii_lowercase
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
input = lambda : sys.stdin.readline().rstrip()

class Tree:

	def __init__(self, inp_size=None, ls=None, init=True, index=1):
		self.LCA_init_stat = False
		self.ETtable = []
		if init:
			if ls == None:
				self.stdin(inp_size, index=index)
			else:
				self.size = len(ls) + 1
				(self.edges, _) = GI(self.size, self.size - 1, ls, index=index)
		return

	def stdin(self, inp_size=None, index=1):
		if inp_size == None:
			self.size = int(input())
		else:
			self.size = inp_size
		(self.edges, _) = GI(self.size, self.size - 1, index=index)
		return

	def listin(self, ls, index=0):
		self.size = len(ls) + 1
		(self.edges, _) = GI(self.size, self.size - 1, ls, index=index)
		return

	def dfs(self, x, func=lambda pr, prv, nx, dist: prv + dist, root_v=0):
		q = deque([x])
		v = [None] * self.size
		v[x] = root_v
		while q:
			c = q.pop()
			for (nb, d) in self.edges[c]:
				if v[nb] == None:
					q.append(nb)
					v[nb] = func(c, v[c], nb, d)
		return v

	def bfs(self, x, func=lambda pr, prv, nx, dist: prv + dist, root_v=0):
		q = deque([x])
		v = [None] * self.size
		v[x] = root_v
		while q:
			c = q.popleft()
			for (nb, d) in self.edges[c]:
				if v[nb] == None:
					q.append(nb)
					v[nb] = func(c, v[c], nb, d)
		return v

	def parent(self, x):
		return self.dfs(0, func=lambda pr, prv, nx, dist: pr, root_v=-1)

	def topological_sort(self, x):
		tps = []
		q = deque([x])
		v = [None] * self.size
		v[x] = 0
		while q:
			c = q.popleft()
			tps.append(c)
			for (nb, d) in self.edges[c]:
				if v[nb] == None:
					q.append(nb)
					v[nb] = 0
		return tps

	def EulerTour(self, x):
		q = deque()
		q.append(x)
		self.depth = [None] * self.size
		self.depth[x] = 0
		self.ETtable = []
		self.ETdepth = []
		self.ETin = [-1] * self.size
		self.ETout = [-1] * self.size
		cnt = 0
		while q:
			c = q.pop()
			if c < 0:
				ce = ~c
			else:
				ce = c
				for (nb, d) in self.edges[ce]:
					if self.depth[nb] == None:
						q.append(~ce)
						q.append(nb)
						self.depth[nb] = self.depth[ce] + 1
			self.ETtable.append(ce)
			self.ETdepth.append(self.depth[ce])
			if self.ETin[ce] == -1:
				self.ETin[ce] = cnt
			else:
				self.ETout[ce] = cnt
			cnt += 1
		return

	def LCA_init(self, root):
		self.EulerTour(root)
		self.st = SparseTable(self.ETdepth, init_func=min, init_idl=inf)
		self.LCA_init_stat = True
		return

	def LCA(self, root, x, y):
		if self.LCA_init_stat == False:
			self.LCA_init(root)
		(xin, xout) = (self.ETin[x], self.ETout[x])
		(yin, yout) = (self.ETin[y], self.ETout[y])
		a = min(xin, yin)
		b = max(xout, yout, xin, yin)
		id_of_min_dep_in_et = self.st.query_id(a, b + 1)
		return self.ETtable[id_of_min_dep_in_et]

	def __str__(self):
		return str(self.edges)

	def show(self):
		if all([all([d == 1 for (nd, d) in edge]) for edge in self.edges]):
			print([[nd for (nd, d) in edge] for edge in self.edges])
		else:
			print(self)

class SparseTable:

	def __init__(self, ls, init_func=min, init_idl=float('inf')):
		self.func = init_func
		self.idl = init_idl
		self.size = len(ls)
		self.N0 = self.size.bit_length()
		self.table = [ls[:]]
		self.index = [list(range(self.size))]
		self.lg = [0] * (self.size + 1)
		for i in range(2, self.size + 1):
			self.lg[i] = self.lg[i >> 1] + 1
		for i in range(self.N0):
			tmp = [self.func(self.table[i][j], self.table[i][min(j + (1 << i), self.size - 1)]) for j in range(self.size)]
			tmp_id = [self.index[i][j] if self.table[i][j] == self.func(self.table[i][j], self.table[i][min(j + (1 << i), self.size - 1)]) else self.index[i][min(j + (1 << i), self.size - 1)] for j in range(self.size)]
			self.table += [tmp]
			self.index += [tmp_id]

	def query(self, l, r):
		if r > self.size:
			r = self.size
		N = self.lg[r - l]
		return self.func(self.table[N][l], self.table[N][max(0, r - (1 << N))])

	def query_id(self, l, r):
		if r > self.size:
			r = self.size
		N = self.lg[r - l]
		(a, b) = (self.index[N][l], self.index[N][max(0, r - (1 << N))])
		if self.table[0][a] == self.func(self.table[N][l], self.table[N][max(0, r - (1 << N))]):
			b = a
		return b

	def right_bound(self, pos, x):
		k = (self.size - pos).bit_length()
		for j in range(k)[::-1]:
			nx = pos + (1 << j)
			if nx < n and self.query(pos, nx + 1) <= x:
				pos += 1 << j
		return pos

	def left_bound(self, pos, x):
		k = pos.bit_length()
		for j in range(k)[::-1]:
			nx = pos - (1 << j)
			if 0 <= nx and self.query(nx, pos + 1) <= x:
				pos -= 1 << j
		return pos

	def __str__(self):
		return str(self.table[0])

	def print(self):
		for i in self.table:
			print(*i)
show_flg = False
show_flg = True
ans = 0
for _ in range(I()):
	ans = 0
	n = I()
	a = LI()
	b = LI()
	B = sum(b)
	if 0 < B < n:
		ans = 0
	elif sorted(a) != a:
		ans = 1
	else:
		ans = 0
	print(Yn[ans])


for _ in range(int(input())):
	_ = input()
	ls = list(map(int, input().split()))
	type = input().split()
	possible = False
	if not min(type.count('1'), type.count('0')):
		if ls == sorted(ls):
			possible = True
	else:
		possible = True
	print('Yes') if possible else print('No')


t = int(input())
for _ in range(t):
	n = int(input())
	list1 = list(map(int, input().strip().split()))
	list2 = list(map(int, input().strip().split()))
	b = 1
	b0 = 0
	b1 = 0
	for value in list2:
		if value == 0:
			b0 = 1
		if value == 1:
			b1 = 1
	for i in range(len(list1) - 1):
		if list1[i + 1] < list1[i]:
			b = 0
			break
	if b == 1:
		print('Yes')
	elif b0 == 0 or b1 == 0:
		print('No')
	else:
		print('Yes')


from sys import stdin, stdout
import math, queue, heapq
fastinput = stdin.readline
fastout = stdout.write
t = int(input())
while t:
	t -= 1
	n = int(fastinput())
	a = list(map(int, fastinput().split()))
	b = list(map(int, fastinput().split()))
	c = a.copy()
	a.sort()
	c1 = b.count(1)
	if a == c:
		print('Yes')
	elif c1 == n or c1 == 0:
		print('No')
	else:
		print('Yes')


t = int(input())
for i in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	if a == sorted(a):
		print('Yes')
	elif sum(b) != n and sum(b) != 0:
		print('Yes')
	else:
		print('No')


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if 0 not in b or 1 not in b:
		if all((a[i] <= a[i + 1] for i in range(n - 1))):
			print('Yes')
		else:
			print('No')
	else:
		print('Yes')


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	tem = list(map(int, input().split()))
	if arr == sorted(arr):
		print('Yes')
	elif len(set(tem)) == 1:
		print('No')
	else:
		print('Yes')


for _ in range(int(input())):
	n = int(input())
	values = list(map(int, input().split()))
	types = list(map(int, input().split()))
	s = set(types)
	if len(s) > 1 or values == sorted(values):
		print('Yes')
	else:
		print('No')


t = int(input())
for test in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if a == sorted(a):
		print('Yes')
	else:
		zert = onet = 0
		for i in range(n):
			if b[i] == 0:
				zert += 1
			else:
				onet += 1
		if zert >= 1 and onet >= 1:
			print('Yes')
		else:
			print('No')


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import ceil, floor, gcd, sqrt, trunc, inf
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
mod = pow(10, 9) + 7
mod2 = 998244353

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

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

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

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

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
for _ in range(int(data())):
	n = int(data())
	a = l()
	b = l()
	s = a[:]
	s.sort()
	if a == s:
		out('YES')
		continue
	if b.count(0) and b.count(1):
		out('YES')
		continue
	out('NO')


from sys import stdin, stdout
from math import *
from heapq import *
from collections import *

def main():
	ntest = int(stdin.readline())
	for testcase in range(ntest):
		n = int(stdin.readline())
		a = [int(k) for k in stdin.readline().split()]
		b = [int(k) for k in stdin.readline().split()]
		nondec = True
		for i in range(1, n):
			if a[i - 1] > a[i]:
				nondec = False
				break
		if nondec or len(set(b)) > 1:
			stdout.write('Yes\n')
		else:
			stdout.write('No\n')
	return 0
main()


from sys import stdin
tt = int(stdin.readline())
for loop in range(tt):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	b = list(map(int, stdin.readline().split()))
	dic = {}
	for i in range(n):
		if b[i] not in dic:
			dic[b[i]] = []
		dic[b[i]].append(a[i])
	ans = 'Yes'
	if len(dic) == 2:
		print(ans)
		continue
	for i in dic:
		for j in range(len(dic[i]) - 1):
			if dic[i][j] > dic[i][j + 1]:
				ans = 'No'
				break
		else:
			continue
		break
	print(ans)


import math

def i():
	return int(input())

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

def lis():
	return list(input())
t = i()
for _ in range(t):
	n = i()
	(a, b) = (lii(), lii())
	if a == sorted(a) or (b.count(1) < n and b.count(1) > 0):
		print('YES')
	else:
		print('NO')


num = int(input())
for k in range(num):
	n = int(input())
	t1 = t2 = t3 = 0
	a = []
	a = list(map(int, input().split()))
	for i in range(n):
		if i >= 1 and a[i] < a[i - 1]:
			t1 = 1
			break
	b = []
	b = list(map(int, input().split()))
	for i in range(n):
		if b[i] != 0:
			t3 = 1
			if t2 == 1:
				break
		else:
			t2 = 1
			if t3 == 1:
				break
	if (t3 == 0 or t2 == 0) and t1 == 1:
		print('No')
	else:
		print('Yes')


for i in range(0, int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	p = a[:]
	p.sort()
	w = b.count(0)
	y = b.count(1)
	if (w == n or y == n) and p != a:
		print('No')
	else:
		print('Yes')


import sys
import math
sys.setrecursionlimit(1000000)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')
p2S = lambda x: print(*x, sep=' ')

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

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

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

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

def SI():
	return sys.stdin.readline()[:-1]

def main():
	_v_ = II()
	for _ in range(_v_):
		n = II()
		ins = LI()
		s = LI()
		(a, b) = (False, False)
		c = True
		for i in s:
			if i == 0:
				a = True
			else:
				b = True
		ins1 = ins[0]
		for i in ins:
			if ins1 > i:
				c = False
				break
			ins1 = i
		if a == True and b == True or c == True:
			print('Yes')
		else:
			print('No')
main()


from sys import stdin, stdout
from collections import Counter, defaultdict
import math

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

def readString():
	return stdin.readline()[:-1]

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

def readListStr():
	return list(map(str, stdin.readline().split()))

def nextLine():
	stdout.write('\n')

def show(x):
	stdout.write(str(x) + '\n')

def showInline(x):
	stdout.write(str(x))

def showList(x):
	for i in x:
		stdout.write(str(i) + ' ')
	nextLine()

def show2D(x):
	for i in range(len(x)):
		for j in range(len(x[0])):
			stdout.write(str(x[i][j]) + ' ')
		nextLine()

def emptyList(length, value=-1):
	return [value] * length

def empty2D(row, col, val=-1):
	return [[val for i in range(col)] for j in range(row)]

def isSquare(x):
	if x ** 0.5 * 10 % 10 == 0:
		return 1
	return 0

def isLog(val, base):
	a = math.log(val, base)
	if a * 10 % 10 == 0:
		return 1
	else:
		return 0

def solve():
	for testcases in range(readInt()):
		n = readInt()
		a = readListInt()
		b = readListInt()
		a1 = sorted(a)
		b1 = sum(b)
		if a1 == a or (b1 != 0 and b1 != n):
			show('Yes')
		else:
			show('No')
solve()


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	bit = list(map(int, input().split()))
	if sorted(l) == l:
		print('Yes')
	else:
		zero = 0
		one = 0
		for i in range(n):
			if bit[i] == 1:
				one += 1
			else:
				zero += 1
		if zero > 0 and one > 0:
			print('Yes')
		else:
			print('No')


(z, zz) = (input, lambda : list(map(int, z().split())))
mod = 10 ** 9 + 7
from string import *
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f

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

def prime(x):
	p = ceil(x ** 0.5) + 1
	for i in range(2, p):
		if x % i == 0:
			return 0
	return 1
n = int(z())
for _ in range(n):
	n = int(z())
	l = zz()
	l2 = sorted(l)
	l3 = z()
	if l3.count('1') >= 1 and l3.count('0') >= 1 or l2 == l:
		print('Yes')
	else:
		print('No')


t = int(input())
while t:
	if t == 0:
		break
	t -= 1
	n = int(input())
	x = input()
	x = x.split()
	x = [int(y) for y in x]
	a = x
	x = input()
	x = x.split()
	x = [int(y) for y in x]
	b = x
	count = 0
	for i in range(n):
		count += b[i]
	if (count == 0 or count == n) and sorted(a) != a:
		print('No')
	else:
		print('Yes')


def isSorted(value_arr):
	for i in range(len(value_arr) - 1):
		if value_arr[i + 1] >= value_arr[i]:
			continue
		else:
			return False
	return True
for _ in range(int(input())):
	n = int(input())
	values = list(map(int, input().split()))
	types = list(map(int, input().split()))
	if isSorted(values):
		print('Yes')
	elif 0 in types and 1 in types:
		print('Yes')
	else:
		print('No')


I = input
t = int(I())
for tt in range(t):
	n = int(I())
	a = list((int(x) for x in I().strip().split()))
	b = list((int(x) for x in I().strip().split()))
	c0 = b.count(0)
	c1 = b.count(1)
	if c0 > 0 and c1 > 0:
		print('YES')
	else:
		fg = 1
		for i in range(n - 1):
			if a[i] > a[i + 1]:
				fg = 0
				break
		if fg == 1:
			print('YES')
		else:
			print('NO')


import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
import sys

def solve(n, A, B):
	if n == 1:
		return 'Yes'
	if len(B) == 2:
		return 'Yes'
	C = sorted(A)
	for (a, c) in zip(A, C):
		if a != c:
			return 'No'
	return 'Yes'

def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		A = list(map(int, input().split()))
		B = set(map(int, input().split()))
		ans = solve(n, A, B)
		sys.stdout.write(ans + '\n')
main()


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if b.count(1) > 0 and b.count(0) > 0 or sorted(a) == a:
		print('YES')
	else:
		print('NO')


from sys import stdin, gettrace
if gettrace():
	inputi = input
else:

	def input():
		return next(stdin)[:-1]

	def inputi():
		return stdin.buffer.readline()

def main():

	def solve():
		n = int(inputi())
		aa = [int(a) for a in inputi().split()]
		bb = [int(a) for a in inputi().split()]
		if 0 < sum(bb) < n:
			print('Yes')
			return
		for i in range(n - 1):
			if aa[i] > aa[i + 1]:
				print('No')
				return
		print('Yes')
	q = int(inputi())
	for _ in range(q):
		solve()
main()


T = int(input())

def ans(A, B):
	arr = list(zip(A, B))
	zeroes = [a for (a, b) in arr if b == 0]
	ones = [a for (a, b) in arr if b == 1]
	if len(ones) > 0 and len(zeroes) > 0:
		return 'Yes'
	if len(ones) > 0:
		if sorted(ones) == ones:
			return 'Yes'
		return 'No'
	if len(zeroes) > 0:
		if sorted(zeroes) == zeroes:
			return 'Yes'
		return 'No'
	assert False
for t in range(T):
	N = int(input())
	A = input().split(' ')
	A = [int(x) for x in A]
	B = input().split(' ')
	B = [int(x) for x in B]
	print(ans(A, B))


def solve(nums, types):
	sorted = True
	for i in range(1, len(nums)):
		if nums[i] < nums[i - 1]:
			sorted = False
			break
	if sorted:
		return True
	if not sorted:
		s = set(types)
		if len(s) == 1:
			return False
		else:
			return True
t = int(input())
for _ in range(t):
	input()
	nums = list(map(int, input().split()))
	types = list(map(int, input().split()))
	if solve(nums, types):
		print('Yes')
	else:
		print('No')


def good(arr, n):
	for i in range(n - 1):
		if arr[i + 1] < arr[i]:
			return False
	return True

def solve(a_vals, b_vals, n, ans):
	zero = 0
	one = 0
	for b in b_vals:
		if b == 0:
			zero += 1
		else:
			one += 1
	if zero == n or one == n:
		if good(a_vals, n):
			ans.append('Yes')
			return
		ans.append('No')
	else:
		ans.append('Yes')

def main():
	t = int(input())
	ans = []
	for i in range(t):
		n = int(input())
		a_vals = list(map(int, input().split()))
		b_vals = list(map(int, input().split()))
		solve(a_vals, b_vals, n, ans)
	for i in ans:
		print(i)
main()


t = int(input())
for q in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	if 1 in b and 0 in b:
		print('Yes')
	else:
		q = sorted(a)
		if a == q:
			print('Yes')
		else:
			print('No')


t = int(input())
while t:
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	(check1, check2) = (False, False)
	for i in b:
		if i == 0:
			check1 = True
		elif i == 1:
			check2 = True
	if check1 and check2 or a == sorted(a):
		print('Yes')
	else:
		print('No')
	t -= 1


n = int(input())
a = []
b = []
for i in range(0, n):
	x = int(input())
	s = 0
	s0 = 0
	s1 = 0
	a = list(map(int, input().split()))
	for j in range(0, x):
		if j >= 1 and a[j] < a[j - 1]:
			s = 1
	b = list(map(int, input().split()))
	for i in range(0, x):
		if b[i] != 0:
			s1 = 1
		else:
			s0 = 1
	if s1 and s0:
		print('Yes')
	elif s == 0:
		print('Yes')
	else:
		print('No')


for _ in range(int(input())):
	n = int(input())
	a = []
	b = []
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	print('nO' if b.count(1) % n == 0 and a != sorted(a) else 'YeS')


def solve():
	for _ in range(int(input())):
		n = int(input())
		la = list(map(int, input().strip().split()))
		a = la[:]
		a.sort()
		lb = list(map(int, input().strip().split()))
		if lb.count(1) == 0 or lb.count(0) == 0:
			if a == la:
				print('Yes')
			else:
				print('No')
			continue
		elif lb.count(1) > 0 and lb.count(0) > 0:
			print('Yes')
solve()


def isSorted(a):
	for i in range(len(a) - 1):
		if a[i] > a[i + 1]:
			return False
	return True
t = int(input())
for _ in range(t):
	n = int(input())
	vals = [int(i) for i in input().split()]
	types = [int(i) for i in input().split()]
	typeA = 0
	for i in types:
		if i == 0:
			typeA += 1
	if typeA == 0 or typeA == n:
		if isSorted(vals):
			print('Yes')
		else:
			print('No')
	else:
		print('Yes')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if a == sorted(a):
		print('YES')
	elif b.count(1) >= 1 and b.count(0) >= 1:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(j) for j in input().split()]
	b = [int(j) for j in input().split()]
	if b.count(b[0]) == len(b):
		flag = 0
		for i in range(n - 1):
			if a[i] > a[i + 1]:
				flag = 1
				break
		if flag == 1:
			print('No')
		else:
			print('Yes')
	else:
		print('Yes')


for _ in range(int(input())):
	n = int(input())
	value = [int(x) for x in input().split()]
	group = [int(x) for x in input().split()]
	temp = value.copy()
	value.sort()
	if temp == value:
		print('Yes')
	elif len(set(group)) == 2:
		print('Yes')
	else:
		print('No')


t = int(input())
for i in range(t):
	n = int(input())
	a = input().split()
	b = input().split()
	arr = []
	c1 = 0
	c2 = 0
	for i in range(len(a)):
		c = [int(a[i]), int(b[i])]
		if int(b[i]) == 0:
			c1 += 1
		elif int(b[i]) == 1:
			c2 += 1
		arr.append(c)
	bulflag = True
	l = len(arr)
	for i in range(l - 1):
		if arr[i][0] > arr[i + 1][0]:
			bulflag = False
	if c1 > 0 and c2 > 0:
		print('Yes')
	elif bulflag == True:
		print('Yes')
	else:
		print('No')


t = int(input())
for test in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if n == 1:
		print('Yes')
	elif len(set(b)) == 2:
		print('Yes')
	else:
		a1 = list(a)
		a1.sort()
		if a1 == a:
			print('Yes')
		else:
			print('No')


from collections import Counter

def main():
	T = int(input())
	for _ in range(T):
		N = int(input())
		A = list(map(int, input().split()))
		B = list(map(int, input().split()))
		sortedA = sorted(A)
		if A == sortedA:
			print('Yes')
		else:
			d = Counter(B)
			if 0 in d and 1 in d:
				print('Yes')
			else:
				print('No')
main()


for i in range(int(input())):
	a = int(input())
	b = list(map(int, input().strip().split()))[:a]
	c = list(map(int, input().strip().split()))[:a]
	g = []
	for n in b:
		g.append(n)
	g.sort()
	if b == g:
		print('Yes')
	elif c.count(1) != 0 and c.count(0) != 0:
		print('Yes')
	else:
		print('NO')


from sys import stdin, stdout
import copy

def main():
	t = int(stdin.readline())
	ans = [None for i in range(t)]
	for q in range(t):
		n = int(stdin.readline())
		a = [int(x) for x in stdin.readline().split()]
		b = [int(x) for x in stdin.readline().split()]
		k = copy.deepcopy(a)
		c = copy.deepcopy(a)
		c.sort()
		if c == k:
			ans[q] = 'YES'
		elif 0 in b and 1 in b:
			ans[q] = 'YES'
		else:
			ans[q] = 'NO'
	for i in range(t):
		print(ans[i])
main()


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	b = set(b)
	if len(b) == 1:
		if a == sorted(a):
			print('Yes')
		else:
			print('No')
	else:
		print('Yes')


def solve(n, a, b):
	present = [False, False]
	for i in range(n):
		if b[i]:
			present[1] = True
		else:
			present[0] = True
	if present[0] and present[1]:
		return True
	last = 0
	for i in range(n):
		v = a[i]
		if v < last:
			return False
		last = v
	return True
t = int(input())
for i_t in range(t):
	n = int(input())
	a = list(map(int, input().split(' ')))
	b = list(map(int, input().split(' ')))
	print('Yes' if solve(n, a, b) else 'No')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if a == sorted(a) or len(a) == 1 or (b.count(1) and b.count(0)):
		print('Yes')
	else:
		print('No')


t = int(input())
for q in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	bool_sort = True
	bool_two = False
	for i in range(1, n):
		if a[i] < a[i - 1]:
			bool_sort = False
		if b[i] != b[i - 1]:
			bool_two = True
	if bool_sort or bool_two:
		print('Yes')
	else:
		print('No')


import sys
import math
import heapq
import collections

def inputnum():
	return int(input())

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

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

def inputstring():
	return [x for x in input()]

def inputmatrixchar(rows):
	arr2d = [[j for j in input().strip()] for i in range(rows)]
	return arr2d

def inputmatrixint(rows):
	arr2d = []
	for _ in range(rows):
		arr2d.append([int(i) for i in input().split()])
	return arr2d
t = int(input())
for q in range(t):
	n = inputnum()
	a = inputlist()
	b = inputlist()
	has1 = False
	has0 = False
	for i in range(n):
		if b[i] == 1:
			has1 = True
		if b[i] == 0:
			has0 = True
	if has1 and has0:
		print('Yes')
		continue
	increasing = True
	for i in range(1, n):
		if a[i] < a[i - 1]:
			increasing = False
	if increasing:
		print('Yes')
		continue
	print('No')


T = int(input())
while T > 0:
	n = int(input())
	a = [int(a) for a in input().split()]
	b = [int(b) for b in input().split()]
	ck = True
	i = 0
	while i < n - 1:
		if a[i] > a[i + 1]:
			ck = False
			break
		i += 1
	if ck == True:
		print('Yes')
	else:
		zero = 0
		one = 0
		i = 0
		while i < n:
			if b[i] == 0:
				zero += 1
			else:
				one += 1
			i += 1
		if one > 0 and zero > 0:
			print('Yes')
		else:
			print('No')
	T -= 1


T = int(input())
for _ in range(T):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	non_dec = True
	for i in range(n - 1):
		if a[i] > a[i + 1]:
			non_dec = False
	u = len(set(b))
	if not non_dec and u > 1 or non_dec:
		print('Yes')
	else:
		print('No')


def is_non_decreasing(l):
	if len(l) <= 1:
		return True
	for i in range(1, len(l)):
		if l[i] < l[i - 1]:
			return False
	return True
t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	(l, r) = ([], [])
	for i in range(len(a)):
		if b[i]:
			r.append(a[i])
		else:
			l.append(a[i])
	ans = True
	if len(l) == 0 and (not is_non_decreasing(r)):
		ans = False
	elif len(r) == 0 and (not is_non_decreasing(l)):
		ans = False
	print('Yes' if ans else 'No')


t = int(input())
while t:
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	flaga = False
	for i in range(1, n):
		if a[i] < a[i - 1]:
			flaga = True
			break
	zero = False
	one = False
	for i in range(n):
		if b[i] == 1:
			one = True
		else:
			zero = True
	if flaga and one and zero or not flaga:
		print('Yes')
	else:
		print('No')
	t -= 1


import math
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	one = b.count(1)
	zero = b.count(0)
	if sorted(a) == a or n == 1 or (one >= 1 and zero >= 1):
		print('Yes')
	else:
		print('No')


for _ in range(int(input())):
	N = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	temp = []
	for i in A:
		temp.append(i)
	temp.sort()
	if len(set(B)) == 1:
		if A == temp:
			print('Yes')
		else:
			print('No')
	else:
		print('Yes')


import math as m
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if 1 in b and 0 in b:
		print('Yes')
	elif a == sorted(a):
		print('Yes')
	else:
		print('No')


import sys
max_int = 1000000001
min_int = -max_int
t = int(input())
for _t in range(t):
	n = int(sys.stdin.readline())
	a = map(int, sys.stdin.readline().split())
	b = sys.stdin.readline().split()
	prev_zero = prev_one = 0
	zero_sorted = True
	ones_sorted = True
	has_zero = has_one = False
	for (num, elem) in enumerate(a):
		if b[num] == '0':
			has_zero = True
			if zero_sorted:
				if elem < prev_zero:
					zero_sorted = False
				else:
					prev_zero = elem
		else:
			has_one = True
			if ones_sorted:
				if elem < prev_one:
					ones_sorted = False
				else:
					prev_one = elem
	if has_one and has_zero:
		print('Yes')
	elif has_one:
		if ones_sorted:
			print('Yes')
		else:
			print('No')
	elif zero_sorted:
		print('Yes')
	else:
		print('No')


import math
import sys
from itertools import permutations
input = sys.stdin.readline
t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	bl = list(map(int, input().split()))
	if sum(bl) == 0 or sum(bl) == n:
		flag = True
		for j in range(n - 1):
			if arr[j] > arr[j + 1]:
				flag = False
				print('No')
				break
		if flag:
			print('Yes')
	else:
		print('Yes')


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	e = []
	o = []
	for i in range(n):
		if b[i] == 0:
			e.append(a[i])
		else:
			o.append(a[i])
	if len(e) == 0 or len(o) == 0:
		if len(o) == 0:
			e1 = sorted(e)
			if e1 == e:
				print('Yes')
			else:
				print('No')
		else:
			o1 = sorted(o)
			if o == o1:
				print('Yes')
			else:
				print('No')
	else:
		print('Yes')


t = int(input())
for ingles in range(t):
	n = int(input())
	A1 = input()
	B1 = input()
	A = A1.split()
	B = B1.split()
	for i in range(n):
		A[i] = int(A[i])
		B[i] = int(B[i])
	X = []
	Y = []
	for i in range(n):
		if B[i]:
			Y.append(A[i])
		else:
			X.append(A[i])
	if len(X) > 0 and len(Y) > 0:
		print('Yes')
	elif n == 1:
		print('Yes')
	else:
		t = True
		for i in range(n - 1):
			if A[i] > A[i + 1]:
				t = False
				break
		if t:
			print('Yes')
		else:
			print('No')


for ad in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	l_1 = []
	l_0 = []
	for i in range(n):
		if b[i] == 1:
			l_1.append(a[i])
		else:
			l_0.append(a[i])
	if len(l_0) == n or len(l_1) == n:
		t = 0
		for i in range(n - 1):
			if a[i + 1] < a[i]:
				t = 1
				break
		if t == 1:
			print('NO')
		else:
			print('YES')
	else:
		print('YES')


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	out = 0
	for i in range(n - 1):
		if b[i] != b[i + 1]:
			out = 1
	sort = 1
	for i in range(n - 1):
		if a[i] > a[i + 1]:
			sort = 0
	if out or sort:
		print('Yes')
	else:
		print('No')


def is_sorted(a, n):
	for i in range(n - 1):
		if a[i + 1] < a[i]:
			return False
	return True
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = {0: 0, 1: 0}
	for v in list(map(int, input().split())):
		b[v] += 1
	if b[0] == 0 or b[1] == 0:
		if is_sorted(a, n):
			print('Yes')
		else:
			print('No')
	else:
		print('Yes')


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	b = list(map(int, input().split()))
	z = b.count(1)
	o = b.count(0)
	if z > 0 and o > 0:
		print('Yes')
	else:
		cpy = arr.copy()
		arr.sort()
		if cpy == arr:
			print('Yes')
		else:
			print('No')


for _ in range(int(input())):
	n = int(input())
	a = [int(s) for s in input().split()]
	b = [int(s) for s in input().split()]
	if a == sorted(a):
		print('Yes')
	else:
		x = b.count(1)
		y = b.count(0)
		if x > 0 and y > 0:
			print('Yes')
		else:
			print('No')


t = int(input())
for T in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	c = []
	d = []
	e = []
	f = []
	for i in range(n):
		if b[i] == 1:
			c.append(a[i])
			e.append(a[i])
		else:
			d.append(a[i])
			f.append(a[i])
	e.sort()
	f.sort()
	if len(c) > 0 and len(d) > 0:
		print('Yes')
	else:
		if len(c) == 0:
			if d == f:
				print('Yes')
			else:
				print('No')
		if len(d) == 0:
			if c == e:
				print('Yes')
			else:
				print('No')


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	pre = True
	for i in range(n - 1):
		if a[i] > a[i + 1]:
			pre = False
			break
	if pre:
		print('Yes')
		continue
	if sum(b) in [0, n]:
		print('No')
	else:
		print('Yes')


def gray_code_for_2(n):
	list = ['0', '1']
	for i in range(1, n):
		left = ['0' + i for i in list]
		right = ['1' + i for i in list[::-1]]
		list = left + right
	return list

def Trouble_Sort():
	n = int(input())
	a = list(map(int, input().split(' ')))
	b = list(map(int, input().split(' ')))
	hs = False
	mood = False
	flag = True
	for i in range(0, n):
		if i < n - 1:
			if a[i + 1] < a[i]:
				flag = False
		if b[i] != 0:
			mood = True
		else:
			hs = True
	if flag or (hs and mood):
		print('Yes')
	else:
		print('No')
h = int(input())
for _ in range(h):
	Trouble_Sort()


t = int(input())
for i in range(t):
	n = int(input())
	l1 = list(map(int, input().split(' ')))
	l1_n = sorted(l1)
	l2 = list(map(int, input().split(' ')))
	if sum(l2) != len(l2) and sum(l2) != 0 or l1 == l1_n:
		print('Yes')
	else:
		print('No')


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().rstrip().split(' ')))
	li = list(map(int, input().rstrip().split(' ')))
	if l == sorted(l):
		print('YES')
	else:
		one = False
		zero = False
		for i in range(n):
			if li[i] == 1:
				one = True
			else:
				zero = True
			if one and zero:
				break
		if one and zero:
			print('YES')
		else:
			print('NO')


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	kek = list(map(int, input().split()))
	if sorted(arr) == arr:
		print('YES')
	elif sum(kek) in (0, n):
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	d = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	a_sort = sorted(a)
	if a_sort == a:
		print('YES')
	else:
		dict1 = {}
		for i in range(d):
			if dict1.get(b[i]) == None:
				dict1[b[i]] = 1
			else:
				dict1[b[i]] += 1
		if len(dict1) > 1:
			print('YES')
		else:
			print('NO')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if a == list(sorted(a)) or set(b).__len__() == 2:
		print('Yes')
	else:
		print('No')


t = int(input())
for ab in range(t):
	n = int(input())
	m = list(map(int, input().split()))
	b = list(map(int, input().split()))
	tx = b.count(0)
	lq = sorted(m)
	if (tx == 0 or tx == n) and lq != m:
		print('No')
	else:
		print('Yes')


def swap(lis, pos1, pos2):
	(lis[pos1], lis[pos2]) = (lis[pos2], lis[pos1])
	return lis
for _ in range(int(input())):
	n = int(input())
	k = []
	a = list(map(int, input().split()))
	l = list(map(int, input().split()))
	l = list(dict.fromkeys(l))
	for i in range(0, n):
		k.append(a[i])
	k.sort()
	flag = True
	if len(l) > 1 or a == k:
		print('Yes')
	else:
		print('No')


import sys
ints = (int(x) for x in sys.stdin.read().split())
sys.setrecursionlimit(3000)

def main():
	ntc = next(ints)
	for tc in range(1, ntc + 1):
		n = next(ints)
		a = [next(ints) for i in range(n)]
		b = [next(ints) for i in range(n)]
		s = sum(b)
		ans = 1 if 0 < s < n else all((x <= y for (x, y) in zip(a, a[1:])))
		print('Yes' if ans else 'No')
	return
main()


def merge(arr, l, m, r):
	n1 = m - l + 1
	n2 = r - m
	L = [0] * n1
	R = [0] * n2
	for i in range(0, n1):
		L[i] = arr[l + i]
	for j in range(0, n2):
		R[j] = arr[m + 1 + j]
	i = 0
	j = 0
	k = l
	while i < n1 and j < n2:
		if L[i] <= R[j]:
			arr[k] = L[i]
			i += 1
		else:
			arr[k] = R[j]
			j += 1
		k += 1
	while i < n1:
		arr[k] = L[i]
		i += 1
		k += 1
	while j < n2:
		arr[k] = R[j]
		j += 1
		k += 1

def mergeSort(arr, l, r):
	if l < r:
		m = (l + (r - 1)) // 2
		mergeSort(arr, l, m)
		mergeSort(arr, m + 1, r)
		merge(arr, l, m, r)
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	num1 = []
	for j in range(n):
		num1.append(a[j])
	mergeSort(num1, 0, n - 1)
	lis = []
	arr1 = 0
	arr2 = 0
	for j in range(n):
		if a[j] != num1[j]:
			lis.append(j)
		if b[j] == 1:
			arr1 += 1
		if b[j] == 0:
			arr2 += 1
	l = len(lis)
	if l == 0:
		print('Yes')
	elif arr1 == 0 or arr2 == 0:
		print('No')
	else:
		print('Yes')


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	order = list(map(int, input().split()))
	if order.count(1) == 0 or order.count(0) == 0:
		print('Yes' if sorted(arr) == arr else 'No')
	else:
		print('Yes')


r = lambda : list(map(int, input().split()))
for _ in range(r()[0]):
	(n, a, b) = (r()[0], r(), r())
	print('YNeos'[sum(b) % n == 0 and a != sorted(a)::2])


def is_sorted(arr):
	for i in range(len(arr) - 1):
		if arr[i] > arr[i + 1]:
			return False
	return True

def solve():
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	zda = False
	if b.count(1) > 0 and b.count(1) < n:
		zda = True
	if is_sorted(a):
		zda = True
	if zda:
		print('Yes')
	else:
		print('No')
t = int(input())
for i in range(t):
	solve()


t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	if a == sorted(a):
		print('Yes')
		continue
	if len(set(b)) == 1:
		print('No')
		continue
	print('Yes')


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
mod = int(pow(10, 9) + 7)
mod2 = 998244353

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

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

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

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

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
for _ in range(l()[0]):
	n = l()[0]
	A = l()
	B = l()
	C = sorted(A)
	if A == C:
		print('Yes')
		continue
	if len(set(B)) == 1:
		print('No')
	else:
		print('Yes')


for i1 in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	first = a.copy()
	first.sort()
	if first == a:
		print('Yes')
		continue
	elif 1 in b and 0 in b:
		print('Yes')
	else:
		print('No')


from fractions import Fraction
import bisect
import os
from collections import Counter
import bisect
from collections import defaultdict
import math
import random
import heapq as hq
from math import sqrt
import sys
from functools import reduce, cmp_to_key
from collections import deque
import threading
from itertools import combinations
from io import BytesIO, IOBase
from itertools import accumulate
from queue import Queue

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

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

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

def rinput():
	return map(int, tinput())

def rlinput():
	return list(rinput())
mod = int(1000000000.0) + 7

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))
t = 1
t = iinput()
for _ in range(t):
	n = iinput()
	a = rlinput()
	b = rlinput()
	if sorted(a) == a:
		print('Yes')
		continue
	elif b.count(0) == n or b.count(0) == 0:
		print('No')
		continue
	print('Yes')


t = int(input())
for _ in range(t):
	n = int(input())
	A = list(map(int, input().split(' ')))
	B = list(map(int, input().split(' ')))
	num0 = 0
	for b in B:
		num0 += 1 if b == 0 else 0
	num1 = len(B) - num0
	if num0 > 0 and num1 > 0:
		print('Yes')
	elif A == sorted(A):
		print('Yes')
	else:
		print('No')


for t in range(int(input())):
	n = int(input())
	a = [int(j) for j in input().split()]
	b = [int(j) for j in input().split()]
	x = [b.count(0), b.count(1)]
	for i in range(n):
		for j in range(i + 1, n):
			if a[i] > a[j]:
				if b[i] != b[j] or x[1 - b[i]]:
					(a[i], a[j]) = (a[j], a[i])
	if a == sorted(a):
		print('Yes')
	else:
		print('No')


def func(lst1, lst2):
	if lst2 == sorted(lst2):
		return 'YES'
	elif len(lst2) == 1:
		return 'YES'
	elif 0 in lst1 and 1 in lst1:
		return 'YES'
	else:
		return 'NO'
output = []
say = int(input())
for i in range(say):
	lst_length = int(input())
	lst2 = list(map(int, input().split()))
	lst1 = list(map(int, input().split()))
	output.append(func(lst1, lst2))
for i in output:
	print(i)


import math
t = int(input())
for i in range(t):
	n = int(input())
	a = [int(x) for x in input().split(' ')]
	b = [int(x) for x in input().split(' ')]
	if sum(b) == len(b) or sum(b) == 0:
		flag = 0
		if all((a[i] <= a[i + 1] for i in range(len(a) - 1))):
			flag = 1
		if flag == 1:
			print('Yes')
		else:
			print('No')
	else:
		print('Yes')


T = int(input())
for t in range(T):
	n = int(input())
	(*a,) = map(int, input().split())
	(*b,) = map(int, input().split())
	if b.count(0) > 0 and b.count(1) > 0:
		print('Yes')
	else:
		s = sorted(a)
		if a == s:
			print('Yes')
		else:
			print('No')


n = int(input())
for i in range(0, n):
	t = int(input())
	L = list(map(int, input().split()))
	M = list(map(int, input().split()))
	N = sorted(L)
	count = 0
	for i in range(0, len(L)):
		if L[i] == N[i]:
			count += 1
	if count == len(L):
		print('Yes')
	elif all((e == 1 for e in M)) or all((e == 0 for e in M)):
		print('No')
	else:
		print('Yes')


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	typ = list(map(int, input().split()))
	if len(set(typ)) == 2:
		print('Yes')
		continue
	prev = -1
	flag = True
	for e in arr:
		if e < prev:
			flag = False
			break
		prev = e
	if flag:
		print('Yes')
	else:
		print('No')


from math import *

def r1(t):
	return t(input())

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

def r3(t):
	return [t(i) for i in input()]
for _ in range(r1(int)):
	n = r1(int)
	a = r2(int)
	b = r2(int)
	p1 = -1
	p2 = -1
	ha = True
	s = sum(b)
	for i in range(n):
		if b[i] == 1:
			if a[i] < p2 and s == n:
				ha = False
				break
			p2 = a[i]
		else:
			if a[i] < p1 and s == 0:
				ha = False
				break
			p1 = a[i]
	if ha:
		print('Yes')
	else:
		print('No')


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	a = list(map(int, input().split()))
	if l == sorted(l):
		print('Yes')
	elif len(set(a)) == 2:
		print('Yes')
	else:
		print('No')


def sort(s1, s2):
	if 0 in s2 and 1 in s2:
		print('YES')
	elif sorted(s1) == s1:
		print('YES')
	else:
		print('NO')
t = int(input())
l = []
for i in range(t):
	n = int(input())
	s1 = list(map(int, input().split()))
	s2 = list(map(int, input().split()))
	l.append([s1, s2])
for j in l:
	sort(j[0], j[1])


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a1 = a[:]
	a1.sort()
	t1 = b.count(0)
	if t1 == n or t1 == 0:
		if a == a1:
			print('Yes')
		else:
			print('No')
	else:
		print('Yes')


for t in range(int(input())):
	n = int(input())
	matrix = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	ct = 0
	for i in range(n):
		ct += arr[i]
	if ct == 0 or ct == n:
		ans = 'Yes'
		for i in range(1, n):
			if matrix[i] - matrix[i - 1] < 0:
				ans = 'No'
				break
		print(ans)
	else:
		print('Yes')


t = int(input())

def fn(arr):
	h0 = False
	h1 = False
	for v in arr:
		if v:
			h1 = True
		else:
			h0 = True
	return h0 and h1
while t:
	t -= 1
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if fn(b):
		print('Yes')
	elif sorted(a) == a:
		print('Yes')
	else:
		print('No')


import io
import os
from collections import Counter, defaultdict, deque

def solve(N, A, B):
	l1 = []
	l2 = []
	for (a, b) in zip(A, B):
		if b == 0:
			l1.append(a)
		else:
			l2.append(a)
	if l1 == sorted(l1) and l2 == sorted(l2):
		return 'Yes'
	if l1 and l2:
		return 'Yes'
	return 'No'
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
T = int(input())
for t in range(T):
	(N,) = [int(x) for x in input().split()]
	A = [int(x) for x in input().split()]
	B = [int(x) for x in input().split()]
	ans = solve(N, A, B)
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = set([int(x) for x in input().split()])
	c = a.copy()
	c.sort()
	if len(b) > 1 or c == a:
		print('Yes')
	else:
		print('No')


t = int(input())
ans = ['Yes'] * t
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	swta = 1
	swtb = 1
	for j in range(1, n):
		if a[j] < a[j - 1]:
			swta = 0
		if b[j] != b[j - 1]:
			swtb = 0
	if swtb == 1:
		if swta == 0:
			ans[i] = 'No'
for i in range(t):
	print(ans[i])


def hasTwoTypes(arr):
	(mark0, mark1) = (0, 0)
	for i in range(len(arr)):
		if arr[i] == 0:
			mark0 = 1
		else:
			mark1 = 1
		if mark0 and mark1:
			return True
	return False

def isSorted(arr):
	for i in range(len(arr) - 1):
		if arr[i] > arr[i + 1]:
			return False
	return True

def troubleSort(a, b, n):
	if hasTwoTypes(b):
		return 'Yes'
	elif isSorted(a):
		return 'Yes'
	else:
		return 'No'
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	print(troubleSort(a, b, n))


def troublesort(a, b):
	if a == sorted(a):
		return 'Yes'
	else:
		c1 = b.count(1)
		c2 = b.count(0)
		if c1 != 0 and c2 != 0:
			return 'Yes'
		else:
			return 'No'
test = int(input())
for i in range(test):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	print(troublesort(a, b))


T = int(input())

def main():
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	if a == sorted(a):
		return True
	else:
		for i in b:
			if i != b[0]:
				return True
		return False
while T != 0:
	if main() == True:
		print('Yes')
	else:
		print('No')
	T -= 1


for test in range(int(input())):
	n = int(input())
	ai = list(map(int, input().split()))
	bi = list(map(int, input().split()))
	flag = True
	for k in range(n - 1):
		if ai[k] > ai[k + 1]:
			flag = False
			break
	if flag:
		print('YES')
		continue
	flagzero = False
	flagum = False
	for k in range(n):
		if bi[k] == 1:
			flagum = True
		if bi[k] == 0:
			flagzero = True
		if flagum and flagzero:
			break
	if flagum and flagzero:
		print('YES')
	else:
		print('NO')


from math import ceil

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

def inin():
	return int(input())

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

def ar(element, size):
	return [element for i in range(size)]

def yes():
	print('Yes')

def no():
	print('No')
Testcase = inin()
for _ in range(Testcase):
	n = inar()
	a = inar()
	b = inar()
	if a == sorted(a):
		yes()
	elif b.count(1) > 0 and b.count(0) > 0:
		yes()
	else:
		no()


for i in range(int(input())):
	no = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	z = a.copy()
	z.sort()
	if a == z:
		print('YES')
	else:
		for j in range(len(b) - 1):
			if b[j] != b[j + 1]:
				temp = a[j]
				a[j] = a[j + 1]
				a[j + 1] = temp
				if set(a) == set(z):
					print('YES')
					break
		else:
			print('NO')


T = int(input())
for t in range(T):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if b.count(0) > 0 and b.count(1) > 0:
		print('Yes')
	else:
		sorted = True
		for (a1, a2) in zip(a[:-1], a[1:]):
			if a1 > a2:
				sorted = False
				break
		if sorted:
			print('Yes')
		else:
			print('No')


x = int(input())
for q in range(x):
	f = 'd'
	xf = 'd'
	n = int(input())
	l = list(input().split())
	xl = list(input().split())
	c = -1
	for i in range(n):
		if int(l[i]) < c:
			xf = 'u'
			break
		else:
			c = int(l[i])
	if xf == 'd':
		print('Yes')
	else:
		champ = xl[0]
		for i in range(1, n):
			if xl[i] != champ:
				f = 'u'
		if f == 'u':
			print('Yes')
		else:
			print('No')


from sys import stdin
from math import ceil, gcd

def func():
	return
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	b = list(map(int, stdin.readline().split()))
	if b.count(1) > 0 and b.count(0) > 0:
		print('YES')
	elif a == sorted(a):
		print('YES')
	else:
		print('NO')


from __future__ import division, print_function
from collections import *
from math import *
from itertools import *
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

def main():
	n = int(input())
	arr = list(map(int, input().split()))
	arr1 = list(map(int, input().split()))
	arr2 = arr.copy()
	arr2.sort()
	if arr == arr2:
		print('Yes')
		return
	elif 0 in arr1 and 1 in arr1:
		print('Yes')
		return
	print('No')
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')
t = int(input())
while t:
	main()
	t -= 1


for _ in range(int(input())):
	n = int(input())
	a = [*map(int, input().split())]
	b = [*map(int, input().split())]
	t = sorted(a)
	print('YES' if len(set(b)) > 1 or a == t else 'NO')


from sys import stdin, stdout
for cases in range(int(stdin.readline())):
	n = int(stdin.readline().strip())
	a = list(map(int, stdin.readline().split()))
	b = list(map(int, stdin.readline().split()))
	check = 1
	for i in range(1, n):
		if a[i - 1] > a[i]:
			check = 0
	cn_0 = b.count(0)
	cn_1 = b.count(1)
	if cn_1 >= 1 and cn_0 >= 1:
		print('Yes')
	elif check:
		print('Yes')
	else:
		print('No')


import sys

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

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

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

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 19
MOD = 10 ** 9 + 7
for _ in range(INT()):
	N = INT()
	A = LIST()
	B = LIST()
	if A == sorted(A) or (B.count(0) and B.count(1)):
		Yes()
	else:
		No()


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if (b.count(0) == n or b.count(1) == n) and sorted(a) != a:
		print('No')
	else:
		print('Yes')


inp = input
for _ in range(int(inp())):
	n = int(inp())
	arr = list(map(int, inp().strip().split(' ')))
	brr = list(map(int, inp().strip().split(' ')))
	z = brr.count(1)
	o = brr.count(0)
	if z > 0 and o > 0:
		print('Yes')
	else:
		cpy = arr.copy()
		arr.sort()
		if cpy == arr:
			print('Yes')
		else:
			print('No')


from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if len(set(b)) == 2:
		print('Yes')
		continue
	if a == sorted(a):
		print('Yes')
	else:
		print('No')


T = int(input())

def solve():
	N = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	count_0 = 0
	count_1 = 0
	for x in B:
		if x == 0:
			count_0 += 1
		else:
			count_1 += 1
	if count_0 == 0 or count_1 == 0:
		return A == sorted(A)
	return True
for _ in range(T):
	if solve():
		print('Yes')
	else:
		print('No')


import sys
import math
import collections
import heapq
import queue
import itertools
import functools
import operator
import time
readline = sys.stdin.readline
IPS = lambda : readline().rstrip()
IP = lambda : int(readline().rstrip())
MP = lambda : map(int, readline().split())
LS = lambda : list(map(int, readline().split()))

def solve():
	for _ in range(IP()):
		n = IP()
		a = LS()
		b = LS()
		cnt = b.count(1)
		if a == sorted(a):
			print('Yes')
		elif cnt > 0 and cnt < n:
			print('Yes')
		else:
			print('No')
solve()


t = int(input())
for _ in range(t):
	num = int(input())
	l = list(map(int, input().split()))
	l1 = [int(j) for j in input().split()]
	l2 = l
	if l2 == sorted(l2):
		print('Yes')
	elif l1.count(0) == 0 or l1.count(1) == 0:
		print('No')
	else:
		print('Yes')


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	l = list(map(int, input().split()))
	m = list(map(int, input().split()))
	x = sorted(l)
	if x == l:
		print('Yes')
	elif m.count(0) and m.count(1):
		print('Yes')
	else:
		print('No')


import os
import heapq
import sys
import math
import operator
from collections import defaultdict
from io import BytesIO, IOBase

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

def main():
	for _ in range(int(input())):
		n = int(input())
		a = inar()
		b = inar()
		lis = a.copy()
		lis.sort()
		z = 0
		o = 0
		for i in range(n):
			if b[i] == 1:
				o += 1
			else:
				z += 1
		if z != 0 and o != 0:
			print('Yes')
		elif lis == a:
			print('Yes')
		else:
			print('No')
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()


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	d = a.copy()
	d.sort()
	if d == a:
		print('Yes')
	else:
		zero = 0
		one = 0
		for i in range(len(b)):
			if b[i] == 0:
				zero += 1
			if b[i] == 1:
				one += 1
			if zero == 1 and one == 1:
				break
		if zero >= 1 and one >= 1:
			print('Yes')
		else:
			print('No')


T = int(input())
D = []
for i in range(0, T):
	n = int(input())
	A = [int(x) for x in input().split(' ')]
	B = [int(x) for x in input().split(' ')]
	C = A.copy()
	C.sort()
	if 1 in B and 0 in B:
		D.append('Yes')
	elif A == C:
		D.append('Yes')
	else:
		D.append('No')
for i in D:
	print(i)


import sys
from sys import stdin
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__

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

def Neo():
	return list(map(int, input().split()))
for _ in range(int(input())):
	n = int(input())
	A = Neo()
	B = Neo()
	mark = {}
	C = A.copy()
	C.sort()
	if C == A:
		print('Yes')
	elif B.count(0) == 0 or B.count(1) == 0:
		print('No')
	else:
		print('Yes')


import math
for _ in range(int(input())):
	n = int(input())
	l1 = [int(x) for x in input().split()]
	l = l1.copy()
	l.sort()
	l2 = [int(x) for x in input().split()]
	s = set(l2)
	if len(set(s)) == 1 and l1 != l:
		print('No')
	else:
		print('Yes')


from sys import stdin, stdout
cin = stdin.readline
cout = stdout.write
mp = lambda : list(map(int, cin().split()))

def swap(x, i, j):
	t = x[i]
	x[i] = x[j]
	x[j] = t
(t,) = mp()
for _ in range(t):
	(n,) = mp()
	a = mp()
	b = mp()
	f = 0
	for i in range(n - 1):
		if a[i] <= a[i + 1]:
			continue
		else:
			x = y = 0
			for val in b:
				if val:
					x += 1
				else:
					y += 1
				if x and y:
					cout('yes\n')
					break
			else:
				cout('no\n')
			break
	else:
		cout('yes\n')


__multitest = True

def is_sorted(a, n):
	flag = True
	for i in range(1, n):
		flag &= a[i - 1] <= a[i]
	return flag

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if b.count(0) < n and b.count(1) < n:
		print('YES')
	elif is_sorted(a, n):
		print('YES')
	else:
		print('NO')
t = int(input()) if __multitest else 1
for tt in range(t):
	solve()


t = int(input())
for i in range(t):
	n = int(input())
	(c1, c2) = (0, 0)
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	for x in b:
		if x == 1:
			c1 += 1
		else:
			c2 += 1
	if c1 == n or c1 == 0:
		if a != sorted(a):
			print('No')
		else:
			print('Yes')
	elif c1 > 0 and c2 > 0:
		print('Yes')
	else:
		print('No')


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	d = 0
	e = 0
	g = 0
	c = sorted(a)
	if a == c:
		d = 1
	else:
		for i in range(n):
			if b[i] == 0:
				e += 1
			else:
				g += 1
	if e and g:
		d = 1
	if d == 1:
		print('Yes')
	else:
		print('No')


T = int(input())
for i in range(T):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if a == sorted(a):
		print('Yes')
	elif n == 1:
		print('No')
	elif b[0] == 0:
		if 1 in b:
			print('Yes')
		else:
			print('No')
	elif 0 in b:
		print('Yes')
	else:
		print('No')


t = int(input())
for s in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	add = 0
	flag = 1
	for i in range(1, n):
		if a[i] < a[i - 1]:
			flag = 0
			break
	if flag == 0:
		for j in b:
			if j == 1:
				add += 1
		if add == 0 or add == n:
			print('No')
		else:
			print('Yes')
	else:
		print('Yes')


x = int(input())
for i in range(0, x):
	n = int(input())
	m = list(map(int, input().split()))[:n]
	k = list(map(int, input().split()))[:n]
	s = 0
	ar = []
	for j in range(0, n):
		ar.append(m[j])
	m.sort()
	g = k.count(k[0])
	if ar == m:
		s = 1
	elif g != n:
		s = 1
	if s == 1:
		print('Yes')
	else:
		print('No')


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	a = list(map(int, input().split()))
	d = {0: 0, 1: 0}
	for i in a:
		d[i] += 1
	if l != sorted(l):
		if d[1] == 0 or d[0] == 0:
			print('No')
		else:
			print('Yes')
	else:
		print('Yes')


class Solution:

	def __init__(self):
		for t in range(int(input())):
			n = int(input())
			a = list(map(int, input().split()))
			b = list(map(int, input().split()))
			self.solve(n, a, b)

	def solve(self, n, a, b):
		c = sorted(a)
		if c == a:
			return print('Yes')
		b = set(b)
		if len(b) == 1 and n > 1:
			return print('No')
		print('Yes')
Solution()


def arraySortedOrNot(arr, n):
	if n == 0 or n == 1:
		return True
	for i in range(1, n):
		if arr[i - 1] > arr[i]:
			return False
	return True
n = int(input())
for _ in range(n):
	t = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if b.count(0) == 0 or b.count(1) == 0:
		if arraySortedOrNot(a, t):
			print('Yes')
		else:
			print('No')
	elif b.count(0) >= 1 and b.count(1) >= 1:
		print('Yes')


t = int(input())

def solved(arr):
	for i in range(len(arr) - 1):
		if arr[i + 1] < arr[i]:
			return False
	return True

def solvable(arr):
	(cnt0, cnt1) = (0, 0)
	for i in arr:
		if i == 1:
			cnt1 += 1
		else:
			cnt0 += 1
	if cnt0 > 0 and cnt1 > 0:
		return True
	else:
		return False
while t > 0:
	n = int(input())
	arr = list(map(int, input().split()))
	binary = list(map(int, input().split()))
	if solved(arr) or solvable(binary):
		print('YES')
	else:
		print('NO')
	t -= 1


for t in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	h1 = 0
	h2 = 0
	for i in input().split():
		if i == '0':
			h1 += 1
		else:
			h2 += 1
	if h1 > 0 and h2 > 0 or sorted(a) == a:
		print('Yes')
	else:
		print('No')


import sys, math
input = lambda : sys.stdin.readline().rstrip()
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if 0 in b and 1 in b:
		print('Yes')
	else:
		ans = 'Yes'
		for i in range(n):
			if a[i] < a[max(0, i - 1)]:
				ans = 'No'
		print(ans)


import math
t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(var) for var in input().split()]
	b = [int(var) for var in input().split()]
	newA = sorted(a)
	if newA == a:
		print('Yes')
	elif 0 < sum(b) < n:
		print('Yes')
	else:
		print('No')


import sys
input = sys.stdin.readline
for f in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	s = sum(b)
	if s == n or s == 0:
		i = 1
		poss = True
		while poss and i < n:
			if a[i] < a[i - 1]:
				poss = False
			i += 1
		if poss:
			print('Yes')
		else:
			print('No')
	else:
		print('Yes')


t = int(input())
for i in range(t):
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	l = l1.copy()
	l.sort()
	a = l2.count(0)
	b = n - a
	if a == 0 or b == 0:
		if l1 == l:
			print('Yes')
		else:
			print('No')
	else:
		print('Yes')


def checkBoth(a):
	m = False
	n = False
	for i in a:
		if i == 0:
			m = True
		else:
			n = True
	return m & n

def func(n, arr, a):
	if checkBoth(a) == 1:
		print('Yes')
		return
	if sorted(arr) == arr:
		print('Yes')
		return
	print('No')
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	a = list(map(int, input().split()))
	func(n, arr, a)


import sys
import math
import collections
from sys import stdin, stdout, setrecursionlimit
import bisect as bs
setrecursionlimit(2 ** 20)
M = 10 ** 9 + 7
T = int(stdin.readline())
for _ in range(T):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	b = list(map(int, stdin.readline().split()))
	A = a.copy()
	A.sort()
	rs = True
	for i in range(n):
		if a[i] == A[i]:
			continue
		rs = False
		break
	if rs:
		print('Yes')
		continue
	o = 0
	z = 0
	rs = False
	for i in range(n):
		if b[i] == 1:
			o += 1
		else:
			z += 1
		if o > 0 and z > 0:
			rs = True
			break
	if rs:
		print('Yes')
	else:
		print('No')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	s = sorted(a)
	if s == a:
		print('Yes')
		continue
	if len(set(b)) == 2:
		print('Yes')
	else:
		print('No')


t = int(input())
while t:
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	f = 0
	for i in range(n - 1):
		if a[i] > a[i + 1]:
			f = 1
			break
	if f == 0:
		print('Yes')
	else:
		k = set(b)
		k = list(k)
		if len(k) > 1:
			print('Yes')
		else:
			print('No')
	t -= 1


T = int(input())
for _ in range(T):
	n = int(input())
	l = list(map(int, input().split()))
	b = list(map(int, input().split()))
	flag = 1
	new = sorted(l)
	for i in range(n):
		if new[i] != l[i]:
			flag = 0
			break
	if flag == 1:
		print('Yes')
		continue
	z = 0
	o = 0
	for i in range(n):
		if b[i] == 0:
			z = 1
		else:
			o = 1
	if z and o:
		print('Yes')
	else:
		print('No')


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	fl = True
	if sum(b) == 0 or sum(b) == n:
		for i in range(n - 1):
			if fl and a[i + 1] < a[i]:
				fl = False
	if fl:
		print('Yes')
	else:
		print('No')


for _ in range(int(input())):
	n = int(input())
	m = list(map(int, input().split()))
	li = list(map(int, input().split()))
	if m == sorted(m):
		print('Yes')
	elif li.count(1) != 0 and li.count(0) != 0:
		print('Yes')
	else:
		print('No')


def solve():
	T = int(input())
	for _ in range(T):
		n = int(input())
		A = [int(s) for s in input().split(' ')]
		B = [int(s) for s in input().split(' ')]
		s = sum(B)
		if s == 0 or s == len(B):
			if sorted(A) == A:
				print('Yes')
			else:
				print('No')
		else:
			print('Yes')
solve()


tests = int(input())
for i in range(tests):
	n = int(input())
	sort_row = 1
	numbers = [int(x) for x in input().split(' ')]
	types = [int(x) for x in input().split(' ')]
	one_count = sum(types)
	for x in range(1, n):
		if numbers[x] < numbers[x - 1]:
			sort_row = 0
			break
	if sort_row == 1:
		print('Yes')
	elif one_count == 0 or one_count == n:
		print('No')
	else:
		print('Yes')


t = int(input())

def search(num1, num2, lst):
	for i in lst:
		if i > num1 or i < num2:
			return 1
	return 0
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	typarr = list(map(int, input().split()))
	typ1 = set(typarr)
	if len(typ1) == 2 or arr == sorted(arr):
		print('Yes')
	else:
		print('No')


import sys
import math
import collections
from collections import deque
from functools import reduce
from sys import stdin, stdout, setrecursionlimit
setrecursionlimit(2 ** 20)

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

def factors(n):
	return list(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))
T = 1
T = int(stdin.readline())
for _ in range(T):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	b = list(map(int, stdin.readline().split()))
	c = a.copy()
	c.sort()
	if n == b.count(0) or n == b.count(1):
		if c == a:
			print('Yes')
			continue
		else:
			print('No')
			continue
	if b.count(1) != 0 and b.count(0) != 0:
		print('Yes')
	else:
		print('No')


for i in range(int(input())):
	k = int(input())
	a = list(map(int, input().split()))
	d = sorted(a)
	c = list(map(int, input().split()))
	e = set(c)
	if a == d:
		print('YES')
	elif len(e) == 2:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	zero = []
	one = []
	for i in range(n):
		if b[i]:
			one.append(a[i])
		else:
			zero.append(a[i])
	if len(zero) == 0:
		if one == sorted(one):
			print('Yes')
		else:
			print('No')
	elif len(one) == 0:
		if zero == sorted(zero):
			print('Yes')
		else:
			print('No')
	else:
		print('Yes')


from sys import stdin, stdout

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

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

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

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

def op(c):
	return stdout.write(c)
from collections import defaultdict
for _ in range(int(stdin.readline())):
	n = get_int()
	a = get_array()
	b = get_array()
	c = sorted(a)
	if a == c:
		print('Yes')
		continue
	(oc, zc) = (0, 0)
	for i in b:
		if i == 1:
			oc += 1
		elif i == 0:
			zc += 1
	if zc == 0 or oc == 0:
		print('No')
	else:
		print('Yes')


t = int(input())
for _ in range(t):
	n = int(input())
	(*vals,) = map(int, input().split())
	(*types,) = map(int, input().split())
	print('Yes' if vals == sorted(vals) or len(set(types)) == 2 else 'No')


import sys
from collections import defaultdict as dd
from collections import deque
from functools import *
from fractions import Fraction as f
from copy import *
from bisect import *
from heapq import *
from math import *
from itertools import permutations, product

def eprint(*args):
	print(*args, file=sys.stderr)
zz = 1
if zz:
	input = sys.stdin.readline
else:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('all.txt', 'w')

def inc(d, c):
	d[c] = d[c] + 1 if c in d else 1

def bo(i):
	return ord(i) - ord('A')

def li():
	return [int(xx) for xx in input().split()]

def fli():
	return [float(x) for x in input().split()]

def comp(a, b):
	if a > b:
		return 2
	return 2 if a == b else 0

def gi():
	return [xx for xx in input().split()]

def fi():
	return int(input())

def pro(a):
	return reduce(lambda a, b: a * b, a)

def swap(a, i, j):
	(a[i], a[j]) = (a[j], a[i])

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

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

def gh():
	sys.stdout.flush()

def isvalid(i, j):
	return 0 <= i < n and 0 <= j < n

def bo(i):
	return ord(i) - ord('a')

def graph(n, m):
	for i in range(m):
		(x, y) = mi()
		a[x].append(y)
		a[y].append(x)
t = fi()
while t > 0:
	t -= 1
	n = fi()
	a = li()
	b = li()
	if b.count(0) not in [0, n] or a == sorted(a):
		print('Yes')
	else:
		print('No')


t = int(input())
for i in range(t):
	n = int(input())
	A = [int(i) for i in input().split()]
	B = [int(i) for i in input().split()]
	B = set(B)
	if A == sorted(A):
		print('Yes')
	elif len(B) > 1:
		print('Yes')
	else:
		print('No')


import re
import sys
from bisect import bisect, bisect_left, insort, insort_left
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from itertools import accumulate, combinations, combinations_with_replacement, groupby, permutations, product
from math import acos, asin, atan, ceil, cos, degrees, factorial, hypot, log2, pi, radians, sin, sqrt, tan
from operator import itemgetter, mul
from string import ascii_lowercase, ascii_uppercase, digits

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

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

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

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

def bubbleSort(nlist):
	for passnum in range(len(nlist) - 1, 0, -1):
		for i in range(passnum):
			if nlist[i] > nlist[i + 1] and b[i] != b[i + 1]:
				temp = nlist[i]
				nlist[i] = nlist[i + 1]
				nlist[i + 1] = temp
				(b[i], b[i + 1]) = (b[i + 1], b[i])
	return nlist
t = inp()
for _ in range(t):
	n = inp()
	a = inlist()
	b = inlist()
	zeros = b.count(0)
	ones = b.count(1)
	res = 'Yes'
	if zeros == 0 or ones == 0:
		res = 'No'
	is_sorted = True
	for i in range(n - 1):
		if a[i] > a[i + 1]:
			is_sorted = False
			break
	if is_sorted:
		res = 'Yes'
	print(res)


t = int(input())
while t > 0:
	n = int(input())
	a = []
	b = []
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if a == sorted(a) or len(set(b)) > 1:
		print('Yes')
	else:
		print('No')
	t = t - 1


t = int(input())
for o in range(t):
	n = int(input())
	a = list(map(int, input().strip().split()))
	b = list(map(int, input().strip().split()))
	c = []
	for i in range(n):
		c.append([a[i], b[i]])
	numZeros = 0
	numOnes = 0
	pos = []
	for i in range(n):
		if b[i] == 0:
			numZeros += 1
		else:
			numOnes += 1
	if numZeros == 0 or numOnes == 0:
		can = 'Yes'
		for i in range(n - 1):
			if c[i][0] > c[i + 1][0]:
				can = 'No'
				break
		print(can)
	else:
		print('Yes')


def solve():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	f = 0
	for v in b:
		f |= 1 << v
	if f == 3:
		print('Yes')
	else:
		print(['No', 'Yes'][a == sorted(a)])
t = int(input())
for _ in range(t):
	solve()


import math
t = int(input())
for i in range(t):
	n = int(input())
	a1 = []
	a = list(map(int, input().strip().split(' ')))
	a1[:] = a[:]
	a1.sort()
	b = list(map(int, input().strip().split(' ')))
	if a1 == a:
		print('yes')
	else:
		c1 = b.count(1)
		c2 = b.count(0)
		if c1 == 0 or c2 == 0:
			print('no')
		else:
			print('yes')


import os
import sys
from io import BytesIO, IOBase

def main():
	t = int(input())
	for case in range(t):
		n = int(input())
		a = list(map(int, input().split()))
		b = list(map(int, input().split()))
		if len(set(b)) == 2:
			write('Yes')
		elif a == sorted(a):
			write('Yes')
		else:
			write('No')
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))

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

def write(*args, end='\n'):
	for x in args:
		sys.stdout.write(str(x) + ' ')
	sys.stdout.write(end)

def r_array():
	return [int(x) for x in input().split()]

def r_int():
	return int(input())

def w_array(arr):
	for x in arr:
		write(x, end=' ')
	write()
main()


t = int(input())
for _ in range(t):
	n = int(input())
	a = input().split()
	b = input().split()
	if b.count('1') and b.count('0'):
		print('Yes')
	else:
		for i in range(1, n):
			if int(a[i - 1]) > int(a[i]):
				print('No')
				break
		else:
			print('Yes')


def is_sorted(a):
	for i in range(len(a) - 1):
		if a[i] > a[i + 1]:
			return False
	return True

def solve(n, a, b):
	return 'yes' if 0 in b and 1 in b or is_sorted(a) else 'no'
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	print(solve(n, a, b))


t = int(input())
while t > 0:
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	(a1, a2) = ([], [])
	for i in range(n):
		if b[i] == 0:
			a1.append(a[i])
		else:
			a2.append(a[i])
	(c1, c2) = (0, 0)
	if len(a1) > 0 and len(a2) > 0:
		print('Yes')
	elif len(a1) > 0 and sorted(a1) == a1:
		print('Yes')
	elif len(a2) > 0 and sorted(a2) == a2:
		print('Yes')
	else:
		print('No')
	t -= 1


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	f = True
	for i in range(1, n):
		if sum(b) == n or sum(b) == 0:
			f = False
		prev = b[i]
	if a == sorted(a):
		f = True
	if f == True:
		print('Yes')
	else:
		print('No')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	flag = 0
	if 0 in b and 1 in b:
		flag = 1
	else:
		flag = 1
		for i in range(1, n):
			if a[i] < a[i - 1]:
				flag = 0
				break
	if flag == 1:
		print('YES')
	else:
		print('NO')


from collections import deque
from sys import stdin, stdout
import math
input = stdin.readline
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	types = list(map(int, input().split()))
	if types.count(1) and types.count(0):
		print('Yes')
	elif sorted(arr) == arr:
		print('Yes')
	else:
		print('No')


t = int(input())
for test in range(0, t):
	n = int(input())
	arr = list(map(int, input().split()))
	types = input().split()
	aux = sorted(arr)
	if aux != arr and len(set(types)) == 1:
		print('No')
	else:
		print('Yes')


def trouble(n, a, b, k):
	if a == k:
		return 'Yes'
	elif len(b) == 2:
		return 'Yes'
	else:
		return 'No'
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = set(map(int, input().split()))
	k = sorted(a)
	print(trouble(n, a, b, k))


t = input()
t = int(t)
for _ in range(t):
	n = input()
	n = int(n)
	a = input()
	a = a.split(' ')
	b = input()
	b = b.split(' ')
	for k in range(n):
		a[k] = int(a[k])
		b[k] = int(b[k])
	bo = True
	k = 1
	while bo and k < n:
		if a[k - 1] > a[k]:
			bo = False
		k += 1
	if bo:
		print('Yes')
	else:
		t0 = False
		t1 = False
		for i in range(n):
			if b[i] == 0:
				t0 = True
			else:
				t1 = True
		if t0 and t1:
			print('Yes')
		else:
			print('No')


R = lambda : map(int, input().split())
(t,) = R()
exec(t * "R();a=[*R()];print('NYoe s'[{*R()}>{0}or a==sorted(a)::2]);")


def check(arr):
	for i in range(len(a) - 1):
		if arr[i] > arr[i + 1]:
			return False
	return True
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split(' ')))
	b = map(int, input().split(' '))
	if check(a):
		print('Yes')
	elif len(set(b)) == 2:
		print('Yes')
	else:
		print('No')


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	b = list(map(int, input().split()))
	s = sorted(arr)
	if 0 in b and 1 in b or arr == s:
		print('Yes')
	else:
		print('No')


from __future__ import division, print_function
import itertools
import sys
import os
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	input = raw_input
	range = xrange
	filter = itertools.ifilter
	map = itertools.imap
	zip = itertools.izip

def is_it_local():
	script_dir = str(os.getcwd()).split('/')
	username = 'dipta007'
	return username in script_dir

def READ(fileName):
	if is_it_local():
		sys.stdin = open(f'./{fileName}', 'r')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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

def input1(type=int):
	return type(input())

def input2(type=int):
	[a, b] = list(map(type, input().split()))
	return (a, b)

def input3(type=int):
	[a, b, c] = list(map(type, input().split()))
	return (a, b, c)

def input_array(type=int):
	return list(map(type, input().split()))

def input_string():
	s = input()
	return list(s)
mp = {}
ar = []
ty = []
sr = []
vis = []

def dfs(u):
	vis[u] = 1
	ret = 0
	for v in mp.get(u, []):
		if vis[v] == 0:
			dfs(v)
	return ret

def main():
	t = input1()
	for ci in range(t):
		n = input1()
		global mp, ar, ty, sr, vis
		ar = input_array()
		ty = input_array()
		sr = sorted(ar)
		mp = {}
		vis = [0 for _ in range(n + 4)]
		for i in range(len(ar)):
			if i not in mp:
				mp[i] = []
			for j in range(len(ar)):
				if ty[i] != ty[j]:
					mp[i].append(j)
		for i in range(n):
			if vis[i] == 0 and sr[i] != ar[i]:
				dfs(i)
				break
		flg = 1
		for i in range(n):
			if vis[i] == 0 and sr[i] != ar[i]:
				flg = 0
		if flg:
			print('Yes')
		else:
			print('No')
	pass
READ('in.txt')
main()


ans = []
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if a == sorted(a):
		ans.append('Yes')
	elif b.count(b[0]) == len(b):
		ans.append('No')
	else:
		ans.append('Yes')
print(*ans, sep='\n')


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().rstrip().split()))
	b = list(map(int, input().rstrip().split()))
	ck = True
	ctr1 = 0
	ctr0 = 0
	elem = {}
	for i in range(n):
		elem[b[i]] = True
		if b[i] == 1:
			if ctr1 <= a[i]:
				ctr1 = a[i]
			else:
				ck = False
		if b[i] == 0:
			if ctr0 <= a[i]:
				ctr0 = a[i]
			else:
				ck = False
	if not ck and len(elem) == 1:
		print('No')
	else:
		print('Yes')


from sys import stdin, stdout
for t in range(int(stdin.readline().strip())):
	n = int(stdin.readline().strip())
	a = list(map(int, stdin.readline().strip().split()))
	b = list(map(int, stdin.readline().strip().split()))
	if n == 1:
		stdout.write('Yes\n')
		continue
	flag = False
	for i in range(1, n):
		if b[i] != b[i - 1]:
			stdout.write('Yes\n')
			flag = True
			break
	if flag:
		continue
	c = a.copy()
	a.sort()
	if c == a:
		stdout.write('Yes\n')
	else:
		stdout.write('No\n')


x = lambda : list(map(int, input().split()))
for _ in ' ' * int(input()):
	input()
	(a, b) = (x(), x())
	print('NYoe s'[len(set(b)) > 1 or sorted(a) == a::2])


import sys
cont = sys.stdin.readlines()
cont = [i.strip('\n').split() for i in cont]
numTests = int(cont.pop(0)[0])
newCont = []
for i in range(numTests):
	newCont.append(cont[:3])
	cont = cont[3:]
cont = newCont
ans = []
for case in cont:
	a = case[1]
	b = case[2]
	for i in range(len(a)):
		a[i] = int(a[i])
	if a == sorted(a):
		ans.append('Yes')
	elif len(set(b)) != 1:
		ans.append('Yes')
	else:
		ans.append('No')
for i in ans:
	print(i)


def parseint():
	ln = input().split()
	for i in range(len(ln)):
		ln[i] = int(ln[i])
	return ln

def is_monotonic(l):
	for i in range(len(l) - 1):
		if l[i] > l[i + 1]:
			return False
	return True

def solve(a, b):
	a0 = [a[i] for i in range(len(a)) if b[i] == 0]
	a1 = [a[i] for i in range(len(a)) if b[i] == 1]
	if len(a0) > 0 and len(a1) > 0:
		print('Yes')
	elif is_monotonic(a0) and is_monotonic(a1):
		print('Yes')
	else:
		print('No')
t = int(input())
for i in range(t):
	n = int(input())
	a = parseint()
	b = parseint()
	solve(a, b)


for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	r = sorted(a)
	if r == a:
		print('Yes')
	elif 0 in b and 1 in b:
		print('Yes')
	elif 1 not in b or 0 not in b:
		print('No')


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	types = list(map(int, input().split()))
	ans = 'YES'
	if types.count(0) == n or types.count(1) == n:
		for i in range(n - 1):
			if arr[i] > arr[i + 1]:
				ans = 'NO'
				break
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	l1 = list(map(int, input().split()))
	a = []
	for j in range(n):
		a.append(l[j])
	l.sort()
	if a == l:
		print('Yes')
	elif 1 in l1 and 0 in l1:
		print('Yes')
	else:
		print('No')


import sys

def arr():
	return list(map(int, input().split()))
input = sys.stdin.readline
from collections import defaultdict
import math
for _ in range(int(input())):
	N = int(input())
	L1 = list(map(int, input().split()))
	L2 = list(map(int, input().split()))
	if sorted(L1) == L1:
		print('YES')
		continue
	flag1 = False
	flag2 = False
	for i in L2:
		if i == 0:
			flag1 = True
		else:
			flag2 = True
	if flag1 and flag2:
		print('YES')
	else:
		print('NO')


R1 = lambda : list(map(int, input().split()))
R2 = lambda : int(input())
for _ in range(R2()):
	n = R2()
	(A, B) = (R1(), R1())
	is_s = False
	o_s = s = 0
	res = 'Yes'
	for i in range(n - 1):
		if A[i] > A[i + 1]:
			res = 'No'
		if B[i] != B[i + 1]:
			res = 'Yes'
			break
	print(res)


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	f = 0
	for i in range(1, len(l)):
		if l[i] >= l[i - 1]:
			if i == n - 1:
				f = 1
		else:
			break
	if len(l) == 1:
		f = 1
	o = 0
	z = 0
	for i in range(len(l)):
		if l2[i] == 0:
			z += 1
		else:
			o += 1
	if o and z:
		print('yes')
	elif f == 1:
		print('yes')
	else:
		print('no')


import sys
import math
from collections import defaultdict

def solve(test):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if sorted(a) == a:
		print('Yes')
		return
	rec = [(a[i], b[i], i) for i in range(n)]
	rec.sort(key=lambda x: x[0])
	(ones, zeros) = (0, 0)
	flag = 0
	flag2 = 0
	for i in range(n):
		if rec[i][1]:
			ones += i - rec[i][2]
			flag = 1
		else:
			zeros += i - rec[i][2]
			flag2 = 1
	print('Yes' if ones + zeros == 0 and flag and flag2 else 'No')
test_cases = int(input())
for t in range(1, test_cases + 1):
	solve(t)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	a = list(map(int, input().split()))
	f = True
	for i in range(n - 1):
		if l[i + 1] < l[i]:
			f = False
			break
	if (sum(a) == n or sum(a) == 0) and (not f):
		print('NO')
	else:
		print('YES')


t = int(input())
for i in range(t):
	n = int(input())
	a = [int(val) for val in input().split()]
	b = [int(val) for val in input().split()]
	isSorted = True
	isSameType = True
	for i in range(1, n):
		if a[i] < a[i - 1]:
			isSorted = False
		if b[i] != b[i - 1]:
			isSameType = False
	if isSorted or not isSameType:
		print('Yes')
	else:
		print('No')


ll = lambda : list(map(int, input().split()))
s = lambda : input()
v = lambda : map(int, input().split())
ii = lambda : int(input())
import math
from collections import Counter
for _ in range(ii()):
	x = ii()
	a = ll()
	b = ll()
	if a == sorted(a):
		print('Yes')
	elif b.count(0) > 0 and b.count(1) > 0:
		print('Yes')
	else:
		print('No')


from sys import stdin
from collections import deque
mod = 10 ** 9 + 7
import sys
import random
from queue import PriorityQueue
from bisect import bisect_right
from bisect import bisect_left
from collections import defaultdict
from math import sqrt, factorial, gcd, log2, inf, ceil
import heapq
input = lambda : sys.stdin.readline().rstrip()
from sys import stdin, stdout
from heapq import heapify, heappush, heappop
from itertools import permutations
from math import factorial as f

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p
import sys
t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	z = l.copy()
	l1 = list(map(int, input().split()))
	z.sort()
	if z == l:
		print('Yes')
	elif len(set(l1)) == 2:
		print('Yes')
	else:
		print('No')


t = int(input())
for _ in range(t):
	n = int(input())
	a_vec = [int(x) for x in input().split()]
	b_vec = [int(x) for x in input().split()]
	tmp = 0
	flag = True
	for aa in a_vec:
		if aa < tmp:
			flag = False
			break
		tmp = aa
	if flag:
		print('Yes')
	elif len(set(b_vec)) > 1:
		print('Yes')
	else:
		print('No')


for j in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a1 = a[:]
	a.sort()
	if a1 == a or b.count(1) * b.count(0) > 0:
		print('Yes')
	else:
		print('No')


q = int(input())
while q:
	q = q - 1
	n = int(input())
	v = list(map(int, input().split()))
	t = list(map(int, input().split()))
	s = sorted(v)
	if s == v:
		print('Yes')
	else:
		(zero, one) = (0, 0)
		for w in t:
			if w == 0:
				zero += 1
			else:
				one += 1
		if zero >= 1 and one >= 1:
			print('Yes')
		else:
			print('No')


def issort(A):
	for i in range(len(A) - 1):
		if int(A[i]) > int(A[i + 1]):
			return False
	return True

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

def f(A, B):
	if issort(A):
		return 'Yes'
	if issame(B):
		return 'No'
	return 'Yes'
t = int(input())
for i in range(t):
	n = input()
	A = input().split(' ')
	B = input().split(' ')
	print(f(A, B))


a = input()
for x in range(int(a)):
	b = input()
	c = input().split(' ')
	list1 = [int(i) for i in c]
	d = input().split(' ')
	list2 = [int(i) for i in d]
	list3 = list1.copy()
	list3.sort()
	if list2.count(1) == len(list2) or list2.count(0) == len(list2):
		if list3 != list1:
			print('No')
		else:
			print('Yes')
	else:
		print('Yes')


def solution():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = [] + a
	c.sort()
	am = True
	for i in range(n):
		if a[i] != c[i]:
			am = False
			break
	if am:
		print('YES')
		return
	ans = False
	t1 = 0
	t0 = 0
	for i in range(n):
		if b[i] == 1:
			t1 += 1
		else:
			t0 += 1
		if t1 > 0 and t0 > 0:
			print('YES')
			return
	print('NO')
T = int(input())
for t in range(T):
	solution()


for _ in range(int(input())):
	n = int(input())
	x = list(map(int, input().split()))
	y = list(map(int, input().split()))
	if x == sorted(x):
		print('Yes')
	elif 1 in y and 0 in y:
		print('Yes')
	else:
		print('No')


q = int(input())
for _ in range(q):
	n = int(input())
	val = list(map(int, input().split()))
	type = list(map(int, input().split()))
	if type.count(1) > 0 and type.count(0) > 0:
		print('Yes')
	else:
		odp = True
		for i in range(1, n):
			if val[i] < val[i - 1]:
				odp = False
				break
		if odp:
			print('Yes')
		else:
			print('No')


for _ in range(int(input())):
	n = int(input())
	v = [int(x) for x in input().split()]
	t = [int(x) for x in input().split()]
	c0 = t.count(0)
	c1 = t.count(1)
	rv = sorted(v)
	if c0 == 0 or c1 == 0:
		if rv == v:
			print('Yes')
		else:
			print('No')
	else:
		print('Yes')


from collections import Counter
for t in range(int(input())):
	j = int(input())
	n = [int(n) for n in input().split()]
	m = input().split()
	if sorted(n) == n:
		print('Yes')
	elif len(Counter(m)) > 1:
		print('Yes')
	else:
		print('No')


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
import bisect
from heapq import *
from math import *
from collections import deque
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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

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

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

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

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

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

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

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

def graph(vertex):
	return [[] for i in range(0, vertex + 1)]

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

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

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

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

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

def power(a, b):
	ans = 1
	while b > 0:
		if b % 2 == 1:
			ans *= a
		a *= a
		b //= 2
	return ans

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

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

def solve():
	n = int(inp())
	a = lis()
	b = lis()
	if len(set(b)) == 2:
		print('Yes')
	elif a == sorted(a):
		print('Yes')
	else:
		print('No')
testcase(int(inp()))


for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	if len(set(b)) == 2 or sorted(a) == a:
		print('Yes')
	else:
		print('No')


t = int(input(''))
for i in range(t):
	n = int(input(''))
	arr = list(map(int, input().split()))
	b = list(map(int, input().split()))
	comp = sorted(arr)
	if arr == comp:
		print('Yes')
		continue
	if b.count(0) != 0 and b.count(1) != 0:
		print('Yes')
		continue
	print('No')


R = lambda : map(int, input().split())
(t,) = R()
for _ in [0] * t:
	R()
	a = [[], []]
	for (x, y) in zip(R(), R()):
		a[y] += (x,)
	print('NYoe s'[all(a) or all((x == sorted(x) for x in a))::2])


t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	if 0 < sum(b) < len(b):
		print('Yes')
	elif a == sorted(a):
		print('Yes')
	else:
		print('No')


for t in range(int(input())):
	n = int(input())
	values = [int(x) for x in input().split()]
	types = [int(x) for x in input().split()]
	print('Yes' if len(set(types)) > 1 or values == sorted(values) else 'No')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	(OneIf, ZeroIf) = (False, False)
	for i in range(n):
		if b[i] == 1:
			OneIf = True
		else:
			ZeroIf = True
	if OneIf and ZeroIf:
		print('Yes')
	else:
		f = True
		for i in range(1, n):
			if a[i - 1] > a[i]:
				f = False
				break
		if f:
			print('Yes')
		else:
			print('No')


n = int(input())
for x in range(n):
	sch = 0
	l = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	for i in range(l - 1):
		if a[i] <= a[i + 1]:
			sch += 1
		else:
			break
	if sch == l - 1:
		print('Yes')
		continue
	hp = 0
	for i in range(l - 1):
		if b[i] == b[i + 1]:
			hp += 1
		else:
			break
	if hp == l - 1:
		print('No')
		continue
	else:
		print('Yes')


def check(ls):
	curr = ls[0]
	for i in range(1, len(ls)):
		if ls[i] < curr:
			return False
		curr = ls[i]
	return True
for test in range(int(input())):
	n = int(input())
	ls = list(map(int, input().split()))
	ar = list(map(int, input().split()))
	if check(ls):
		print('Yes')
	elif len(set(ar)) == 2:
		print('Yes')
	else:
		print('No')


p = int(input())
arr = []
for i in range(p):
	_1 = 0
	_0 = 0
	n = int(input())
	num = [int(d) for d in input().split(' ')]
	type_ = [int(d) for d in input().split(' ')]
	t = 0
	for j in range(len(num)):
		if j < len(num) - 1 and num[j] > num[j + 1]:
			t += 1
	if t == 0:
		arr.append('YES')
		continue
	for j in range(len(type_)):
		if type_[j] == 1:
			_1 += 1
		elif type_[j] == 0:
			_0 += 1
		if _1 > 0 and _0 > 0:
			arr.append('YES')
			break
		if j == len(type_) - 1 and (_1 == 0 or _0 == 0):
			arr.append('NO')
for j in range(len(arr)):
	print(arr[j])


from sys import stdin, stdout
from math import gcd, sqrt
from collections import deque
input = stdin.readline
R = lambda : map(int, input().split())
I = lambda : int(input())
S = lambda : input().rstrip('\n')
P = lambda x: stdout.write(x)
hg = lambda x, y: (y + x - 1) // x * x
N = 10 ** 9 + 7
for _ in range(I()):
	n = I()
	a = list(R())
	b = list(R())
	x = sorted(a)
	if a == x:
		print('YES')
	elif 1 in b and 0 in b:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	is_sorted = 1
	for (i, j) in zip(a[1:], a[:-1]):
		if i < j:
			is_sorted = 0
			break
	if len(list(set(b))) != 1 or is_sorted:
		print('Yes')
	else:
		print('No')


for _ in range(int(input())):
	n = int(input())
	arr = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	temp = sorted(arr)
	if 1 in b and 0 in b or temp == arr:
		print('Yes')
	else:
		print('No')


t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	type = list(map(int, input().split()))
	zeros = type.count(0)
	if zeros == 0 or zeros == n:
		flag = True
		for i in range(n - 1):
			if arr[i] > arr[i + 1]:
				print('No')
				flag = False
				break
		if flag:
			print('Yes')
	else:
		print('Yes')


t = int(input())
for q in range(t):
	n = int(input())
	mas1 = list(map(int, input().split()))
	mas2 = list(map(int, input().split()))
	if sum(mas2) != 0 and sum(mas2) != n:
		print('Yes')
	else:
		f = 0
		for i in range(n - 1):
			if mas1[i] > mas1[i + 1]:
				f = 1
		if f:
			print('No')
		else:
			print('Yes')


t = int(input())
for tc in range(t):
	n = int(input())
	a1 = list(map(int, input().split()))
	b1 = list(map(int, input().split()))
	num = a1[:]
	num.sort()
	if num == a1:
		print('YES')
	else:
		co = b1.count(1)
		if co > 0 and co != n:
			print('YES')
		else:
			print('NO')


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	pos = list(map(int, input().split()))
	if pos.count(0) == 0 or pos.count(1) == 0:
		flag = 0
		for i in range(1, n):
			if arr[i] < arr[i - 1]:
				flag = 1
				print('No')
				break
		if flag == 0:
			print('Yes')
		continue
	else:
		print('Yes')


def solve():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a_copy = a.copy()
	a_copy.sort()
	(o, z) = (0, 0)
	flag = 0
	if a_copy == a:
		flag = 1
	for i in b:
		if i:
			o = 1
		else:
			z = 1
		if o == 1 and z == 1:
			break
	if o == 1 and z == 1:
		print('Yes')
	elif flag == 1:
		print('Yes')
	else:
		print('No')
t = int(input())
while t:
	solve()
	t = t - 1


for test_case in range(int(input())):
	array_size = int(input())
	values = list(map(int, input().split()))
	state = list(map(int, input().split()))
	ones = state.count(1)
	zeros = state.count(0)
	sorted_list = sorted(values)
	if sorted_list == values:
		print('YES')
	elif ones > 0 and zeros > 0:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	if a == sorted(a):
		print('Yes')
	elif any([b[i] != b[i - 1] for i in range(1, n)]):
		print('Yes')
	else:
		print('No')


t = int(input())
for _ in range(t):
	n = int(input())
	ar = list(map(int, input().split()))
	ar2 = list(map(int, input().split()))
	sorted1 = 1
	if n > 1:
		for i in range(1, n):
			if ar[i] < ar[i - 1]:
				sorted1 = 0
				break
	zeroes = 0
	once = 0
	for i in range(n):
		if ar2[i] == 1:
			once += 1
		else:
			zeroes += 1
	if sorted1 == 1:
		print('Yes')
	elif once > 0 and zeroes > 0:
		print('Yes')
	else:
		print('No')


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

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

def inputArray():
	return input().rstrip().split()

def inputVars():
	return map(int, input().rstrip().split())

def inputNum():
	return int(input())

def main():
	for _ in range(inputNum()):
		n = inputNum()
		arrVal = inputIntArray()
		arrType = inputIntArray()
		if arrVal == sorted(arrVal):
			print('Yes')
		else:
			check = True
			for pos in range(1, n):
				if arrType[pos] != arrType[pos - 1]:
					check = False
					break
			if check:
				print('No')
			else:
				print('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()


r = lambda : list(map(int, input().split()))
for _ in range(r()[0]):
	(n, a, b) = (r()[0], r(), r())
	print('No\n' if b.count(1) in [0, n] and a != sorted(a) else 'Yes\n')


def solve(n, a, b):
	sign = b[0]
	for i in range(1, n):
		if b[i] != sign:
			return 'Yes'
	if a == sorted(a):
		return 'Yes'
	else:
		return 'No'
t = int(input())
for i in range(t):
	(n, a, b) = (int(input()), [int(i) for i in input().split()], [int(i) for i in input().split()])
	print(solve(n, a, b))


for _ in range(int(input())):
	num = int(input())
	arr_a = list(map(int, input().split()))
	arr_b = list(map(int, input().split()))
	aa = []
	t = arr_b.count(1)
	if t == 0 or t == num:
		if sorted(arr_a) == arr_a:
			print('Yes')
			continue
		else:
			print('No')
			continue
	for i in range(num):
		aa.append([arr_a[i], arr_b[i]])
	aa.sort()
	bb = [i[1] for i in aa]
	result = []
	for i in range(num):
		result.append(bb[i] ^ arr_b[i])
	ans = result.count(1)
	if ans % 2 == 0:
		print('Yes')
	else:
		print('No')


import sys
import math

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

def get_list():
	return list(get_ints())

def printspx(*args):
	return print(*args, end='')

def printsp(*args):
	return print(*args, end=' ')

def printchk(*args):
	return print(*args, end=' \\ ')
MODPRIME = int(1000000000.0 + 7)
BABYMODPR = 998244353
from collections import Counter
for _testcases_ in range(int(input())):
	n = int(input())
	a = get_list()
	b = get_list()
	li = list()
	for i in range(n):
		li.append([a[i], b[i]])
	sorted_list = li.copy()
	sorted_list.sort(key=lambda x: x[0])
	flag = True
	one = False
	zero = False
	same = diff = 0
	for i in range(n):
		if sorted_list[i][0] != li[i][0]:
			flag = False
		if li[i][1] == 0:
			zero = True
		elif li[i][1] == 1:
			one = True
	if flag:
		print('Yes')
	elif one and zero:
		print('Yes')
	else:
		print('No')


wer = int(input())
for ewr in range(wer):
	n = int(input())
	l1 = list(map(int, input().split(' ')))
	l2 = list(map(int, input().split(' ')))
	li = []
	flag = 0
	li.append([l1[0], l2[0]])
	for i in range(1, n):
		li.append([l1[i], l2[i]])
		if l2[i] != l2[i - 1]:
			flag = 1
	if flag == 1:
		print('Yes')
	else:
		for i in range(n - 1):
			if l1[i] > l1[i + 1]:
				print('No')
				flag = 2
				break
		if flag == 0:
			print('Yes')


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split(' ')))
	b = list(map(int, input().split(' ')))
	c = a[:]
	c.sort()
	if c == a:
		print('Yes')
	elif len(set(b)) == 1:
		print('No')
	else:
		print('Yes')


import sys
from collections import defaultdict as dd
from queue import Queue
import math
import itertools
try:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
except:
	pass
input = lambda : sys.stdin.buffer.readline().rstrip()
for _ in range(int(input())):
	n = int(input())
	q = list(map(int, input().split()))
	w = list(map(int, input().split()))
	t = 0
	e = sorted(q)
	if e == q:
		print('YES')
	elif 1 in w and 0 in w:
		print('YES')
	else:
		print('NO')


def main():
	first = []
	second = []
	for i in range(505):
		first.append(0)
		second.append(0)
	control = int(input())
	while control != 0:
		come = int(input())
		flag = 1
		temp = 1
		str = list(input().split(' '))
		count = 1
		for i in str:
			first[count] = int(i)
			count += 1
		count = 1
		str = list(input().split(' '))
		for i in str:
			second[count] = int(i)
			count += 1
		for i in range(1, come):
			if second[i] != second[i + 1]:
				temp = 0
		if temp != 0:
			for i in range(1, come):
				if first[i] > first[i + 1]:
					flag = 0
			if flag == 0:
				print('No')
			else:
				print('Yes')
		else:
			print('Yes')
		control -= 1
main()


t = int(input())
for z in range(t):
	n = int(input())
	s1 = input().split()
	s2 = input().split()
	for i in range(n):
		s1[i] = int(s1[i])
	k = 0
	for i in range(n):
		k += s2[i] == '0'
	if k > 0 and k < n or s1 == sorted(s1):
		print('Yes')
	else:
		print('No')


t = int(input())
for k in range(t):
	n = int(input())
	a = list(map(int, input().split(' ')))
	b = list(map(int, input().split(' ')))
	f = 0
	o = 0
	z = 0
	for i in range(0, n, 1):
		for j in range(i + 1, n, 1):
			if a[i] > a[j]:
				f = 1
				break
	if f == 0:
		print('yes')
	else:
		for i in range(0, n, 1):
			if b[i] == 0:
				z += 1
			else:
				o += 1
	if f == 1:
		if o > 0 and z > 0:
			print('Yes')
		else:
			print('No')


def is_sorted(arr):
	if len(arr) < 2:
		return True
	for i in range(1, len(arr)):
		if arr[i] < arr[i - 1]:
			return False
	return True
t = int(input())
for _ in range(t):
	n = int(input())
	a_s = list(map(int, input().split(' ')))
	b_s = list(map(int, input().split(' ')))
	if is_sorted(a_s):
		print('Yes')
		continue
	xs = list(zip(a_s, b_s))
	zeros = [x[0] for x in xs if x[1] == 0]
	ones = [x[0] for x in xs if x[1] == 1]
	if len(zeros) > 0 and len(ones) > 0:
		print('Yes')
	else:
		print('No')


t = int(input())
for _ in range(t):
	n = int(input())
	nums = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if sorted(nums) == nums:
		out = 'Yes'
	elif len(set(b)) == 1:
		out = 'No'
	else:
		out = 'Yes'
	print(out)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = a[:]
	c.sort()
	ans = 1
	if a == c:
		print('Yes')
	else:
		c = b.count(1)
		d = b.count(0)
		if c and d:
			print('Yes')
		else:
			print('No')


def solve(n, a, b):
	bsum = sum(b)
	a_sort = a[:]
	a_sort.sort()
	ans = 1
	if bsum == 0 or bsum == n:
		if a != a_sort:
			ans = 0
	if ans == 1:
		print('YES')
	else:
		print('NO')
	return
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	solve(n, a, b)


import sys, math
import io, os

def data():
	return sys.stdin.buffer.readline().strip()

def mdata():
	return list(map(int, data().split()))

def outl(var):
	sys.stdout.write(' '.join(map(str, var)) + '\n')

def out(var):
	sys.stdout.write(str(var) + '\n')
mod = int(1000000000.0) + 7

def main():
	for t in range(int(data())):
		n = int(data())
		a = mdata()
		b = mdata()
		a1 = []
		a2 = []
		flag = True
		for i in range(n):
			if b[i] == 0:
				a1.append(a[i])
			else:
				a2.append(a[i])
		if len(a2) == 0:
			for i in range(len(a1) - 1):
				if a1[i + 1] - a1[i] < 0:
					flag = False
					break
			if flag == False:
				out('No')
				continue
		elif len(a1) == 0:
			for i in range(len(a2) - 1):
				if a2[i + 1] - a2[i] < 0:
					flag = False
					break
			if flag == False:
				out('No')
				continue
		out('Yes')
main()


t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().strip().split()))
	brr = list(map(int, input().strip().split()))
	crr = sorted(arr)
	if arr == crr:
		print('Yes')
	else:
		count1 = 0
		count0 = 0
		for j in range(n):
			if brr[j] == 0:
				count0 = count0 + 1
			else:
				count1 = count1 + 1
		if count0 != n and count1 != n:
			print('Yes')
		else:
			print('No')


t = int(input())
results = []
for case in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ans = 'Yes'
	if 1 in b and 0 not in b:
		ans = 'No'
	elif 0 in b and 1 not in b:
		ans = 'No'
	if a == sorted(a):
		ans = 'Yes'
	results.append(ans)
for result in results:
	print(result)


for I in range(int(input())):
	n = input()
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	zeros = 0
	ones = 0
	for num in b:
		if num == 1:
			ones += 1
		else:
			zeros += 1
	if ones > 0 and zeros > 0:
		print('YES')
	else:
		c = a[:]
		a.sort()
		if a == c:
			print('YES')
		else:
			print('NO')


from sys import stdin

def inp():
	return stdin.readline().strip()
t = int(inp())
for _ in range(t):
	n = int(inp())
	a = [int(x) for x in inp().split()]
	b = [int(x) for x in inp().split()]
	if a == sorted(a):
		print('Yes')
	elif 1 in b and 0 in b:
		print('Yes')
	else:
		print('No')


def main():
	n = int(input())
	a = list(map(int, input().split(' ')))
	b = list(map(int, input().split(' ')))
	if a == list(sorted(a)):
		return True
	bsum = sum(b)
	if bsum == n or bsum == 0:
		return False
	return True
for t in range(int(input())):
	print('Yes' if main() else 'No')


import sys
input = sys.stdin.readline
for T in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	tp = list(map(int, input().split()))
	cnt0 = 0
	cnt1 = 0
	ans = True
	for i in range(n):
		if i < n - 1 and arr[i] > arr[i + 1]:
			ans = False
		if tp[i] == 0:
			cnt0 += 1
		else:
			cnt1 += 1
	if ans:
		print('Yes')
	elif cnt1 == 0 or cnt0 == 0:
		print('No')
	else:
		print('Yes')


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(_) for _ in input().split()]
	b = [int(_) for _ in input().split()]
	sumB = sum(b)
	if sumB == 0 or sumB == n:
		flg = True
		for i in range(n - 1):
			if a[i] <= a[i + 1]:
				pass
			else:
				flg = False
				break
		if flg:
			print('Yes')
		else:
			print('No')
	else:
		print('Yes')


import sys
input = sys.stdin.readline
tcs = int(input())
for tc in range(tcs):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if a == sorted(a):
		print('Yes')
		continue
	zeros = 0
	ones = 0
	for i in range(n):
		if b[i] == 0:
			zeros += 1
		else:
			ones += 1
	if zeros and ones:
		print('Yes')
	else:
		print('No')


import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__

def gift():
	for _ in range(t):
		n = int(input())
		eles = list(map(int, input().split()))
		types = list(map(int, input().split()))
		if sum(types) == 0 or sum(types) == n:
			eleina = sorted(eles)
			if eleina == eles:
				yield 'YES'
			else:
				yield 'NO'
		else:
			yield 'YES'
t = int(input())
ans = gift()
print(*ans, sep='\n')


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if n == 1:
		print('Yes')
	else:
		p = 0
		q = 0
		for i in b:
			if i == 0:
				p = p + 1
		q = n - p
		if p == n or q == n:
			f = 0
			for i in range(n - 1):
				if a[i + 1] < a[i]:
					f = 1
					break
			if f == 1:
				print('No')
			else:
				print('Yes')
		else:
			print('Yes')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	cnt = 1
	for i in range(n - 1):
		if a[i + 1] < a[i]:
			break
		else:
			cnt += 1
	if cnt == n:
		print('YES')
	elif len(set(b)) == 1:
		print('NO')
	else:
		print('YES')


import sys
input = lambda : sys.stdin.readline().rstrip()
inp = sys.stdin.buffer.readline

def I():
	return list(map(int, inp().split()))
for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	if a == sorted(a):
		print('Yes')
	elif len(set(b)) == 2:
		print('Yes')
	else:
		print('No')


for _ in range(int(input())):
	n = int(input())
	val = list(map(int, input().split()))
	bin = list(map(int, input().split()))
	bul = False
	for i in range(1, n):
		if val[i] < val[i - 1]:
			bul = True
			break
	count = 0
	for i in range(n):
		if bin[i] == 0:
			count += 1
	if bul and (count == 0 or count == n):
		print('NO')
	else:
		print('YES')


import sys
ip = lambda : sys.stdin.readline().rstrip()
for _ in range(int(ip())):
	n = int(ip())
	a = list(map(int, ip().split()))
	b = list(map(int, ip().split()))
	c = [a[i] for i in range(n)]
	c.sort()
	ans = True
	if c != a:
		if 0 not in b or 1 not in b:
			ans = False
	if ans:
		print('yes')
	else:
		print('no')


import math

def Divisors(n):
	l = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				l.append(i)
			else:
				l.append(i)
				l.append(n // i)
		i = i + 1
	return l

def SieveOfEratosthenes(n):
	l = []
	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]:
			l.append(p)
	return l

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

def Factors(n):
	result = []
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			if i == n / i:
				result.append(i)
			else:
				result.append(i)
				result.append(n // i)
	result.append(1)
	result.append(n)
	return result

def maxSubArraySum(a):
	max_so_far = 0
	max_ending_here = 0
	size = len(a)
	for i in range(0, size):
		max_ending_here = max_ending_here + a[i]
		if max_so_far < max_ending_here:
			max_so_far = max_ending_here
		if max_ending_here < 0:
			max_ending_here = 0
	return max_so_far

def main():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	l = []
	c1 = 0
	c2 = 0
	for j in range(0, n):
		l.append(a[j])
		if b[j] == 0:
			c1 += 1
		else:
			c2 += 1
	l.sort()
	if c1 > 0 and c2 > 0:
		print('Yes')
	else:
		f = 0
		for j in range(0, n):
			if a[j] != l[j]:
				print('No')
				f = 1
				break
		if f == 0:
			print('Yes')
t = int(input())
for i in range(0, t):
	main()


t = int(input())
for T in range(0, t):
	n = int(input())
	a = input().split()
	b = input().split()
	a = list(map(lambda x: int(x), a))
	b = list(map(lambda x: int(x), b))
	has_one = False
	has_zero = False
	for i in range(0, n):
		if b[i] == 0:
			has_zero = True
		elif b[i] == 1:
			has_one = True
		if has_one and has_zero:
			break
	if has_one and has_zero:
		print('Yes')
	else:
		good = True
		prev = -1
		for i in range(0, n):
			if a[i] < prev:
				good = False
				break
			prev = a[i]
		print('Yes' if good else 'No')


t = int(input())
while t:
	t -= 1
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if sum(b) == n:
		if sorted(a) == a:
			print('Yes')
		else:
			print('No')
	elif sum(b) == 0:
		if sorted(a) == a:
			print('Yes')
		else:
			print('No')
	elif sum(b) >= 1:
		print('Yes')
	else:
		print('No')


for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	if a == sorted(a):
		print('YES')
	else:
		zero = b.count(0)
		one = b.count(1)
		if one > 0 and zero > 0:
			print('YES')
		else:
			print('NO')


t = int(input())
for i in range(t):
	n = int(input())
	a = [int(val) for val in input().split()]
	b = [int(val) for val in input().split()]
	prev_a = 0
	isSorted = True
	(b0, b1) = (0, 0)
	for j in range(n):
		a_j = a[j]
		if a_j < prev_a:
			isSorted = False
		else:
			prev_a = a_j
		if b[j] == 0:
			b0 += 1
		else:
			b1 += 1
	if isSorted:
		print('Yes')
	elif b0 == 0 or b1 == 0:
		print('No')
	else:
		print('Yes')


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().rstrip().split()))
	b = list(map(int, input().rstrip().split()))
	tempa = a[:]
	tempb = b
	k = True
	tempa.sort()
	if tempa == a:
		k = True
	elif sum(b) == len(b) or sum(b) == 0:
		k = False
	else:
		k = True
	if k:
		print('Yes')
	else:
		print('No')


try:
	for _ in range(int(input())):
		n = int(input())
		val = list(map(int, input().split()))
		b = list(map(int, input().split()))
		if val == sorted(val):
			print('Yes')
		elif len(set(b)) == 1:
			print('No')
		else:
			arr = list(zip(val, b))
			flagval = 0
			flagb = 0
			for i in range(n):
				if i > 0 and arr[i][0] >= arr[i - 1][0]:
					flagval = 1
			if flagval != 0:
				flagb = 1
			for i in range(n):
				if i > 0 and arr[i][1] != arr[i - 1][1]:
					flagb = 1
			if flagb == 1:
				print('Yes')
			else:
				print('No')
except EOFError:
	pass


from __future__ import division, print_function
import sys
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
import os, sys, bisect, copy
from collections import defaultdict, Counter, deque
if os.path.exists('in.txt'):
	sys.stdin = open('in.txt', 'r')
if os.path.exists('out.txt'):
	sys.stdout = open('out.txt', 'w')

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

def mapi(arg=0):
	return map(int if arg == 0 else str, input().split())
for _ in range(int(input())):
	n = int(input())
	a = list(mapi())
	b = list(mapi())
	f1 = 1
	f2 = 1
	for i in range(n - 1):
		if b[i] != b[i + 1]:
			f1 = 0
		if a[i] > a[i + 1]:
			f2 = 0
	if f2 or not f1:
		print('Yes')
	else:
		print('No')


def ans(l, l1):
	x = list(dict.fromkeys(l))
	y = list(dict.fromkeys(l1))
	if l == sorted(l):
		print('Yes')
	elif len(y) == 1:
		print('No')
	else:
		print('Yes')
t = int(input())
while t > 0:
	a = int(input())
	l = list(map(int, input().split()))
	l1 = list(map(int, input().split()))
	ans(l, l1)
	t -= 1


t = int(input())
for _ in range(t):
	n = int(input())
	x = list(map(int, input().split()))
	y = list(map(int, input().split()))
	c = [0] * n
	for i in range(n):
		c[i] = x[i]
	s = sum(y)
	c.sort()
	if x == c:
		print('Yes')
	elif s == 0 or s == n:
		print('No')
	else:
		print('Yes')


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	homogeneous = True
	for i in range(1, n):
		if b[i - 1] != b[i]:
			homogeneous = False
			break
	if not homogeneous:
		print('Yes')
	else:
		sorted = True
		for i in range(1, n):
			if a[i - 1] > a[i]:
				sorted = False
		if sorted:
			print('Yes')
		else:
			print('No')


for i in range(int(input())):
	n = int(input())
	massive = [int(item) for item in input().split()]
	weight = {int(item) for item in input().split()}
	res = len(weight) > 1
	res2 = massive == sorted(massive)
	if res or res2:
		print('YES')
	else:
		print('NO')


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

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

def mode(arr):
	value_counts = defaultdict(int)
	for item in arr:
		value_counts[item] = value_counts[item] + 1
	return value_counts

def main():
	for _ in range(int(input())):
		n = int(input())
		a = list(map(int, input().split()))
		b = list(map(int, input().split()))
		temp = a.copy()
		if sorted(temp) == a:
			print('Yes')
		else:
			x = set(b)
			if len(x) == 2:
				print('Yes')
			else:
				print('No')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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


from sys import stdin, stdout
from math import gcd, ceil, sqrt
ii1 = lambda : int(stdin.readline().strip())
is1 = lambda : stdin.readline().strip()
iia = lambda : list(map(int, stdin.readline().strip().split()))
isa = lambda : stdin.readline().strip().split()
mod = 1000000007
tc = ii1()
for _ in range(tc):
	n = ii1()
	arr1 = iia()
	arr2 = iia()
	if sorted(arr1) != arr1 and len(set(arr2)) < 2:
		print('No')
	else:
		print('Yes')


for _ in range(int(input())):
	n = int(input())
	lst = [int(i) for i in input().split()]
	s = set([int(i) for i in input().split()])
	result = len(s) > 1 or lst == sorted(lst)
	print('Yes' if result else 'No')


for i in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	acopy = a[:]
	acopy.sort()
	b = [int(i) for i in input().split()]
	ones = b.count(1)
	zero = b.count(0)
	if acopy == a:
		print('Yes')
	elif ones > 0 and zero > 0:
		print('Yes')
	else:
		print('No')


t = int(input())
for i in range(t):
	incflag = True
	oneflag = False
	n = int(input())
	narr = list(map(int, input().split()))
	barr = list(map(int, input().split()))
	for t in range(1, n):
		if incflag:
			if narr[t] < narr[t - 1]:
				incflag = False
		if oneflag == False:
			if barr[t] != barr[t - 1]:
				oneflag = True
				break
	if oneflag:
		print('Yes')
	elif incflag:
		print('Yes')
	else:
		print('No')


for _ in range(int(input())):
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	r = []
	for i in l1:
		r.append(i)
	l1.sort()
	if 0 in l2 and 1 in l2:
		print('Yes')
	elif r == l1:
		print('Yes')
	else:
		print('No')


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a0 = 0
	a1 = 0
	f = True
	for (i, x) in enumerate(a):
		if b[i]:
			if x < a1:
				f = False
			else:
				a1 = x
		elif x < a0:
			f = False
		else:
			a0 = x
	if len(set(b)) == 2:
		f = True
	if f:
		print('yes')
	else:
		print('no')


tll = int(input())
while tll > 0:
	tll -= 1
	n = int(input())
	val = list(map(int, input().split()))
	typ = list(map(int, input().split()))
	t = [0, 0]
	for i in range(n):
		t[typ[i]] += 1
	flag = True
	if t[0] != 0 and t[1] != 0:
		print('Yes')
		continue
	else:
		for i in range(1, n):
			if val[i] < val[i - 1]:
				flag = False
				break
	if flag == True:
		print('Yes')
		continue
	print('No')


for _ in range(int(input())):
	n = int(input())
	x = list(map(int, input().split()))
	y = sum(map(int, input().split()))
	if y > 0 and y < n:
		print('Yes')
	elif all((u >= v for (u, v) in zip(x[1:], x))):
		print('Yes')
	else:
		print('No')


def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		a = list(map(int, input().split()))
		b = list(map(int, input().split()))
		b_test = 0 in b and 1 in b
		if b_test:
			print('YES')
			continue
		a_test = True
		for i in range(1, n):
			if a[i] < a[i - 1]:
				a_test = False
				break
		if a_test:
			print('YES')
		else:
			print('NO')
main()


for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	aa = a[:]
	aa.sort()
	if b.count(1) == 0 or b.count(0) == 0:
		if a == aa:
			print('Yes')
		else:
			print('No')
	else:
		print('Yes')


for _ in range(int(input())):
	n = int(input())
	N = list(map(int, input().split()))
	A = list(map(int, input().split()))
	(p, f) = (N[0], True)
	for i in N[1:]:
		if p > i:
			f = False
			break
		p = i
	if f:
		print('Yes')
		continue
	if sum(A) == 0 or sum(A) == n:
		print('No')
		continue
	print('Yes')


def trouble_sort(a, b, n):
	ones = 0
	zeros = 0
	for i in range(n):
		if b[i] == 1:
			ones += 1
		else:
			zeros += 1
	if ones > 0 and zeros > 0:
		return True
	elif a == sorted(a):
		return True
	else:
		return False
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	print('YES' if trouble_sort(a, b, n) 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 fact(x):
	if x == 0:
		return 1
	else:
		return x * fact(x - 1)

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

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

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

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

def sieve_of_eratosthenes(n):
	ans = []
	arr = [1] * (n + 1)
	(arr[0], arr[1], i) = (0, 0, 2)
	while i * i <= n:
		if arr[i] == 1:
			j = i + i
			while j <= n:
				arr[j] = 0
				j += i
		i += 1
	for k in range(n):
		if arr[k] == 1:
			ans.append(k)
	return ans

def nc2(x):
	if x == 1:
		return 0
	else:
		return x * (x - 1) // 2
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	asort = a[:]
	asort.sort()
	if asort == a:
		print('Yes')
	else:
		check = set(b)
		if len(check) == 1:
			print('No')
		else:
			print('Yes')


for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	if (1 not in b or 0 not in b) and sorted(a) != a:
		print('NO')
	else:
		print('YES')


import sys
read = sys.stdin.buffer.readline
mi = lambda : map(int, read().split())
cin = lambda : int(read())
li = lambda : list(mi())
for _ in range(cin()):
	n = cin()
	a = li()
	c = li()
	b = a.copy()
	b.sort()
	if a == b:
		print('Yes')
	elif 1 in c and 0 in c:
		print('Yes')
	else:
		print('No')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	t1 = []
	t2 = []
	for i in range(n):
		if b[i] == 1:
			t2.append(a[i])
		else:
			t1.append(a[i])
	if len(t1) != 0 and len(t2) != 0:
		print('Yes')
	elif t1 == sorted(t1) and t2 == sorted(t2):
		print('Yes')
	else:
		print('No')


def isSorted(arr):
	flag = 0
	for i in range(len(arr) - 1):
		if arr[i] > arr[i + 1]:
			flag += 1
	if flag >= 1:
		return 0
	else:
		return 1
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	cond_arr = list(map(int, input().split()))
	if isSorted(arr):
		print('Yes')
	elif cond_arr.count(1) > 0 and cond_arr.count(0) > 0:
		print('Yes')
	else:
		print('No')


import sys
input = lambda : sys.stdin.readline().strip('\r\n')
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if len(set(b)) == 1 and sorted(a) == a or len(set(b)) == 2:
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.readline
output = sys.stdout

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

def solve(n, a, b):
	var = True
	c = []
	c.extend(a)
	c.sort()
	for i in range(n):
		if a[i] != c[i]:
			var = False
			break
	if var:
		res = 'Yes'
	else:
		s = sum(b)
		if s == 0 or s == n:
			res = 'No'
		else:
			res = 'Yes'
	output.write(res + '\n')
t = int(input())
for i in range(t):
	n = int(input())
	a = inlt()
	b = inlt()
	solve(n, a, b)


from sys import stdin
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	b = list(map(int, stdin.readline().split()))
	need_swap = False
	for i in range(n - 1):
		if a[i] > a[i + 1]:
			need_swap = True
			break
	res = 'Yes'
	if need_swap:
		has_both = False
		for i in range(n - 1):
			if b[i] != b[i + 1]:
				has_both = True
				break
		if not has_both:
			res = 'No'
	print(res)


t = int(input())
for q in range(t):
	l = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a1 = a.copy()
	a.sort()
	sm = sum(b)
	m = len(b)
	d = {}
	cnt = 0
	for i in a1:
		d[i] = b[cnt]
		cnt = +1
	if a == a1:
		print('Yes')
	else:
		cnt = 0
		flag = 0
		for i in range(len(a1)):
			if a1[i] == a[i]:
				continue
			elif d[a1[i]] == 0:
				if sm >= 1:
					a1[i] = a[i]
					cnt += 1
				else:
					flag = 1
					break
			elif sm < m:
				a1[i] = a[i]
				cnt += 1
			else:
				flag = 1
				break
		if flag == 0:
			print('Yes')
		else:
			print('No')


t = int(input())
for i in range(1, t + 1):
	n = int(input())
	aList = [int(s) for s in input().split(' ')]
	bList = [int(s) for s in input().split(' ')]
	qa = True
	qb = False
	for i in range(1, n):
		if aList[i - 1] > aList[i]:
			qa = False
		if bList[i - 1] != bList[i]:
			qb = True
	print('Yes' if qa or qb else 'No')


def main():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if a == sorted(a):
		print('Yes')
		return
	tp = b[0]
	if (tp - 1) % 2 in b:
		print('Yes')
	else:
		print('No')

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


for i in range(int(input())):
	n = int(input())
	ele = [int(i) for i in input().split()][:n]
	ty = [int(j) for j in input().split()][:n]
	if ty.count(1) % n == 0 and ele != sorted(ele):
		print('No')
	else:
		print('Yes')


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	first = []
	second = []
	for i in range(n):
		if b[i] == 0:
			first.append(a[i])
		else:
			second.append(a[i])
	if len(first) == 0 and sorted(second) != second or (len(second) == 0 and sorted(first) != first):
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	z = 0
	o = 0
	for i in range(n):
		if b[i] == 0:
			z += 1
		if b[i] == 1:
			o += 1
	if z == n or o == n:
		if sorted(a) == a:
			print('YES')
		else:
			print('NO')
	elif o >= 1 and z >= 1:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	flag = 1
	c1 = 0
	c2 = 0
	for i in range(n - 1):
		if a[i] <= a[i + 1]:
			flag = 1
		else:
			flag = 0
			break
	if flag:
		print('Yes')
	else:
		for i in range(n):
			if b[i] == 0:
				c1 += 1
			elif b[i] == 1:
				c2 += 1
		if c1 == 0 or c2 == 0:
			print('No')
		else:
			print('Yes')


import sys

def all(types):
	return sum(types) == 0 or sum(types) == len(types)
lines = []
for i in sys.stdin:
	lines.append(i)
num_games = int(lines[0].split()[0])
for i in range(num_games):
	vals = list(map(int, lines[2 + 3 * i].split()))
	types = list(map(int, lines[3 + 3 * i].split()))
	if sorted(vals) != vals and all(types):
		print('No')
	else:
		print('Yes')


ct = input()
for _ in range(int(ct)):
	n = input()
	arr = [int(i) for i in input().split()]
	snd = [int(i) for i in input().split()]
	multiFlag = sum(snd) / len(snd)
	if arr == sorted(arr) or (multiFlag > 0 and multiFlag < 1):
		print('YES')
	else:
		print('NO')


def testCase():
	nElements = int(input())
	elements = list(map(int, input().split(' ')))
	types = list(map(int, input().split(' ')))
	return (elements, types)

def isSortable(elements, types):
	if sorted(elements) != elements and all((types[0] == x for x in types)):
		return 'No'
	return 'Yes'
testCases = int(input())
[print(isSortable(*testCase())) for x in range(testCases)]


def tbs(l1, l2):
	if l1 == sorted(l1):
		print('yes')
		return
	elif l2.count(0) == len(l2) or l2.count(1) == len(l2):
		if l1 == sorted(l1):
			print('yes')
		else:
			print('no')
		return
	elif l2.count(0) > 0 and l2.count(1) > 0:
		print('yes')
	return
t = int(input())
for i in range(t):
	n = int(input())
	t1 = input()
	t2 = input()
	l1 = list(map(int, t1.split(' ')))
	l2 = list(map(int, t2.split(' ')))
	tbs(l1, l2)


t = int(input())
while t:
	t -= 1
	n = int(input())
	l = list(map(int, input().split()))
	p = list(map(int, input().split()))
	flag = 1
	f = 0
	if n == 1:
		print('YES')
		flag = 0
	if flag:
		for i in range(1, n):
			if l[i - 1] > l[i]:
				f = 1
				break
			elif i == n - 1:
				print('YES')
		if f:
			ff = 1
			for i in range(1, n):
				if p[i] != p[i - 1]:
					print('YES')
					ff = 0
					break
			if ff:
				print('NO')


from sys import stdin

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

def sinput():
	return input()

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

def linput():
	return list(map(int, stdin.readline().split()))
t = iinput()
while t:
	t -= 1
	n = iinput()
	a = linput()
	b = linput()
	c = sorted(a)
	d = {}
	if c == a:
		print('Yes')
	elif len(set(b)) == 1:
		print('No')
	else:
		print('Yes')


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	zero_count = 0
	one_count = 0
	for i in b:
		if i == 1:
			one_count += 1
		else:
			zero_count += 1
	flag = False
	for i in range(1, len(a)):
		if a[i] < a[i - 1]:
			flag = True
			break
	if flag:
		if zero_count > 0 and one_count > 0:
			print('Yes')
		else:
			print('No')
	else:
		print('Yes')


t = int(input())
while t:
	n = int(input())
	s = list(map(int, input().split()))
	k = list(map(int, input().split()))
	l = set(k)
	if len(l) == 2:
		print('YES')
	else:
		for i in range(len(s) - 1):
			if s[i] > s[i + 1]:
				print('NO')
				break
		else:
			print('YES')
	t -= 1


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	flag = True
	dif = False
	for i in range(n - 1):
		if a[i] > a[i + 1]:
			flag = False
		if b[i] != b[i + 1]:
			dif = True
	if flag:
		print('Yes')
	elif dif:
		print('Yes')
	else:
		print('No')


t = int(input())
for i in range(t):
	size = map(int, input().split())
	list1 = list(map(int, input().split()))
	list2 = list(map(int, input().split()))
	flag = 0
	if 1 in list2 and 0 in list2:
		flag = 1
	if flag != 1:
		temp = sorted(list1)
		if temp == list1:
			print('YES')
			continue
		else:
			print('NO')
			continue
	print('YES')


T = int(input())

def isSorted(elems):
	siz = len(elems)
	for i in range(siz - 1):
		if elems[i] > elems[i + 1]:
			return False
	return True
for t in range(T):
	n = int(input())
	elements = [int(x) for x in input().split()]
	types = [int(x) for x in input().split()]
	if isSorted(elements):
		print('Yes')
	elif types.count(0) == 0 or types.count(1) == 0:
		print('No')
	else:
		print('Yes')


testcases = int(input())
for testcase in range(testcases):
	n = int(input())
	temparr = input()
	temparr = temparr.split()
	dicts = {}
	arr = []
	ordertemp = input()
	ordertemp = ordertemp.split()
	order = []
	difforder = 0
	for i in ordertemp:
		order.append(int(i))
	if sum(order) != 0 and sum(order) != n:
		difforder = 1
	if difforder == 1:
		print('Yes')
		continue
	for i in temparr:
		i = int(i)
		if i not in dicts:
			dicts[i] = 1
		else:
			dicts[i] += 1
		arr.append(i)
	orderedarr = sorted(arr[:])
	diff_flag = 0
	for i in range(n):
		if arr[i] != orderedarr[i]:
			diff_flag = 1
			break
	if diff_flag == 1:
		print('No')
	else:
		print('Yes')


from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	t = sum(b)
	if sorted(a) == a or (t != 0 and t != n):
		print('Yes')
	else:
		print('No')


import sys
import os
import heapq
import math
try:
	path = './file/input.txt'
	if os.path.exists(path):
		sys.stdin = open(path, 'r')
except:
	pass
t = int(input())

def printd(value):
	pass

def case():
	n = int(input())
	a = list(map(int, input().split(' ')))
	b = list(map(int, input().split(' ')))
	one = False
	zero = False
	answer = True
	for i in range(0, n):
		if i < n - 1:
			if a[i + 1] < a[i]:
				answer = False
		if b[i] == 0:
			one = True
		else:
			zero = True
	print('Yes' if answer or (one and zero) else 'No')
for _ in range(t):
	case()


from sys import stdin, stdout
import collections
import heapq
import itertools
import functools
import math
import operator
import string
ALPHABET = string.ascii_lowercase
DIGITS = string.digits

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

def read_int():
	return int(read_line())

def read_arr():
	return read_line().split(' ')

def read_int_arr():
	return [int(x) for x in read_arr()]

def query_interactive(s):
	print(s)
	stdout.flush()

def solve():
	n = read_int()
	a = read_int_arr()
	b = read_int_arr()
	is_sorted = True
	has_zero = False
	has_one = False
	for i in range(n):
		if i > 0:
			if a[i] < a[i - 1]:
				is_sorted = False
		if b[i] == 0:
			has_zero = True
		else:
			has_one = True
	if has_zero and has_one or is_sorted:
		print('Yes')
	else:
		print('No')

def main():
	T = 1
	T = read_int()
	for _ in range(T):
		solve()
main()


t = int(input())
for loop in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	types = list(map(int, input().split()))
	yes = 0
	no = 0
	flag = 0
	for i in types:
		if i == 1:
			yes += 1
		else:
			no += 1
		if yes >= 1 and no >= 1:
			flag = 1
			break
	if flag == 1:
		print('Yes')
	else:
		flag = 0
		for i in range(1, n):
			if arr[i] < arr[i - 1]:
				flag = 1
				break
		if flag == 0:
			print('Yes')
		else:
			print('No')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ac = a.copy()
	ze = b.count(0)
	on = n - ze
	if ze == 0:
		ac.sort()
		if a == ac:
			print('Yes')
		else:
			print('No')
	elif on == 0:
		ac.sort()
		if a == ac:
			print('Yes')
		else:
			print('No')
	else:
		print('Yes')


t = int(input())
while t != 0:
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	l3 = l1.copy()
	l3.sort()
	if l2.count(0) == n or l2.count(1) == n:
		if l1 == l3:
			print('YES')
		else:
			print('NO')
	else:
		print('YES')
	t = t - 1


for _ in range(int(input())):
	n = int(input())
	a = [*map(int, input().split())]
	b = [*map(int, input().split())]
	count = 0
	se = 0
	s = sorted(a)
	if a == s:
		print('YES')
	else:
		for i in b:
			if i == 0:
				count += 1
			else:
				se += 1
		if count == len(b) or se == len(b):
			print('NO')
		else:
			print('YES')


for iiij in range(int(input())):
	input()
	l1 = list(map(int, input().split()))
	l2 = input().split()
	print(('No', 'Yes')[l1 == sorted(l1) or (l2.count('1') > 0 and l2.count('0') > 0)])


from collections import Counter
import math
import sys
from bisect import bisect, bisect_left, bisect_right

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

def INT():
	return int(input())

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

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def mod():
	return 10 ** 9 + 7
for _ in range(INT()):
	n = INT()
	arr1 = LIST()
	arr2 = LIST()
	x = arr2[0]
	check = sorted(arr1)
	if arr1 == check:
		print('Yes')
	elif arr2.count(x) == n:
		print('No')
	else:
		print('Yes')


T = int(input())
for _ in range(0, T):
	N = int(input())
	A = list(map(int, input().split()))
	C = list(A)
	C.sort()
	c1 = 0
	c0 = 0
	B = list(map(int, input().split()))
	for i in range(0, N):
		if B[i] == 0:
			c0 += 1
		else:
			c1 += 1
	if c1 != 0 and c0 != 0:
		A.sort()
	if C == A:
		print('Yes')
	else:
		print('No')


t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	brr = list(map(int, input().split()))
	cnt0 = 0
	for i in brr:
		if i == 0:
			cnt0 += 1
	if arr == sorted(arr):
		print('Yes')
	elif cnt0 == n or cnt0 == 0:
		print('No')
	else:
		print('Yes')


for i in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	if a != sorted(a) and (sum(b) == 0 or sum(b) == len(b)):
		print('NO')
	else:
		print('YES')


import sys
input = lambda : sys.stdin.readline()
int_arr = lambda : list(map(int, input().split()))
str_arr = lambda : list(map(str, input().split()))
get_str = lambda : map(str, input().split())
get_int = lambda : map(int, input().split())
get_flo = lambda : map(float, input().split())
mod = 1000000007

def solve(n, arr, type):
	(o, z) = (0, 0)
	for i in type:
		if i == 0:
			z += 1
		else:
			o += 1
	if arr == sorted(arr) or (o > 0 and z > 0):
		print('Yes')
	else:
		print('No')
for _ in range(int(input())):
	n = int(input())
	arr = int_arr()
	type = int_arr()
	solve(n, arr, type)


from collections import defaultdict
import math
from functools import reduce
from heapq import heapify, heappush, heappop
import sys
from sys import stdin, stdout
from random import seed
from random import randint
mod = 10 ** 9 + 7

def mul_mod(a, b):
	return a % mod * (b % mod) % mod

def add_mod(a, b):
	return (a % mod + b % mod) % mod

def sub_mod(a, b):
	return (a % mod - b % mod + mod) % mod

def modInverse(b):
	return pow(b, mod - 2, mod)

def div_mod(a, b):
	a = a % mod
	inv = modInverse(b)
	return inv * a % mod

class Graph:

	def __init__(self, vertices):
		self.V = vertices + 1
		self.graph = defaultdict(set)
		self.Time = 0
		self.P = 0
		self.Q = 0

	def addEdge(self, u, v):
		self.graph[u].add(v)
		self.graph[v].add(u)

	def bridgeUtil(self, u):
		self.count[u] += 1
		self.disc[u] = self.Time
		self.low[u] = self.Time
		self.Time += 1
		for v in self.graph[u]:
			if self.count[v] == 0:
				self.parent[v] = u
				self.bridgeUtil(v)
				self.count[u] += self.count[v]
				self.low[u] = min(self.low[u], self.low[v])
				if self.low[v] > self.disc[u]:
					self.Q += 1
					if self.count[v] % 2 == 0:
						self.P += 1
			elif v != self.parent[u]:
				self.low[u] = min(self.low[u], self.disc[v])

	def bridge(self):
		self.disc = [float('Inf')] * self.V
		self.low = [float('Inf')] * self.V
		self.parent = [-1] * self.V
		self.count = [0] * self.V
		for i in range(1, self.V):
			if self.count[i] == 0:
				self.bridgeUtil(i)
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	poss = True
	if a == sorted(a):
		print('Yes')
		continue
	count_0 = 0
	count_1 = 0
	for i in range(n):
		if b[i] == 0:
			count_0 += 1
		else:
			count_1 += 1
	if count_0 == n or count_1 == n:
		print('No')
	else:
		print('Yes')


import atexit
import io
import sys
import math
from collections import defaultdict, Counter
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	d = [0, 0]
	for j in b:
		d[j] += 1
	if d[0] > 0 and d[1] > 0:
		print('Yes')
	elif sorted(a) == a:
		print('Yes')
	else:
		print('No')


import math
t = int(input())
for w in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	l = sorted(a)
	if b.count(0) == 0 or b.count(1) == 0:
		if a == l:
			print('Yes')
		else:
			print('No')
	else:
		print('Yes')


t = int(input())
for _ in range(t):
	n = int(input())
	num = list(map(int, input().split()))
	typ = list(map(int, input().split()))
	if 0 in typ and 1 in typ:
		print('Yes')
	elif num == sorted(num):
		print('Yes')
	else:
		print('No')


def isSorted(a):
	for i in range(0, len(a) - 1):
		if int(a[i]) > int(a[i + 1]):
			return False
	return True
t = int(input())
for i in range(0, t):
	n = int(input())
	a = input().split()
	b = input().split()
	if isSorted(a) == True:
		print('Yes')
	elif '1' in b and '0' in b:
		print('Yes')
	else:
		print('No')


t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	if a == sorted(a):
		print('Yes')
	elif 0 in b and 1 in b:
		print('Yes')
	else:
		print('No')


import queue
import math
t = int(input())
while t:
	n = int(input())
	a = input().split()
	a = [int(x) for x in a]
	b = input().split()
	b = [int(x) for x in b]
	incr = True
	p = 0
	cnt = 0
	for i in range(n):
		if a[i] < p:
			incr = False
		p = a[i]
		cnt += b[i]
	if cnt < n and cnt > 0:
		print('Yes')
	elif incr:
		print('Yes')
	else:
		print('No')
	t -= 1


import sys
import string
import math
import bisect as bi
from collections import defaultdict as dd
input = sys.stdin.readline

def cin():
	return map(int, sin().split())

def ain():
	return list(map(int, sin().split()))

def sin():
	return input()

def inin():
	return int(input())

def pref(a, n):
	pre = [0] * n
	pre[0] = a[0]
	for i in range(1, n):
		pre[i] = a[i] + pre[i - 1]
	return pre
for i in range(inin()):
	n = inin()
	a = ain()
	b = ain()
	x = sorted(a)
	one = b.count(1)
	zer = n - one
	if (one == 0 or zer == 0) and a != x:
		print('No')
	else:
		print('Yes')


t = int(input())
while t:
	t += -1
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	l1 = []
	for i in a:
		l1.append(i)
	l1.sort()
	if l1 == a:
		print('Yes')
		continue
	(ch1, ch2) = (0, 0)
	for i in b:
		if i == 0:
			ch1 = 1
		if i == 1:
			ch2 = 1
	if ch1 == 1 and ch2 == 1:
		print('Yes')
	else:
		print('No')


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	fin = []
	fin = a + fin
	fin.sort()
	if fin == a:
		print('Yes')
	elif len(set(b)) == 1 and fin != a:
		print('No')
	elif len(set(b)) == 1 and fin == a:
		print('Yes')
	elif len(set(b)) == 2:
		print('Yes')
	else:
		print('No')


for _ in range(int(input())):
	n = int(input())
	aa = list(map(int, input().split()))
	bb = set(map(int, input().split()))
	if len(bb) < 2 and aa != sorted(aa):
		print('no')
	else:
		print('yes')


def solve():
	n = int(input())
	val = [int(x) for x in input().split()]
	typ = [int(x) for x in input().split()]
	ans = sorted(val)
	if val == ans:
		return 'Yes'
	zero = 0
	one = 0
	for i in typ:
		if zero >= 1 and one >= 1:
			return 'Yes'
		if i == 0:
			zero += 1
		else:
			one += 1
	if zero >= 1 and one >= 1:
		return 'Yes'
	return 'No'
t = int(input())
while t > 0:
	ans = solve()
	print(ans)
	t -= 1


n = int(input())
for i in range(n):
	t = int(input())
	c = list(map(int, input().split()))
	d = set(map(int, input().split()))
	e = sorted(c)
	if e == c:
		print('Yes')
	elif len(d) == 2:
		print('Yes')
	else:
		print('No')


import sys

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

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

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

def ws(s):
	sys.stdout.write(s + '\n')

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

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

def is_sorted(a):
	for i in range(1, len(a)):
		if a[i - 1] > a[i]:
			return False
	return True

def solve(n, a, b):
	t0 = [a[i] for i in range(n) if b[i] == 0]
	t1 = [a[i] for i in range(n) if b[i] == 1]
	t0_sorted = is_sorted(t0)
	t1_sorted = is_sorted(t1)
	if t0_sorted and t1_sorted:
		return True
	return len(t0) > 0 and len(t1) > 0

def main():
	for _ in range(ri()):
		n = ri()
		a = ria()
		b = ria()
		wi('Yes' if solve(n, a, b) else 'No')
main()


a = int(input())

def isSorted(arr):
	for i in range(1, len(arr)):
		if arr[i - 1] > arr[i]:
			return False
	return True
for i in range(0, a):
	b = int(input())
	arr = list(map(int, input().split()))
	brr = list(map(int, input().split()))
	if len(arr) == 1:
		print('YES')
	elif len(set(brr)) == 2:
		print('YES')
	elif isSorted(arr):
		print('YES')
	else:
		print('NO')


def f(a, b):
	arr = sorted(a)
	if a == arr:
		print('Yes')
		return
	n = len(a)
	ones = sum(b)
	zeros = n - ones
	if min(ones, zeros) >= 1:
		print('Yes')
	else:
		print('No')
t = int(input())
for _ in range(t):
	n = input()
	line_1 = [int(a) for a in input().split(' ')]
	line_2 = [int(a) for a in input().split(' ')]
	f(line_1, line_2)


t = int(input())
for i in range(t):
	n = int(input())
	ls = [int(a) for a in input().split()]
	pos = [int(a) for a in input().split()]
	srtls = sorted(ls)
	if 1 in pos and 0 in pos:
		print('Yes')
	elif ls == srtls:
		print('Yes')
	else:
		print('No')


def main(n, a, b):
	ones = 0
	for i in b:
		if i == 1:
			ones += 1
	zeros = n - ones
	if min(ones, zeros) >= 1:
		return 'Yes'
	if a == sorted(a):
		return 'Yes'
	return 'No'
for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	print(main(n, a, b))


def solve_test_case(t):
	n = int(input())
	a = parse_array(int)
	b = parse_array(int)
	is_sorted = True
	for i in range(1, n):
		if a[i - 1] > a[i]:
			is_sorted = False
			break
	impossible = not is_sorted and len(set(b)) == 1
	if not impossible:
		print('Yes')
	else:
		print('No')

def parse_array(f):
	return list(map(f, input().split()))

def solve():
	T = int(input())
	for t in range(T):
		solve_test_case(t)
solve()


k = int(input())
for i in range(k):
	l = int(input())
	a = [int(i) for i in input().split(' ')]
	b = [int(i) for i in input().split(' ')]
	if 0 in b and 1 in b or a == sorted(a):
		print('YES')
	else:
		print('No')


test = int(input())
for _ in range(test):
	n = int(input())
	ele = list(map(int, input().split()))
	typ = list(map(int, input().split()))
	flag = True
	se = sorted(ele)
	for i in range(n):
		if se[i] != ele[i]:
			flag = False
			break
	if flag:
		print('Yes')
	else:
		(z, o) = (0, 0)
		for i in range(n):
			if typ[i] == 0:
				z += 1
			else:
				o += 1
		if z != n and o != n:
			print('Yes')
		else:
			print('No')


for i in range(int(input())):
	n = int(input())
	vals = list(map(int, input().split(' ')))
	types = list(map(int, input().split(' ')))
	if sum(types) == 0 or sum(types) == n:
		if sorted(vals) == vals:
			print('yes')
		else:
			print('no')
	else:
		print('yes')


def ALLSAME(brr, n):
	if brr.count(1) == n or brr.count(0) == n:
		return True
	return False

def is_SORT_possible(arr, brr, n):
	for i in range(n):
		for j in range(i + 1, n):
			if arr[i] > arr[j]:
				if brr[i] != brr[j]:
					(arr[i], arr[j]) = (arr[j], arr[i])
					(brr[i], brr[j]) = (brr[j], brr[i])
	return arr == sorted(arr)
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	brr = list(map(int, input().split()))
	if arr == sorted(arr):
		print('Yes')
	elif ALLSAME(brr, n):
		print('No')
	else:
		print('Yes')


t = int(input())
while t > 0:
	t -= 1
	c = 0
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	flag = 0
	test = a[:]
	test.sort()
	if test == a:
		flag = 1
	if flag == 1:
		print('Yes')
	else:
		res = all((ele == b[0] for ele in b))
		if res:
			print('No')
		else:
			flag = 0
			q = b[0]
			for i in b:
				if i != q:
					flag = 1
					break
			if flag == 0:
				print('No')
			else:
				print('Yes')


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	brr = list(map(int, input().split()))
	if sorted(arr) != arr:
		if 1 not in brr or 0 not in brr:
			print('NO')
			continue
	print('YES')


for _ in range(int(input())):
	n = int(input())
	a = []
	d = []
	f = 0
	g = 0
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if 0 in b:
		f = 1
	if 1 in b:
		g = 1
	if f * g == 1:
		print('YES')
	else:
		c = 1
		for i in range(n - 1):
			if a[i + 1] < a[i]:
				c = 0
				break
		if c == 0:
			print('NO')
		else:
			print('YES')


t = int(input())
for i in range(t):
	n = int(input())
	a = [int(j) for j in input().split()]
	b = [int(j) for j in input().split()]
	if n == 1:
		print('YES')
		continue
	ascending = True
	for i in range(1, n):
		if a[i] < a[i - 1]:
			ascending = False
			break
	if ascending == True:
		print('YES')
	elif 1 in b and 0 in b:
		print('YES')
	else:
		print('NO')


def sorted(arr, n):
	for i in range(n - 1):
		if arr[i] > arr[i + 1]:
			return False
	return True
tc = int(input().strip())
while tc:
	n = int(input().strip())
	arr = list(map(int, input().strip().split()))
	brr = list(map(int, input().strip().split()))
	if sum(brr) in [0, n] and (not sorted(arr, n)):
		print('NO')
	else:
		print('YES')
	tc -= 1


import os
import sys
from io import BytesIO, IOBase
input = sys.stdin.readline

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

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

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

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

def main():
	try:
		from math import floor, ceil
		for _ in range(inp()):
			n = inp()
			a = inlt()
			b = inlt()
			if len(set(b)) == 1 and sorted(a) != a:
				print('No')
			else:
				print('Yes')
	except Exception as e:
		print(e)
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()


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ac = sorted(a)
	if ac == a:
		print('Yes')
		continue
	zeros = 0
	ones = 0
	for v in b:
		if v == 1:
			ones += 1
		else:
			zeros += 1
	if ones == 0 or zeros == 0:
		print('No')
	else:
		print('Yes')


from collections import *
for t in range(int(input())):
	n = int(input())
	l = [*map(int, input().split(' '))]
	l_sorted = sorted(l)
	t = [*map(int, input().split(' '))]
	i = 0
	flag = True
	c = Counter(t)
	if l_sorted == l:
		print('Yes')
	elif n == c[0] or n == c[1]:
		print('No')
	elif c[0] > 0 and c[1] > 0:
		print('Yes')
	else:
		print('No')


from math import *
t = int(input())
for y in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if a == sorted(a):
		print('Yes')
		continue
	o = b.count(1)
	z = b.count(0)
	if o > 0 and z > 0:
		print('Yes')
	else:
		print('No')


from bisect import bisect_left as lower_bound, bisect_right as upper_bound
from sys import stdin, stdout
from collections import defaultdict

def solve(arr, n):
	pass

def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		a = list(map(int, input().strip().split()))
		b = list(map(int, input().strip().split()))
		if len(set(b)) == 1:
			if sorted(a) == a:
				print('Yes')
			else:
				print('No')
		else:
			print('Yes')

def __starting_point():
	main()
__starting_point()


t = int(input())
while t:
	n = int(input())
	arr = list(map(int, input().rstrip().split()))
	typ = list(map(int, input().rstrip().split()))
	if typ.count(1) == len(typ) and arr != sorted(arr) or (typ.count(0) == len(typ) and arr != sorted(arr)):
		print('No')
	else:
		print('Yes')
	t -= 1


from math import floor, ceil
for _ in range(int(input())):
	n = int(input())
	a = [*map(int, input().split())]
	b = [*map(int, input().split())]
	c = b.count(1)
	if 1 <= c <= n - 1:
		print('Yes')
	elif sorted(a) == a:
		print('Yes')
	else:
		print('No')


from sys import stdin, stdout
int_in = lambda : int(stdin.readline())
arr_in = lambda : [int(x) for x in stdin.readline().split()]
mat_in = lambda rows: [arr_in() for y in range(rows)]
str_in = lambda : stdin.readline().strip()
out = lambda o: stdout.write('{}\n'.format(o))
arr_out = lambda o: out(' '.join(map(str, o)))
bool_out = lambda o: out('YES' if o else 'NO')
tests = lambda : range(1, int_in() + 1)
case_out = lambda i, o: out('Case #{}: {}'.format(i, o))

def solve(n, a, b):
	if a == sorted(a):
		return True
	if sum(b) == n or sum(b) == 0:
		return False
	return True
for i in tests():
	n = int_in()
	a = arr_in()
	b = arr_in()
	out('Yes' if solve(n, a, b) else 'No')


from sys import stdin, stdout

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

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

def solve():
	n = II()
	a = LI()
	b = LI()
	bvals = set(b)
	possible = True
	if len(bvals) != 2:
		for i in range(1, n):
			if a[i] < a[i - 1]:
				possible = False
				break
	if possible:
		stdout.write('Yes\n')
	else:
		stdout.write('No\n')
t = II()
for _ in range(t):
	solve()


for _ in range(int(input())):
	n = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	A1 = []
	A2 = []
	for i in range(len(A)):
		if B[i] == 1:
			A1.append(A[i])
		else:
			A2.append(A[i])
	if len(A1) > 0 and len(A2) > 0:
		print('Yes')
	elif A == sorted(A):
		print('Yes')
	else:
		print('No')


import sys
import math
t = int(input())
for _ in range(t):
	n = int(input())
	nums = list(map(int, input().split()))
	types = list(map(int, input().split()))
	count_1 = types.count(1)
	count_0 = types.count(0)
	if count_1 == n or count_0 == n:
		if sorted(nums) == nums:
			print('Yes')
		else:
			print('No')
	else:
		print('Yes')


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if a == sorted(a) or 0 < sum(b) < n:
		print('Yes')
	else:
		print('No')


t = int(input())
for i in range(t):
	n = int(input())
	inp = input().split()
	lis = []
	for j in inp:
		lis.append(int(j))
	checksort = True
	for j in range(n - 1):
		if lis[j] > lis[j + 1]:
			checksort = False
			break
	typelis = input().split()
	one = False
	zero = False
	for j in typelis:
		if j == '0':
			zero = True
		else:
			one = True
	if one and zero or checksort:
		print('Yes')
	else:
		print('No')


for _ in range(int(input())):
	n = int(input())
	li = list(map(int, input().split()))
	li1 = list(map(int, input().split()))
	k = sum(li1)
	p = sorted(li)
	if p == li:
		print('Yes')
	elif k != 0 and k < n:
		print('Yes')
	else:
		print('No')


T = int(input())
for _ in range(T):
	size = int(input())
	values = list(map(int, input().strip().split()))
	types = list(map(int, input().strip().split()))
	s = sum(types)
	if s == len(types) or s == 0:
		if all((values[i] <= values[i + 1] for i in range(len(values) - 1))):
			print('YES')
		else:
			print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	input()
	k = list(map(int, input().split()))
	l = list(map(int, input().split()))
	print('YNeos'[(len(set(l)) > 1 or sorted(k) == k) ^ 1::2])


for _ in range(int(input())):
	n = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	C = [a for a in A]
	C.sort()
	if C == A:
		print('YES')
		continue
	if len(set(B)) == 1:
		print('NO')
		continue
	print('YES')


t = int(input())
for i in range(t):
	n = int(input())
	decr = [int(i) for i in input().split()]
	nums = [int(i) for i in input().split()]
	count = 0
	for l in range(n - 1):
		if decr[l] <= decr[l + 1]:
			pass
		else:
			count = 1
	if count == 0:
		print('Yes')
		continue
	else:
		pass
	if nums.count(1) > 0 and nums.count(0) > 0:
		print('Yes')
	else:
		print('No')


T = int(input())
while T > 0:
	s = int(input())
	vals = [int(el) for el in input().split(' ')]
	b = [int(el) for el in input().split(' ')]
	vals_copy = vals.copy()
	vals_copy.sort()
	if vals == vals_copy:
		print('Yes')
	elif b.count(1) != 0 and b.count(0) != 0:
		print('Yes')
	else:
		print('No')
	T -= 1


t = int(input())
for i in range(t):
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	print('Yes' if len(set(l2)) == 2 or (len(set(l2)) == 1 and l1 == sorted(l1)) else 'No')


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	aSorted = [x for x in a]
	aSorted.sort()
	if len(set(b)) == 1:
		if aSorted == a:
			print('Yes')
		else:
			print('No')
	else:
		print('Yes')


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 math import factorial
from collections import Counter, defaultdict, deque
from heapq import heapify, heappop, heappush

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

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

def N():
	return int(input())

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

def perm(n, m):
	return factorial(n) // factorial(n - m) if n >= m else 0

def mdis(x1, y1, x2, y2):
	return abs(x1 - x2) + abs(y1 - y2)
mod = 998244353
INF = float('inf')

def main():
	for _ in range(N()):
		n = N()
		arra = RLL()
		arrb = RLL()
		one = False
		zero = False
		for i in arrb:
			if i == 0:
				zero = True
			else:
				one = True
		if zero and one:
			print('YES')
		else:
			for i in range(n - 1):
				if arra[i] > arra[i + 1]:
					print('NO')
					break
			else:
				print('YES')
main()


from fractions import Fraction
import sys
import bisect
import heapq
from math import *
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
mod = 1000000007

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

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

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

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

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

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

def graph(vertex):
	return [[] for i in range(0, vertex + 1)]

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

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

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

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

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

def power(a, b):
	ans = 1
	while b > 0:
		if b % 2 == 1:
			ans *= a
		a *= a
		b //= 2
	return ans

def createMatrix(rowCount, colCount, dataList):
	mat = []
	for i in range(rowCount):
		rowList = []
		for j in range(colCount):
			if dataList[j] not in mat:
				rowList.append(dataList[j])
		mat.append(rowList)
	return mat

def isprime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True
for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = 0
	d = 0
	e = 0
	g = sorted(a)
	if g == a:
		c = 1
	else:
		for i in range(n):
			if b[i] == 0:
				d += 1
			else:
				e += 1
		if e >= 1 and d >= 1:
			c = 1
	if c == 1:
		print('Yes')
	else:
		print('No')


t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	c = sorted(a)
	if c == a:
		print('Yes')
	elif n == 1:
		print('Yes')
	else:
		z = 0
		for i in range(n - 1):
			if b[i] != b[i + 1]:
				z = 1
				break
		if z == 0:
			print('No')
		else:
			print('Yes')


from sys import stdin, stdout
import math, sys
from itertools import permutations, combinations
from collections import defaultdict, deque, OrderedDict
from os import path
import bisect as bi
import string as st
import heapq

def yes():
	print('YES')

def no():
	print('NO')
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

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

	def In():
		return map(int, input().split())
else:

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

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

def main():
	try:
		n = I()
		l = list(In())
		j = list(In())
		q = 0
		flag = 0
		for x in range(1, n):
			if l[x] < l[x - 1]:
				q = 1
		if q == 1:
			t = j.count(1)
			t1 = n - t
			if t == 0 or t1 == 0:
				flag = 1
		if flag:
			print('No')
		else:
			print('Yes')
	except:
		pass
M = 998244353
P = 1000000007
for _ in range(I()):
	main()


import math

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

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

def bs(arr, l, r, x):
	while l <= r:
		mid = l + (r - l) // 2
		if arr[mid] == x:
			return arr[mid]
		elif arr[mid] < x:
			l = mid + 1
		else:
			r = mid - 1
	return -1

def swap(list, pos1, pos2):
	(list[pos1], list[pos2]) = (list[pos2], list[pos1])
	return list
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = sorted(a)
	if c == a or len(set(b)) == 2:
		print('Yes')
	else:
		print('No')


for i in range(int(input())):
	n = int(input())
	ele_value = list(map(int, input().split()))
	ele_type = set(map(int, input().split()))
	ele_srt = sorted(ele_value)
	if ele_srt == ele_value:
		print('YES')
	elif len(ele_type) == 2:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	N = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	count1 = B.count(1)
	count2 = B.count(0)
	temp = sorted(A)
	if count1 == N or count2 == N:
		if A == temp:
			print('Yes')
		else:
			print('No')
	else:
		print('Yes')


import sys, io, os, time
from collections import defaultdict
from collections import OrderedDict
from collections import deque
from itertools import combinations
from itertools import permutations
import bisect, math, heapq
alphabet = 'abcdefghijklmnopqrstuvwxyz'
input = sys.stdin.readline
for ii in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	na = a[:]
	b = list(map(int, input().split()))
	if len(set(b)) == 2:
		print('Yes')
	elif a == sorted(a):
		print('Yes')
	else:
		print('No')


import math

def main():
	t = int(input())
	for _ in range(t):
		n = input()
		a = list(map(int, input().split()))
		b = list(map(str, input().split()))
		if b.count(b[0]) == len(b):
			if a == sorted(a):
				print('YES')
			else:
				print('NO')
		elif b.count('0') >= 1 and b.count('1') >= 1:
			print('YES')
		else:
			print('NO')
main()


t = int(input())
i = 0
while i < t:
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = a.copy()
	c.sort()
	isSorted = c == a
	if isSorted:
		print('Yes')
	elif sum(b) == 0 or sum(b) == n:
		print('No')
	else:
		print('Yes')
	i += 1


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if sorted(a) == a:
		print('Yes')
	elif len(set(b)) == 1:
		print('No')
	else:
		print('Yes')


t = int(input())
for i in range(t):
	(n, v, s, k, j) = (int(input()), input().split(), input().split(), 0, 0)
	for j in range(1, n):
		if int(v[j]) < int(v[j - 1]):
			break
	for i in range(n):
		if s[i] == '0':
			k = k + 1
	if k != n and k != 0 or int(v[j]) >= int(v[j - 1]):
		print('Yes')
	else:
		print('No')


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	d = {0: [], 1: []}
	for i in range(n):
		if b[i] == 0:
			d[0].append(a[i])
		else:
			d[1].append(a[i])
	if len(d[1]) > 0 and len(d[0]) > 0:
		print('Yes')
	elif len(d[1]) == 0:
		if sorted(d[0]) == d[0]:
			print('Yes')
		else:
			print('No')
	elif sorted(d[1]) == d[1]:
		print('Yes')
	else:
		print('No')


import sys
input = sys.stdin.buffer.readline
t = int(input())
ans = []
for _ in range(t):
	n = int(input())
	(*a,) = map(int, input().split())
	(*b,) = map(int, input().split())
	if 0 < sum(b) < n:
		ans.append('Yes')
	elif all((i <= j for (i, j) in zip(a, a[1:]))):
		ans.append('Yes')
	else:
		ans.append('No')
print('\n'.join(ans))


import sys
q = int(input())
for i in range(q):
	t = int(input())
	a = [int(j) for j in sys.stdin.readline().split()]
	d = input().split()
	sorting = 1
	for j in range(len(d) - 1):
		if a[j] > a[j + 1]:
			sorting = 0
			break
	if sorting == 1:
		print('Yes')
	else:
		f1 = 0
		f0 = 0
		for k in d:
			if k == '1':
				f1 = 1
			if k == '0':
				f0 = 1
			if f1 + f0 == 2:
				print('Yes')
				break
		else:
			print('No')


for _ in range(int(input())):
	n = input()
	l = list(map(int, input().split()))
	r = input().split()
	lsort = sorted(l)
	if l == lsort or (r.count('1') > 0 and r.count('0') > 0):
		print('Yes')
	else:
		print('No')


t = int(input())
for test in range(t):
	n = int(input())
	key = [int(x) for x in input().split()]
	val = [int(x) for x in input().split()]
	fin = sorted(key)
	if key == fin:
		print('Yes')
	else:
		sv = set(val)
		if len(sv) == 2:
			print('Yes')
		else:
			print('No')


for lo in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	if a == sorted(a):
		print('YES')
		continue
	c = 0
	for i in range(n):
		if b[i] == 1:
			c += 1
	if c != 0 and c != n:
		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

def main():
	tinn = 1
	tinn = int(input())
	for tin in range(tinn):
		n = int(input())
		a = list(map(int, input().split()))
		b = list(map(int, input().split()))
		c = list(a)
		c.sort()
		if b.count(b[0] ^ 1) >= 1:
			print('YES')
		elif a == c:
			print('YES')
		else:
			print('NO')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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

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


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	count0 = 0
	count1 = 0
	flag = 0
	d = []
	for m in range(len(a)):
		d.append(a[m])
	d.sort()
	for j in range(len(b)):
		if b[j] == 0:
			count0 += 1
		else:
			count1 += 1
	if count0 > 0 and count1 > 0 or d == a:
		flag = 1
	else:
		flag = 0
	if flag == 1:
		print('YES')
	else:
		print('NO')


import sys
import bisect

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

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

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

def SI():
	return sys.stdin.readline().strip()
t = int(input())
for q in range(t):
	n = II()
	a = LI()
	b = LI()
	if sorted(a) == a:
		print('Yes')
	elif 1 in b and 0 in b:
		print('Yes')
	else:
		print('No')


def check(b):
	if b.count(0) == len(b) or b.count(1) == len(b):
		print('No')
	else:
		print('Yes')
for ii in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if a == sorted(a):
		print('Yes')
	else:
		check(b)


a = int(input())
for x in range(a):
	a = int(input())
	b = [int(x) for x in input().split()]
	c = [int(x) for x in input().split()]
	if sorted(b) == b:
		print('Yes')
		continue
	elif 0 in c and 1 in c:
		print('Yes')
		continue
	else:
		print('No')


from sys import stdin
t = int(stdin.readline())
for _ in range(t):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().rstrip().split(' ')))
	b = list(map(int, stdin.readline().rstrip().split(' ')))
	if b.count(0) == 0 or b.count(1) == 0:
		if a == sorted(a):
			print('Yes')
		else:
			print('No')
	else:
		print('Yes')


t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	if list(sorted(a)) == a or not all((x == b[0] for x in b)):
		print('Yes')
	else:
		print('No')


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = input()
	k = list(a)
	k.sort()
	if k == a:
		print('YES')
	elif '0' not in b or '1' not in b:
		print('NO')
	else:
		print('YES')


import math
import os
import random
import re
import sys
t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	has_one = False
	has_zero = False
	for i in b:
		if i == 1:
			has_one = True
		else:
			has_zero = True
		if has_one and has_zero:
			break
	if has_one and has_zero:
		print('Yes')
	else:
		is_sorted = True
		for i in range(1, len(a)):
			if a[i] < a[i - 1]:
				is_sorted = False
				break
		if is_sorted:
			print('Yes')
		else:
			print('No')


import sys
input = sys.stdin.readline
for nt in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if sorted(a) != a:
		if 1 not in b or 0 not in b:
			print('NO')
			continue
	print('YES')


from heapq import heappush, heappop

def solve():
	n = int(input())
	arr = [int(v) for v in input().split()]
	no1 = sum([int(v) for v in input().split()])
	if (no1 == n or no1 == 0) and sorted(arr) != arr:
		print('No')
	else:
		print('Yes')
t = int(input())
for _ in range(t):
	solve()


n = int(input())
for i in range(0, n):
	o = int(input())
	p = input().rstrip().split(' ')
	r = input().rstrip().split(' ')
	if r.count('0') > 0 and r.count('1') > 0:
		print('Yes')
	elif r.count('0') == 0 or r.count('1') == 0:
		X = list(p)
		X.sort(key=int)
		if X == p:
			print('Yes')
		else:
			print('No')


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	ans = set(map(int, input().split()))
	flag = True
	for i in range(n - 1):
		if arr[i] > arr[i + 1]:
			flag = False
	if flag:
		print('Yes')
		continue
	if len(ans) == 2:
		print('Yes')
	else:
		print('NO')


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

def print_list(l):
	print(' '.join(map(str, l)))
N = int(input())
for _ in range(N):
	n = int(input())
	(a, b) = (read_list(), read_list())
	s = set(b)
	if len(s) == 2:
		print('Yes')
	else:
		t = sorted(a)
		if a == t:
			print('Yes')
		else:
			print('No')


import sys
input = sys.stdin.readline
t = int(input())
for i in range(t):
	n = int(input())
	a = [int(i) for i in input().split() if i != '\n']
	b = [int(i) for i in input().split() if i != '\n']
	copy = a[:]
	copy.sort()
	if a == copy:
		sys.stdout.write('Yes' + '\n')
	elif sum(b) > 0 and sum(b) < n:
		sys.stdout.write('Yes' + '\n')
	else:
		sys.stdout.write('No' + '\n')


from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import heappush, heappop
import math
from collections import *
from functools import reduce, cmp_to_key, lru_cache
from itertools import *
import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
M = mod = 10 ** 9 + 7

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

def inv_mod(n):
	return pow(n, mod - 2, mod)

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

def st():
	return str(input().rstrip())[2:-1]

def val():
	return int(input().rstrip())

def li2():
	return [str(i)[2:-1] for i in input().rstrip().split()]

def li3():
	return [int(i) for i in st()]
for _ in range(val()):
	n = val()
	l1 = li()
	l2 = li()
	l3 = sorted(l1)
	ans = 'NO'
	if l3 == l1 or max(l2) != min(l2):
		ans = 'YES'
	print(ans)


t = int(input())
while t:
	t -= 1
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	sorte = True
	for i in range(1, n):
		if a[i - 1] > a[i]:
			sorte = False
			break
	if sorte:
		print('Yes')
	elif 1 not in b or 0 not in b:
		print('No')
	else:
		print('Yes')


t = int(input())
for t in range(0, t):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	x = False
	if sum(b) == 0 or sum(b) == n:
		x = True
	y = a[:]
	y.sort()
	if x and y == a:
		print('YES')
	else:
		one = two = False
		for i in range(0, n):
			if b[i] == 0:
				one = True
			elif b[i] == 1:
				two = True
		if one and two:
			print('YES')
		else:
			print('NO')


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	ll = list(map(int, input().split()))
	set = 0
	nset = 0
	for i in ll:
		if i == 1:
			set += 1
		else:
			nset += 1
	if set > 0 and nset > 0:
		print('Yes')
	else:
		count = 1
		for i in range(1, len(l)):
			if l[i - 1] <= l[i]:
				count += 1
		if count == n:
			print('Yes')
		else:
			print('No')


t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(i) for i in input().split(' ')]
	b = [int(i) for i in input().split(' ')]
	prev = a[0]
	sorted = True
	for cur in a:
		if prev > cur:
			sorted = False
	prev = b[0]
	one_type = True
	for cur in b:
		if prev != cur:
			one_type = False
	if sorted or not one_type:
		print('Yes')
	else:
		print('No')


import os
import sys
from io import BytesIO, IOBase
import math
from fractions import Fraction
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	p = list(map(int, input().split()))
	ss = sorted(l)
	if l == ss:
		print('YES')
	else:
		c = 0
		d = 0
		for i in range(n):
			if p[i] == 0:
				c += 1
			else:
				d += 1
		if c > 0 and d > 0:
			print('YES')
		else:
			print('NO')


t = int(input())
for test in range(t):
	n = int(input())
	list1 = list(map(int, input().split()))
	list2 = list(map(int, input().split()))
	count1 = 0
	count2 = 0
	if list1 == sorted(list1):
		print('Yes')
		continue
	ans = 'No'
	for i in range(n):
		if count1 >= 1 and count2 >= 1:
			ans = 'Yes'
			break
		if list2[i] == 0:
			count1 += 1
		if list2[i] == 1:
			count2 += 1
	if count1 >= 1 and count2 >= 1:
		ans = 'Yes'
	print(ans)


def B():
	T = int(input())
	for i in range(T):
		size = int(input())
		a = input().split(' ')
		b = input().split(' ')
		a = [int(k) for k in a]
		b = [int(k) for k in b]
		m = []
		for j in range(size):
			m.append([a[j], b[j]])

		def sort(m):
			nonlocal a, b, size
			if a == sorted(a):
				return True
			if 0 < sum(b) < size:
				return True
			return False
		if sort(m):
			print('Yes')
		else:
			print('No')
B()


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	s = list(map(int, input().split()))
	if sorted(l) == l:
		print('Yes')
	elif len(set(s)) == 1:
		print('No')
	else:
		print('Yes')


for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	s = sorted(a)
	c1 = b.count(1)
	c0 = b.count(0)
	if c1 > 0 and c0 > 0 or s == a:
		print('Yes')
	else:
		print('No')


t = int(input())
for i in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	a.insert(0, 0)
	(check_sort, if_1, if_0) = (1, 0, 0)
	for j in range(1, n + 1):
		if a[j] < a[j - 1] and j >= 2:
			check_sort = 0
	for j in range(n):
		if b[j] == 0:
			if_0 = 1
		else:
			if_1 = 1
	if if_1 and if_0:
		print('Yes')
	elif check_sort:
		print('Yes')
	else:
		print('No')


import sys
input = sys.stdin.readline
from math import ceil, floor, factorial

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

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

def nCr(n, k):
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def upper_bound(a, x, lo=0):
	hi = len(a)
	while lo < hi:
		mid = (lo + hi) // 2
		if a[mid] < x:
			lo = mid + 1
		else:
			hi = mid
	return lo

def primefs(n):
	primes = {}
	while n % 2 == 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

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

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

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

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def factoriazation(x):
	ret = {}
	while x != 1:
		ret[spf[x]] = ret.get(spf[x], 0) + 1
		x = x // spf[x]
	return ret

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

def str_array():
	return input().strip().split()
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
for _ in range(int(input())):
	n = int(input())
	a = int_array()
	b = int_array()
	one = b.count(1)
	zero = b.count(0)
	if sorted(a) == a:
		print('Yes')
	elif one >= 1 and zero >= 1:
		print('Yes')
	else:
		print('No')


import sys
import string
input = sys.stdin.readline
import math
from operator import xor
p = 10 ** 9 + 7
n = int(input())
for i in range(n):
	l = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	x = list(a)
	x.sort()
	if x == a:
		print('yes')
	elif sum(b) == 0 or sum(b) == len(b):
		print('no')
	else:
		print('yes')


def is_sorted(arr):
	length = len(arr)
	for i in range(length - 1):
		if arr[i] > arr[i + 1]:
			return False
	return True
t = int(input())
for testcase in range(t):
	n = int(input())
	value_arr = list(map(int, input().split(' ')))
	type_arr = list(map(int, input().split(' ')))
	sum_type = sum(type_arr)
	if sum_type > 0 and sum_type < n:
		print('Yes')
	elif is_sorted(value_arr):
		print('Yes')
	else:
		print('No')


t = int(input())
for _ in range(t):
	n = int(input())
	arr = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	x = b.count(0)
	x1 = b.count(1)
	a = min(x, x1)
	if a > 0:
		print('Yes')
	elif arr == sorted(arr):
		print('Yes')
	else:
		print('No')


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	li = list(map(int, input().split()))
	chk = list(map(int, input().split()))
	s = sorted(li)
	if li == s:
		print('Yes')
	elif 1 in chk and 0 in chk:
		print('Yes')
	else:
		print('No')


q = int(input())
for i in range(q):
	p = int(input())
	arry = []
	arry2 = []
	x = 0
	y = 0
	w = input().split()
	for it in w:
		arry.append(int(it))
	for j in range(1, p):
		if arry[j] < arry[j - 1]:
			x += 1
	w = input().split()
	for it in w:
		arry2.append(int(it))
	for j in range(p):
		if arry2[j] != arry2[0]:
			y += 1
	if y > 0 or x == 0:
		print('YES')
	else:
		print('NO')


def check_sorted(arr):
	for i in range(0, len(arr) - 1):
		if arr[i] > arr[i + 1]:
			return False
	return True

def solve():
	n = int(input())
	arr = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = {'1': 0, '0': 0}
	for i in range(0, len(b)):
		c[str(b[i])] += 1
	if c['1'] != 0 and c['0'] != 0 or check_sorted(arr):
		print('Yes')
	else:
		print('No')
t = int(input())
for i in range(t):
	solve()


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	cc = a
	cc = sorted(cc)
	z = 0
	o = 0
	for i in b:
		if i == 0:
			z += 1
		else:
			o += 1
	if a != cc and (z == len(b) or o == len(b)):
		print('No')
	else:
		print('Yes')


for _ in range(int(input())):
	n = int(input())
	list1 = list(map(int, input().split()))
	list2 = list(map(int, input().split()))
	l = list1.copy()
	l.sort()
	x = list2.count(1)
	y = list2.count(0)
	if list1 != l:
		if x == 0 or y == 0:
			print('No')
		else:
			print('Yes')
	else:
		print('Yes')


import sys, random
input = sys.stdin.readline
T = int(input())
for _ in range(T):
	n = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	C = []
	v = B[0]
	f = 1
	for i in range(n):
		C.append(A[i])
		if B[i] != v:
			f = 0
	C.sort()
	c = 0
	for i in range(n):
		if A[i] == C[i]:
			c = c + 1
	if c == n:
		f = 0
	if f == 0:
		print('Yes')
	else:
		print('No')


t = int(input())
for i in range(t):
	n = int(input())
	N = list(map(int, input().split()))
	N1 = sorted(N)
	t = list(map(int, input().split()))
	print('Yes' if len(set(t)) == 2 or N1 == N else 'No')


t = int(input())
for _ in range(t):
	n = int(input())
	A = list(map(int, input().split(' ')))
	B = list(map(int, input().split(' ')))
	C = sorted(A)
	if C == A:
		print('YES')
	elif 1 in B and 0 in B:
		print('YES')
	else:
		print('NO')


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

def solve():
	n = int(input())
	a = list(inp())
	b = list(inp())
	srt = True
	for i in range(1, n):
		if a[i] < a[i - 1]:
			srt = False
			break
	zer = b.count(0)
	one = b.count(1)
	if not srt and (zer == 0 or one == 0):
		print('No')
	else:
		print('Yes')

def main():
	t = int(input())
	while t:
		solve()
		t -= 1
main()


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	l2 = sorted(l)
	b = list(map(int, input().split()))
	if l == l2:
		print('Yes')
	elif 1 in b and 0 in b:
		print('Yes')
	else:
		print('No')


for _ in range(int(input())):
	n = int(input())
	values = list(map(int, input().split()))
	type_of_value = list(map(int, input().split()))
	lnegth = n
	types = [0, 0]
	need_to_sort = False
	if sorted(values) != values:
		need_to_sort = True
	else:
		print('Yes')
	if need_to_sort:
		for t in type_of_value:
			if t == 0:
				types[0] += 1
			else:
				types[1] += 1
		if lnegth == 1:
			print('Yes')
		elif lnegth >= 2:
			if 0 not in types:
				print('Yes')
			else:
				print('No')
		else:
			print('Impossible case')


for t in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if all((l[i] <= l[i + 1] for i in range(len(l) - 1))):
		print('YES')
	elif b.count(1) > 0 and b.count(0) > 0:
		print('YES')
	else:
		print('NO')


tc = int(input())
for ctr in range(tc):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if b.count(1) > 0 and b.count(0) > 0 or sorted(a) == a:
		print('Yes')
	else:
		print('No')


t = int(input())
while t:
	n = int(input())
	l = list(map(int, input().split()))
	ll = list(map(int, input().split()))
	o = 0
	z = 0
	for i in ll:
		if i == 0:
			o = 1
		else:
			z = 1
	if o and z:
		print('Yes')
	else:
		lol = 0
		for i in range(1, n):
			if l[i] < l[i - 1]:
				lol = 1
		if lol:
			print('No')
		else:
			print('Yes')
	t -= 1


for i in range(int(input())):
	l3 = []
	c = 0
	o = 0
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	for j in range(len(l1)):
		l3.append(l1[j])
	l3.sort()
	if l1 == l3:
		print('Yes')
	elif l1 != l3:
		for j in range(len(l2)):
			if l2[j] == 1:
				c += 1
			elif l2[j] == 0:
				o += 1
		if c >= 1 and o >= 1:
			print('Yes')
		else:
			print('No')


def solver():
	pass
for _ in range(int(input())):
	n = int(input())
	vals = list(map(int, input().split()))
	types = list(map(int, input().split()))
	temp = []
	for (i, j) in zip(vals, types):
		temp.append((i, j))
	temp.sort(key=lambda x: x[0])
	count_zero = types.count(0)
	diff = 0
	for i in range(n):
		if temp[i][0] != vals[i]:
			diff += 1
	if diff == 0:
		print('Yes')
	elif count_zero == 0 or count_zero == n:
		print('No')
	else:
		print('Yes')


import sys
sys.setrecursionlimit(10 ** 8)
try:
	FILE_POINTER = open('input.inpt')
	input = FILE_POINTER.readline
except:
	FILE_POINTER = None
	input = sys.stdin.readline

def already_sorted(a):
	n = len(a)
	sorted_ = 1
	for i in range(1, n):
		if a[i] < a[i - 1]:
			sorted_ = 0
			break
	return sorted_
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().strip().split()))
	b = list(map(int, input().strip().split()))
	poss = 1
	zero = 0
	one = 0
	for i in range(n):
		if b[i] == 0:
			zero = 1
		if b[i] == 1:
			one = 1
	if zero and one or already_sorted(a):
		print('Yes')
	else:
		print('No')
if FILE_POINTER:
	FILE_POINTER.close()


T = int(input())
for _ in range(T):
	n = int(input())
	lis = list(map(int, input().split()))
	lis1 = [int(j) for j in input().split()]
	lis2 = lis
	if lis2 == sorted(lis2):
		print('YES')
	elif lis1.count(0) == 0 or lis1.count(1) == 0:
		print('NO')
	else:
		print('YES')


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if a == sorted(a):
		print('YES')
	else:
		x = b.count(0)
		y = b.count(1)
		if y == len(b):
			print('NO')
		elif x == len(b):
			print('NO')
		else:
			print('YES')


import sys
buff_readline = sys.stdin.readline
readline = sys.stdin.readline
INF = 2 ** 62 - 1

def read_int():
	return int(buff_readline())

def read_int_n():
	return list(map(int, buff_readline().split()))

def read_float():
	return float(buff_readline())

def read_float_n():
	return list(map(float, buff_readline().split()))

def read_str():
	return readline().strip()

def read_str_n():
	return readline().strip().split()

def error_print(*args):
	print(*args, file=sys.stderr)

def mt(f):
	import time

	def wrap(*args, **kwargs):
		s = time.time()
		ret = f(*args, **kwargs)
		e = time.time()
		error_print(e - s, 'sec')
		return ret
	return wrap

def slv(N, A, B):
	if A == list(sorted(A)):
		return 'Yes'
	if 1 in B and 0 in B:
		return 'Yes'
	return 'No'

def main():
	T = read_int()
	for _ in range(T):
		N = read_int()
		A = read_int_n()
		B = read_int_n()
		print(slv(N, A, B))
main()


import sys
Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()

def Yes():
	print('Yes')

def No():
	print('No')
for _ in range(int(ri())):
	n = int(ri())
	a = Ri()
	b = Ri()
	flag1 = False
	flag0 = False
	for i in b:
		if i == 1:
			flag1 = True
		else:
			flag0 = True
	if flag1 and flag0:
		Yes()
	else:
		arr = sorted(a)
		if a == arr:
			Yes()
		else:
			No()


from sys import stdin
T = int(stdin.readline().strip())
for caso in range(T):
	n = int(stdin.readline().strip())
	s = list(map(int, stdin.readline().strip().split()))
	s1 = list(map(int, stdin.readline().strip().split()))
	x = s1.count(1)
	if x == n or x == 0:
		s2 = s.copy()
		s2.sort()
		if s == s2:
			print('Yes')
		else:
			print('No')
	else:
		print('Yes')


t = int(input())
for _ in range(t):
	n = int(input())
	lsta = input().split()
	lsta = [int(i) for i in lsta]
	lstb = input().split()
	lstb = [int(i) for i in lstb]
	can = True
	for i in range(1, n):
		if lstb[i] != lstb[i - 1]:
			print('Yes')
			break
		if lsta[i] < lsta[i - 1]:
			can = False
	else:
		if can:
			print('Yes')
		else:
			print('No')


from collections import defaultdict as dd
from collections import deque
import bisect
import heapq

def ri():
	return int(input())

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

def solve():
	n = ri()
	A = rl()
	B = rl()
	is_sorted = True
	for i in range(len(A) - 1):
		if A[i] > A[i + 1]:
			is_sorted = False
			break
	if is_sorted or len(set(B)) == 2:
		print('Yes')
	else:
		print('No')
mode = 'T'
if mode == 'T':
	t = ri()
	for i in range(t):
		solve()
else:
	solve()


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	(c1, c0) = (0, 0)
	t = sorted(a)
	if t == a:
		print('Yes')
	else:
		for i in b:
			if i == 0:
				c0 += 1
			else:
				c1 += 1
		if c0 == n or c1 == n:
			print('No')
		else:
			print('Yes')


n = int(input())
for i in range(n):
	t = int(input())
	a = str(input()).split()
	b = str(input()).split()
	a = [int(u) for u in a]
	b = [int(y) for y in b]
	if 1 in b and 0 in b:
		print('Yes')
	elif sorted(a) == a:
		print('Yes')
	else:
		print('No')


for _ in range(int(input())):
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	l3 = l1.copy()
	l3.sort()
	if l3 == l1:
		print('Yes')
	else:
		c = l2.count(1)
		if c == n or c == 0:
			print('No')
		else:
			print('Yes')


def solve(n, d, e):
	big = float('inf')
	small = float('-inf')
	if sorted(d) == d:
		return 'Yes'
	has_one = False
	has_zero = False
	for i in e:
		if i == 0:
			has_zero = True
		if i == 1:
			has_one = True
	if has_one and has_zero:
		return 'Yes'
	return 'No'

def main():
	t = int(input())
	for i in range(t):
		n = int(input())
		d = input()
		d = [int(i) for i in d.split()]
		e = input()
		e = [int(i) for i in e.split()]
		ans = solve(n, d, e)
		print(ans)
main()


for x in range(int(input())):
	n = int(input())
	m = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = b.count(1)
	r = 'YES'
	for i in range(n - 1):
		if m[i + 1] < m[i]:
			r = 'NO'
			break
	if c == n or c == 0:
		print(r)
	else:
		print('YES')


t = int(input())
while t:
	t -= 1
	n = int(input())
	l = list(map(int, input().split()))
	parity = list(map(int, input().split()))
	mybookmark = 1
	fddd = 0
	if n == 1:
		print('YES')
		mybookmark = 0
	if mybookmark:
		for i in range(1, n):
			if l[i - 1] > l[i]:
				fddd = 1
				break
			elif i == n - 1:
				print('YES')
		if fddd:
			ff = 1
			for i in range(1, n):
				if parity[i] != parity[i - 1]:
					print('YES')
					ff = 0
					break
			if ff:
				print('NO')


t = int(input())
while t != 0:
	n = int(input())
	list1 = list(map(int, input().split()))
	list2 = list(map(int, input().split()))
	list3 = list()
	for i in range(n):
		list3.append(list1[i])
	list3.sort()
	f1 = 0
	one = 0
	zer = 0
	for i in range(n):
		if list3[i] != list1[i]:
			f1 = 1
		if list2[i] == 0:
			zer = 1
		else:
			one = 1
	if f1 == 0:
		print('Yes')
	elif zer == 1 and one == 1:
		print('Yes')
	else:
		print('No')
	t -= 1


def answer(n, a, b):
	if b.count(0) >= 1 and b.count(1) >= 1:
		return 'Yes'
	a_s = sorted(a)
	if a_s == a:
		return 'Yes'
	return 'No'

def main():
	t = int(input())
	while t:
		n = int(input())
		a = [int(i) for i in input().split()]
		b = [int(i) for i in input().split()]
		print(answer(n, a, b))
		t -= 1
	return
main()


test_cases = int(input())
while test_cases > 0:
	dummy = input()
	toSort = list(map(int, input().split()))
	isSort = sorted(toSort)
	data = input().split()
	flag0 = False
	flag1 = False
	avail = 0
	for element in data:
		if element == '1':
			flag1 = True
		else:
			flag0 = True
	if flag0 and flag1 or toSort == isSort:
		print('Yes')
	else:
		print('No')
	test_cases -= 1


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = [ele for ele in a]
	c.sort()
	if a == c:
		print('Yes')
	else:
		o = b.count(1)
		z = b.count(0)
		if o > 0 and z > 0:
			print('Yes')
		else:
			print('No')


from math import *
from copy import *
t = int(input())
for ww in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	c = deepcopy(a)
	c = sorted(c)
	b = list(map(int, input().split()))
	if b.count(0) == len(b) or b.count(1) == len(b):
		if a == c:
			print('Yes')
		else:
			print('No')
		continue
	l1 = []
	l2 = []
	for j in range(len(a)):
		if b[j] == 0:
			l1.append(a[j])
		else:
			l2.append(a[j])
	l1.sort()
	l2.sort()
	a = deepcopy(l1 + l2)
	b = deepcopy([0] * len(l1) + [1] * len(l2))
	for i in range(n):
		for j in range(0, n - i - 1):
			if a[j] > a[j + 1] and b[j] != b[j + 1]:
				(a[j], a[j + 1]) = (a[j + 1], a[j])
				(b[j], b[j + 1]) = (b[j + 1], b[j])
	if a == c:
		print('Yes')
	else:
		print('No')


import bisect
import decimal
from decimal import Decimal
import os
from collections import Counter
import bisect
from collections import defaultdict
import math
import random
import heapq
from math import sqrt
import sys
from functools import reduce, cmp_to_key
from collections import deque
import threading
from itertools import combinations
from io import BytesIO, IOBase
from itertools import accumulate
decimal.getcontext().prec = 46

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

def getFactors(n):
	factors = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				factors.append(i)
			else:
				factors.append(i)
				factors.append(n // i)
		i = i + 1
	return factors

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
	num = []
	for p in range(2, n + 1):
		if prime[p]:
			num.append(p)
	return num

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

def sort_dict(key_value):
	return sorted(key_value.items(), key=lambda kv: (kv[1], kv[0]))

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

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

def string_list():
	return list(input())

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

def binaryToDecimal(n):
	return int(n, 2)

def DFS(n, s, adj):
	visited = [False for i in range(n + 1)]
	stack = []
	stack.append(s)
	while len(stack):
		s = stack[-1]
		stack.pop()
		if not visited[s]:
			visited[s] = True
		for node in adj[s]:
			if not visited[node]:
				stack.append(node)

def solve():
	n = int(input())
	arr = list_input()
	temp = arr.copy()
	b = list_input()
	temp.sort()
	if arr == temp:
		print('YES')
		return
	count0 = count1 = 0
	for i in b:
		if i == 0:
			count0 += 1
		else:
			count1 += 1
	if count1 != 0 and count0 != 0:
		print('YES')
	else:
		print('NO')
t = int(input())
for _ in range(t):
	solve()


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = a[:]
	c.sort()
	if a == c:
		print('Yes')
		continue
	one = 0
	zero = 0
	for i in b:
		if i == 0:
			zero += 1
		else:
			one += 1
	if zero and one:
		print('Yes')
	else:
		print('No')


from sys import *

def solve(b):
	(c1, c2) = (0, 0)
	for el in b:
		if el == 1:
			c1 += 1
		else:
			c2 += 1
	if c1 == 0 or c2 == 0:
		print('No')
	else:
		print('Yes')
	pass
test = 1
test = int(input())
for t in range(0, test):
	n = int(input())
	brr = [int(x) for x in input().split()]
	arr = [int(x) for x in input().split()]
	if brr == sorted(brr):
		print('Yes')
	else:
		ans = solve(arr)


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if len(set(b)) == 2 or (len(set(b)) == 1 and a == sorted(a)):
		print('Yes')
	else:
		print('No')


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	d = a[:]
	d.sort()
	if d != a and (b.count(0) == 0 or b.count(1) == 0):
		print('No')
	else:
		print('Yes')


from sys import stdin

def readline():
	return stdin.readline()
tests = int(readline())

def solve(n, a, b):
	i0 = 0
	i1 = 0
	for i in range(0, n):
		if b[i] == 0:
			i0 += 1
		if b[i] == 1:
			i1 += 1
		if i0 > 0 and i1 > 0:
			return 'Yes'
	for i in range(1, n):
		if a[i] < a[i - 1]:
			return 'No'
	return 'Yes'
for t in range(0, tests):
	n = int(readline())
	a = list(map(int, readline().split(' ')))
	b = list(map(int, readline().split(' ')))
	print(solve(n, a, b))


from sys import stdin, stdout
for test in range(int(stdin.readline())):
	n = int(stdin.readline())
	arr_a = [int(x) for x in stdin.readline().split()]
	arr_b = [int(x) for x in stdin.readline().split()]
	check = True
	for i in range(n - 1):
		if arr_a[i] > arr_a[i + 1]:
			check = False
	if check:
		stdout.write('Yes\n')
	else:
		c1 = sum(arr_b)
		c0 = n - c1
		if c1 > 0 and c0 > 0:
			stdout.write('Yes\n')
		else:
			stdout.write('No\n')


import math

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if a == sorted(a):
		print('Yes')
		return
	x = b.count(1)
	y = b.count(0)
	if x == 0 or y == 0:
		print('No')
	else:
		print('Yes')
t = int(input())
for i in range(t):
	solve()


T = int(input())
for _ in range(1, T + 1):
	n = int(input())
	val = [int(x) for x in input().split()]
	type = [int(x) for x in input().split()]
	sorted = True
	for i in range(len(val) - 1):
		if val[i] > val[i + 1]:
			sorted = False
			break
	if sorted or (1 in type and 0 in type):
		print('Yes')
	else:
		print('No')


for _ in range(int(input())):
	n = int(input())
	li = list(map(int, input().split()))
	ty = list(map(int, input().split()))
	l = len(set(ty))
	if li == sorted(li):
		print('Yes')
	elif l == 2:
		print('Yes')
	else:
		print('No')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	d = [0] * n
	for i in range(n):
		d[i] = a[i]
	d.sort()
	p = q = 0
	for i in range(n):
		if b[i] == 1:
			p = 1
		else:
			q = 1
	if p == 1 and q == 1:
		print('Yes')
	else:
		f = 0
		for i in range(1, n):
			if a[i] < a[i - 1]:
				f = 1
				break
		if f == 1:
			print('No')
		else:
			print('Yes')


import sys
from bisect import *
from math import floor, sqrt, ceil, factorial as F, gcd, pi, log
from itertools import chain, combinations, permutations, accumulate
from collections import Counter, defaultdict, OrderedDict, deque
from array import array
INT_MAX = sys.maxsize
INT_MIN = -sys.maxsize - 1
mod = 1000000007
ch = 'abcdefghijklmnopqrstuvwxyz'
lcm = lambda a, b: a * b // gcd(a, b)
setbit = lambda x: bin(x)[2:].count('1')

def solve():
	T = int(sys.stdin.readline())
	for _ in range(T):
		n = int(sys.stdin.readline())
		a = list(map(int, sys.stdin.readline().split()))
		b = list(map(int, sys.stdin.readline().split()))
		one = []
		zero = []
		for i in range(n):
			if b[i] == 1:
				one.append(a[i])
			else:
				zero.append(a[i])
		if len(one) == 0:
			if zero == sorted(zero):
				print('Yes')
			else:
				print('No')
		elif len(zero) == 0:
			if one == sorted(one):
				print('Yes')
			else:
				print('No')
		else:
			print('Yes')
try:
	sys.stdin = open('input.txt', 'r')
except:
	pass
solve()


import sys
import heapq

def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		aList = list(map(int, sys.stdin.readline().split()))
		bList = list(map(int, sys.stdin.readline().split()))
		list0 = []
		list1 = []
		for i in range(n):
			if bList[i]:
				list1.append(aList[i])
			else:
				list0.append(aList[i])
		if list0 and list1:
			print('Yes')
		else:
			flag = True
			if list0:
				for i in range(len(list0) - 1):
					if list0[i] > list0[i + 1]:
						flag = False
						break
			if list1:
				for i in range(len(list1) - 1):
					if list1[i] > list1[i + 1]:
						flag = False
						break
			if flag:
				print('Yes')
			else:
				print('No')
	return
main()


t = int(input())
while t > 0:
	n = int(input())
	arr = [int(x) for x in input().split()]
	a = [int(x) for x in input().split()]
	temp = arr.copy()
	temp.sort()
	if temp == arr:
		print('Yes')
	else:
		n0 = 0
		n1 = 0
		for i in range(n):
			if a[i] == 0:
				n0 += 1
			else:
				n1 += 1
		if n0 == n or n1 == n:
			print('No')
		else:
			print('Yes')
	t -= 1


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	k = list(a)
	k.sort()
	if a == k:
		print('Yes')
	elif len(list(set(b))) == 2:
		print('Yes')
	else:
		print('No')


for i in range(int(input())):
	a = int(input())
	b = list(map(int, input().split()))
	c = set(map(int, input().split()))
	if len(c) < 2 and b != sorted(b):
		print('no')
	else:
		print('yes')


for t in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	sorted = True
	i = 1
	while i < n and sorted:
		if a[i] >= a[i - 1]:
			i += 1
		else:
			sorted = False
	print('Yes' if 0 < sum(b) < n or sorted else 'No')


import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
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 value():
	return tuple(map(int, input().split()))

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

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
for _ in range(Int()):
	n = Int()
	a = array()
	b = array()
	if len(set(b)) != 1 or sorted(a) == a:
		print('Yes')
	else:
		print('No')


import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
t = int(input())
for _ in range(t):
	n = int(input())
	arr = [int(x) for x in input().split()]
	bits = [int(x) for x in input().split()]
	SORT = sorted(arr)
	if bits.count(0) and bits.count(1) or SORT == arr:
		print('Yes')
	else:
		print('No')


cases = int(input())
answers = [] * 0
for problems in range(cases):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	s = sorted(a)
	if 0 in b and 1 in b:
		answers.append('Yes')
	elif a == s:
		answers.append('Yes')
	else:
		answers.append('No')
for answer in answers:
	print(answer)


t = int(input())
for z in range(0, t):
	n = int(input())
	a = [int(i) for i in input().split(' ')]
	b = [int(i) for i in input().split(' ')]
	if sum(b) == 0 or sum(b) == n:
		issorted = True
		for i in range(1, n):
			if a[i - 1] > a[i]:
				issorted = False
				break
		if issorted == True:
			print('Yes')
		else:
			print('No')
	else:
		print('Yes')


import sys
input = sys.stdin.readline
(T,) = map(int, input().split())
for _ in range(T):
	(N,) = map(int, input().split())
	X = list(map(int, input().split()))
	Y = list(map(int, input().split()))
	if len(set(Y)) == 1:
		for (a, b) in zip(X, X[1:]):
			if a > b:
				print('No')
				break
		else:
			print('Yes')
	else:
		print('Yes')


for _ in range(int(input())):
	x = int(input())
	I = [item for item in map(int, input().split())]
	I1 = sorted(I)
	sign = [item for item in map(int, input().split())]
	if I1 == I or (max(sign) == 1 and min(sign) == 0):
		print('Yes')
	else:
		print('No')


import math

def check(arr, brr):
	crr = sorted(arr)
	if arr == crr or len(set(brr)) == 2:
		return 'Yes'
	return 'No'
t = int(input())
while t:
	n = int(input())
	arr = list(map(int, input().split()))
	brr = list(map(int, input().split()))
	print(check(arr, brr))
	t -= 1


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	t1 = []
	t0 = []
	for i in range(n):
		if b[i] == 1:
			t1.append(a[i])
		else:
			t0.append(a[i])
	if len(t1) > 0 and len(t0) > 0:
		print('YES')
		continue
	tt = True
	for i in range(len(t1) - 1):
		if t1[i] > t1[i + 1]:
			tt = False
	for i in range(len(t0) - 1):
		if t0[i] > t0[i + 1]:
			tt = False
	if tt:
		print('YES')
	else:
		print('NO')


n = int(input())
for l in range(n):
	size = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	flag = 0
	i = 1
	while i < len(a):
		if a[i] < a[i - 1]:
			flag = 1
			break
		i += 1
	if flag == 0:
		print('yes')
	else:
		flag = 0
		i = 1
		while i < len(b):
			if b[i] != b[i - 1]:
				flag = 1
				break
			i += 1
		if flag == 1:
			print('yes')
		else:
			print('no')


from sys import stdin, stdout
import heapq as hq
from collections import defaultdict
t = int(input())
for tc in range(t):
	n = int(stdin.readline())
	ara = list(map(int, stdin.readline().split()))
	arb = list(map(int, stdin.readline().split()))
	l0 = 0
	valid = True
	if sum(arb) == n or sum(arb) == 0:
		for val in ara:
			if l0 > val:
				valid = False
			l0 = val
			if not valid:
				break
	if valid:
		res = 'Yes'
	else:
		res = 'No'
	stdout.write(str(res) + '\n')


t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	kopia_a = a.copy()
	a.sort()
	if kopia_a == a:
		print('Yes')
	else:
		vsetky = set()
		for i in range(n):
			vsetky.add(b[i])
		if vsetky == set([0, 1]):
			print('Yes')
		else:
			print('No')


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = 0
	d = 0
	e = []
	e = sorted(a)
	for i in range(n):
		if b[i] == 0:
			c += 1
		else:
			d += 1
	t = True
	for i in range(n):
		if e[i] != a[i]:
			t = False
			break
	if not c or not d:
		if t:
			print('Yes')
		else:
			print('No')
	else:
		print('Yes')


from sys import stdin, stdout
q = int(input())
for k in range(q):
	n = int(input())
	a = list(map(int, stdin.readline().split()))
	b = list(map(int, stdin.readline().split()))
	cnt = 0
	for i in range(1, len(a)):
		if a[i] < a[i - 1]:
			cnt += 1
	if cnt == 0:
		print('Yes')
	else:
		cnt0 = 0
		cnt1 = 0
		for i in b:
			if i == 1:
				cnt1 += 1
			else:
				cnt0 += 1
		if cnt0 == 0 or cnt1 == 0:
			print('No')
		else:
			print('Yes')


for __ in range(int(input())):
	n = int(input())
	A = [int(_) for _ in input().split()]
	T = set([int(_) for _ in input().split()])
	yes = len(T) > 1 or A == sorted(A)
	print('Yes' if yes else 'No')


t = int(input())
while t > 0:
	n = int(input())
	value = list(map(int, input().split()))
	typ = list(map(int, input().split()))
	s = sorted(value)
	res = 'No'
	if s == value:
		print('Yes')
	else:
		if 0 in typ:
			if 1 in typ:
				res = 'Yes'
		print(res)
	t -= 1


import math as mt

def tran(arr, key):
	data = list(arr)
	data.sort()
	if data == arr:
		return 'Yes'
	elif data != arr and len(set(key)) == 1:
		return 'No'
	else:
		return 'Yes'
t = int(input())
ans = []
for i in range(t):
	n = int(input())
	arr = list(map(int, input().rstrip().split()))
	key = list(map(int, input().rstrip().split()))
	r = tran(arr, key)
	ans.append(r)
for i in ans:
	print(i)


n = int(input())
for i in range(n):
	items = int(input())
	num = [int(x) for x in input().split()]
	num_type = [int(x) for x in input().split()]
	if num == sorted(num):
		print('Yes')
	else:
		type_one = [x == 1 for x in num_type]
		type_zero = [x == 0 for x in num_type]
		if any(type_zero) and any(type_one):
			print('Yes')
		else:
			print('No')


import copy
for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	k = copy.deepcopy(a)
	k.sort()
	if 0 in b and 1 in b or a == k:
		print('Yes')
	else:
		print('No')


t = int(input())
while t > 0:
	n = int(input())
	lis = list(map(int, input().strip().split()))[:n]
	typ = list(map(int, input().strip().split()))[:n]
	if lis != sorted(lis) and len(set(typ)) == 1:
		print('No')
	else:
		print('Yes')
	t -= 1


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if max(b) != min(b):
		print('Yes')
	elif sorted(a) == a:
		print('Yes')
	else:
		print('No')


def is_already_sorted(a, n):
	if n < 1:
		return True
	for i in range(1, n):
		if a[i - 1] > a[i]:
			return False
	return True

def solve(a, b, n):
	if is_already_sorted(a, n):
		return True
	cnt_1s = 0
	cnt_0s = 0
	for i in range(n):
		if b[i] == 1:
			cnt_1s += 1
		else:
			cnt_0s += 1
	if cnt_1s >= 1 and cnt_0s >= 1:
		return True
	return False

def read():
	t = int(input())
	for i in range(t):
		n = int(input())
		a = list(map(int, input().strip().split()))
		b = list(map(int, input().strip().split()))
		if solve(a, b, n):
			print('Yes')
		else:
			print('No')
read()


for s in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = []
	for (k, y) in zip(a, b):
		c.append((k, y))
	c.sort(key=lambda x: x[0])
	total_0 = b.count(0)
	total_diff = 0
	for k in range(n):
		if c[k][0] != a[k]:
			total_diff += 1
	if total_diff == 0:
		print('YES')
	elif total_0 == 0 or total_0 == n:
		print('NO')
	else:
		print('YES')


import sys
input = sys.stdin.readline
ipnl = lambda n: [int(input()) for _ in range(n)]
inp = lambda : int(input())
ip = lambda : [int(w) for w in input().split()]
for _ in range(inp()):
	n = inp()
	a = ip()
	b = ip()
	if b.count(0) == n or b.count(1) == n:
		if a == sorted(a):
			print('Yes')
		else:
			print('No')
	else:
		print('Yes')


t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(s) for s in input().split()]
	b = [int(s) for s in input().split()]
	c1 = 0
	c2 = 0
	pre = a[0]
	flag = True
	for el in a:
		if el < pre:
			flag = False
			break
		pre = el
	for el in b:
		if el == 1:
			c1 += 1
		elif el == 0:
			c2 += 1
		if c1 * c2 != 0 or flag:
			flag = True
			break
	if flag:
		print('Yes')
	else:
		print('No')


def check_sorted(data):
	now = data[0]
	for i in range(1, len(data)):
		if now > data[i]:
			return False
		else:
			now = data[i]
	return True
for _ in range(int(input())):
	n = int(input())
	a_data = list(map(int, input().split()))
	b_data = list(map(int, input().split()))
	zero_count = 0
	one_count = 0
	for i in b_data:
		if i == 0:
			zero_count += 1
		else:
			one_count += 1
	if zero_count == 0 or one_count == 0:
		if check_sorted(a_data):
			print('Yes')
			continue
		else:
			print('No')
			continue
	print('Yes')


t = int(input())
c = []
for i in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	if 0 in b and 1 in b:
		c.append('Yes')
	else:
		p = 0
		for i in range(n - 1):
			if a[i] > a[i + 1]:
				c.append('No')
				p = 1
				break
		if p == 0:
			c.append('Yes')
for k in c:
	print(k)


for s in range(int(input())):
	r = int(input())
	val = [int(x) for x in input().split()]
	typ = [int(x) for x in input().split()]
	print('Yes' if len(set(typ)) > 1 or val == sorted(val) else 'No')


t = int(input())

def solve(a, b, n):
	for i in range(n):
		for j in range(i + 1, n):
			if a[i] > a[j] and b[i] == b[j]:
				return False
	return True
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	equal = True
	for i in range(1, n):
		if b[i] != b[0]:
			equal = False
			break
	is_sorted = True
	for i in range(1, n):
		if a[i] < a[i - 1]:
			is_sorted = False
			break
	if equal and is_sorted:
		print('Yes')
	if equal and (not is_sorted):
		print('No')
	if not equal:
		print('Yes')


def solve(n, a, b):
	summ = sum(b)
	if summ == 0 or summ == n:
		if a == sorted(a):
			return 'yes'
		return 'no'
	return 'yes'
t = int(input())
for _ in range(t):
	inp = input().split()
	n = int(inp[0])
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	print(solve(n, a, b))


import sys
input = sys.stdin.buffer.readline

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

def sieve(n):
	a = [1] * n
	for i in range(2, n):
		if a[i]:
			for j in range(i * i, n, i):
				a[j] = 0
	return a
for __ in range(int(input())):
	n = int(input())
	a = I()
	b = I()
	if a == sorted(a):
		print('Yes')
		continue
	elif min(b.count(0), b.count(1)) >= 1:
		print('Yes')
	else:
		print('No')


a = int(input())
for _ in range(a):
	c = int(input())
	d = list(map(int, input().split()))
	e = list(map(int, input().split()))
	if len(set(e)) == 2 or d == sorted(d):
		print('Yes')
	else:
		print('No')


def swap(a, b, n):
	temp = a[:]
	temp.sort()
	j = 0
	f = 0
	while j < n:
		if temp[j] != a[j]:
			f = 1
			j = n
			break
		else:
			j = j + 1
	if f == 1:
		if len(set(b)) == 1:
			return 'No'
	return 'Yes'
t = int(input())
for j in range(t):
	n = int(input())
	a = [int(v) for v in input().split()]
	b = [int(v) for v in input().split()]
	res = swap(a, b, n)
	print(res)


import sys
input = sys.stdin.readline
t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	if len(set(b)) == 2 or a == sorted(a):
		print('Yes')
	else:
		print('No')


from sys import stdin
A = int(stdin.readline())
for k in range(0, A):
	B = int(stdin.readline())
	C = list(map(int, stdin.readline().split()))
	D = list(map(int, stdin.readline().split()))
	E = list()
	F = list()
	K = 0
	for t in range(0, B):
		if D[t] == 0:
			E.append(C[t])
		else:
			F.append(C[t])
	if len(E) > 0 and len(F) > 0:
		print('YES')
		continue
	if len(E) == 0:
		for v in range(0, len(F)):
			if v == 0:
				continue
			if F[v] < F[v - 1]:
				K = 1
				break
	if len(F) == 0:
		for u in range(0, len(E)):
			if u == 0:
				continue
			if E[u] < E[u - 1]:
				K = 1
				break
	if K == 1:
		print('NO')
	else:
		print('YES')


T = int(input())
for _ in range(0, T):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	c1 = 0
	c2 = 0
	temp = 'Yes'
	for i in range(0, len(b)):
		if b[i] == 1:
			c1 = 1
		else:
			c2 = 1
	h = sorted(a)
	if c1 * c2 == 0 and h != a:
		temp = 'No'
	print(temp)


import sys
from bisect import bisect_left, bisect_right
INF = 1 << 60
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if a == sorted(a):
		print('Yes')
	elif len(set(b)) == 2:
		print('Yes')
	else:
		print('No')


from sys import stdin, stdout

def main():
	t = int(stdin.readline())
	for _ in range(t):
		n = int(stdin.readline())
		arr = list(map(int, stdin.readline().split()))
		arr2 = list(map(int, stdin.readline().split()))
		is_increase = True
		prev = -1
		for x in arr:
			if x < prev:
				is_increase = False
				break
			prev = x
		zero = 0
		one = 0
		for x in arr2:
			if x == 1:
				one += 1
			else:
				zero += 1
		if is_increase or (one > 0 and zero > 0):
			stdout.write('Yes\n')
			continue
		stdout.write('No\n')
main()


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	res = []
	for i in range(n):
		res.append([a[i], b[i]])
	res.sort()
	for i in range(1):
		if a == sorted(a):
			print('Yes')
			break
		elif sum(b) == 0 or sum(b) == len(b):
			print('No')
			break
		s = 0
		for i in range(n):
			s += b[i] - res[i][1]
		print('Yes' if s == 0 else 'No')


tc = int(input())
while tc > 0:
	si = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if a == sorted(a) or len(set(b)) > 1:
		print('Yes')
	else:
		print('No')
	tc -= 1


def solve(n, arr, types):
	ans = 'Yes'
	if all((arr[i] <= arr[i + 1] for i in range(n - 1))):
		return ans
	elif all((types[i] == 0 for i in range(n))) or all((types[i] == 1 for i in range(n))):
		return 'No'
	else:
		return ans
cases = int(input())
for _ in range(cases):
	n = int(input())
	arr = list(map(int, input().split()))
	types = list(map(int, input().split()))
	print(solve(n, arr, types))


from math import radians
from heapq import heapify, heappush, heappop
import bisect
from math import pi
from collections import deque
from math import factorial
from math import log, ceil
from collections import defaultdict
from math import *
from sys import stdin, stdout
import itertools
import os
import sys
import threading
from collections import deque, Counter, OrderedDict, defaultdict
from heapq import *
from fractions import Fraction
mod = int(pow(10, 9) + 7)

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

def si():
	return str(input())

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

def li1():
	return list(mi())

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

def fsi():
	return str(stdin.readline())

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

def fli():
	return list(fmi())
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}

def getKey(item):
	return item[0]

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

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

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

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

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

def powerMod(x, y, p):
	res = 1
	x %= p
	while y > 0:
		if y & 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res
graph = defaultdict(list)
visited = [0] * 1000000
col = [-1] * 1000000

def bfs(d, v):
	q = []
	q.append(v)
	visited[v] = 1
	while len(q) != 0:
		x = q[0]
		q.pop(0)
		for i in d[x]:
			if visited[i] != 1:
				visited[i] = 1
				q.append(i)
		print(x)

def make_graph(e):
	d = {}
	for i in range(e):
		(x, y) = mi()
		if x not in d:
			d[x] = [y]
		else:
			d[x].append(y)
		if y not in d:
			d[y] = [x]
		else:
			d[y].append(x)
	return d

def gr2(n):
	d = defaultdict(list)
	for i in range(n):
		(x, y) = mi()
		d[x].append(y)
	return d

def connected_components(graph):
	seen = set()

	def dfs(v):
		vs = set([v])
		component = []
		while vs:
			v = vs.pop()
			seen.add(v)
			vs |= set(graph[v]) - seen
			component.append(v)
		return component
	ans = []
	for v in graph:
		if v not in seen:
			d = dfs(v)
			ans.append(d)
	return ans

def primeFactors(n):
	s = set()
	while n % 2 == 0:
		s.add(2)
		n = n // 2
	for i in range(3, int(sqrt(n)) + 1, 2):
		while n % i == 0:
			s.add(i)
			n = n // i
	if n > 2:
		s.add(n)
	return s

def find_all(a_str, sub):
	start = 0
	while True:
		start = a_str.find(sub, start)
		if start == -1:
			return
		yield start
		start += len(sub)

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

def dijkstra(edges, f, t):
	g = defaultdict(list)
	for (l, r, c) in edges:
		g[l].append((c, r))
	(q, seen, mins) = ([(0, f, ())], set(), {f: 0})
	while q:
		(cost, v1, path) = heappop(q)
		if v1 not in seen:
			seen.add(v1)
			path = (v1, path)
			if v1 == t:
				return (cost, path)
			for (c, v2) in g.get(v1, ()):
				if v2 in seen:
					continue
				prev = mins.get(v2, None)
				next = cost + c
				if prev is None or next < prev:
					mins[v2] = next
					heappush(q, (next, v2, path))
	return float('inf')

def binsearch(a, l, r, x):
	while l <= r:
		mid = l + (r - 1) // 2
		if a[mid]:
			return mid
		elif a[mid] > x:
			l = mid - 1
		else:
			r = mid + 1
	return -1

def readTree(n):
	adj = [set() for _ in range(n)]
	for _ in range(n - 1):
		(u, v) = map(int, input().split())
		adj[u - 1].add(v - 1)
		adj[v - 1].add(u - 1)
	return adj

def treeOrderByDepth(n, adj, root=0):
	parent = [-2] + [-1] * (n - 1)
	ordered = []
	q = deque()
	q.append(root)
	depth = [0] * n
	while q:
		c = q.popleft()
		ordered.append(c)
		for a in adj[c]:
			if parent[a] == -1:
				parent[a] = c
				depth[a] = depth[c] + 1
				q.append(a)
	return (ordered, parent, depth)

def isSubSequence(str1, str2):
	m = len(str1)
	n = len(str2)
	j = 0
	i = 0
	while j < m and i < n:
		if str1[j] == str2[i]:
			j = j + 1
		i = i + 1
	return j == m

def nextPowerOf2(n):
	count = 0
	if n and (not n & n - 1):
		return n
	while n != 0:
		n >>= 1
		count += 1
	return 1 << count

def isChangeable(notes, n):
	fiveCount = 0
	tenCount = 0
	for i in range(n):
		if notes[i] == 5:
			fiveCount += 1
		elif notes[i] == 10:
			if fiveCount > 0:
				fiveCount -= 1
				tenCount += 1
			else:
				return 0
		elif fiveCount > 0 and tenCount > 0:
			fiveCount -= 1
			tenCount -= 1
		elif fiveCount >= 2:
			fiveCount -= 2
		else:
			return 0
	return 1
for _ in range(ii()):
	n = ii()
	l = li1()
	b = li1()
	f = 0
	if 1 in b and 0 in b:
		f = 1
	if f == 0:
		if l == sorted(l):
			print('Yes')
		else:
			print('No')
	else:
		print('Yes')


def solve():
	n = int(input())
	arr = list(map(int, input().split()))
	typ = list(map(int, input().split()))
	if arr == sorted(arr):
		print('Yes')
		return
	if len(set(typ)) == 1:
		print('No')
		return
	print('Yes')
t = int(input())
for _ in range(t):
	solve()


t = int(input())
for iteration in range(t):
	n = int(input())
	values = [int(x) for x in input().split(' ')]
	types = [int(x) for x in input().split(' ')]
	if all((values[i] <= values[i + 1] for i in range(len(values) - 1))):
		print('Yes\n')
	else:
		sumarized = sum(types)
		if sumarized == n or sumarized == 0:
			print('No\n')
		else:
			print('Yes\n')


def solve():
	n = int(input())
	L = list(map(int, input().split()))
	l = list(map(int, input().split()))
	b = sorted(L)
	if L == b:
		print('Yes')
	elif len(set(l)) == 1:
		print('No')
	else:
		print('Yes')
t = int(input())
for _ in range(t):
	solve()


import sys
input = lambda : sys.stdin.readline().strip()
li = lambda : list(map(int, input().split()))
I = lambda : int(input())
for _ in range(I()):
	n = I()
	a = li()
	b = li()
	(o, z) = (0, 0)
	for i in b:
		if i:
			o += 1
		else:
			z += 1
	if o > 0 and z > 0:
		print('Yes')
	elif sorted(a) == a:
		print('Yes')
	else:
		print('No')


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	t = list(map(int, input().split()))
	sa = sorted(a)
	if sa == a:
		print('yes')
	elif sum(t) == 0:
		print('no')
	elif sum(t) == n:
		print('no')
	else:
		print('yes')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	(cnt0, cnt1) = (0, 0)
	for i in range(n):
		if b[i] == 0:
			cnt0 += 1
		else:
			cnt1 += 1
	if cnt1 == 0 or cnt0 == 0:
		if sorted(a) != a:
			print('No')
			continue
	print('Yes')


for _ in range(0, int(input())):
	n = int(input())
	l = list(map(int, input().strip().split()))
	t = list(map(int, input().strip().split()))
	if t.count(0) > 0 and t.count(1) > 0:
		print('Yes')
	else:
		z2 = [jk for jk in l]
		z2.sort()
		if z2 == l:
			print('Yes')
		else:
			print('No')


import sys
import collections as cc
import bisect as bi
input = sys.stdin.buffer.readline
I = lambda : list(map(int, input().split()))
for tc in range(int(input())):
	(n,) = I()
	a = I()
	b = I()
	x = a.copy()
	x.sort()
	if x == a:
		print('YES')
	else:
		(xx, yy) = (b.count(1), b.count(0))
		if xx and yy:
			print('YES')
		else:
			print('NO')


t = int(input())
for i in range(t):
	n = int(input())
	ai = [-1] + list(map(int, input().split()))
	bi = list(map(int, input().split()))
	ai = [ai[i] >= ai[i - 1] for i in range(1, n + 1)]
	if (sum(bi) == 0 or sum(bi) == n) and min(ai) == 0:
		print('No')
	else:
		print('Yes')


T = int(input())
for tasdf in range(T):
	n = int(input())
	arr = [int(i) for i in input().split()]
	ts = [int(i) for i in input().split()]
	arr2 = sorted(arr)
	if arr2 == arr:
		print('Yes')
		continue
	if 0 in ts and 1 in ts:
		print('Yes')
		continue
	print('No')


for _ in range(int(input())):
	n = int(input())
	l = [int(j) for j in input().split()]
	l1 = [int(j) for j in input().split()]
	test_list = l
	if test_list == sorted(test_list):
		print('Yes')
	elif l1.count(0) == 0 or l1.count(1) == 0:
		print('No')
	else:
		print('Yes')


import sys
import math
import operator as op
from functools import reduce
from bisect import *
from collections import deque

def read_line():
	return sys.stdin.readline()[:-1]

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

def read_int_line():
	return [int(v) for v in sys.stdin.readline().split()]

def read_float_line():
	return [float(v) for v in sys.stdin.readline().split()]

def ncr(n, r):
	r = min(r, n - r)
	numer = reduce(op.mul, range(n, n - r, -1), 1)
	denom = reduce(op.mul, range(1, r + 1), 1)
	return numer / denom
N = int(1000000.0) + 10
fenwick = [0] * N

def add(i, x, n):
	while i < n:
		fenwick[i] += x
		i = i | i + 1

def fsum(i, n):
	res = 0
	while i >= 0:
		res += fenwick[i]
		i = (i & i + 1) - 1
	return res

def fsum_range(i, j, n):
	return fsum(j, n) - fsum(i - 1, n)
mod = int(1000000000.0) + 7
mod2 = 998244353
t = read_int()
for i in range(t):
	n = read_int()
	a = read_int_line()
	b = read_int_line()
	(o, z) = (sum(b), n - sum(b))
	f = True
	if o > 0 and z > 0:
		print('Yes')
		continue
	else:
		for i in range(1, n):
			if a[i] < a[i - 1]:
				f = False
				break
	if f:
		print('Yes')
	else:
		print('No')


def countSetBits(n):
	count = 0
	while n:
		count += n & 1
		n >>= 1
	return count
import math

def mycool(i, j, l):
	for oo in range(m):
		if l[i][oo] == 1:
			return 0
	for oo in range(n):
		if l[oo][j] == 1:
			return 0
	return 1
t = int(input())
while t:
	t -= 1
	n = int(input())
	l = list(map(int, input().split()))
	parity = list(map(int, input().split()))
	mybookmark = 1
	fddd = 0
	if n == 1:
		print('YES')
		mybookmark = 0
	if mybookmark:
		for i in range(1, n):
			if l[i - 1] > l[i]:
				fddd = 1
				break
			elif i == n - 1:
				print('YES')
		if fddd:
			ff = 1
			for i in range(1, n):
				if parity[i] != parity[i - 1]:
					print('YES')
					ff = 0
					break
			if ff:
				print('NO')


import sys

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

def idata():
	return [int(x) for x in ii().split()]

def solve_of_problem():
	n = int(ii())
	a = idata()
	b = idata()
	if sum(b) != n and sum(b) != 0:
		print('Yes')
		return
	if a == sorted(a):
		print('Yes')
		return
	print('No')
	return
for ______ in range(int(ii())):
	solve_of_problem()


for i in range(int(input())):
	n = int(input())
	lis1 = list(map(int, input().split()))
	lis2 = list(map(int, input().split()))
	list3 = sorted(lis1)
	if sum(lis2) != 0 and sum(lis2) != n:
		print('Yes')
	elif lis1 == list3:
		print('Yes')
	else:
		print('No')


ans = []
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if 1 in b and 0 in b:
		ans.append('YES')
		continue
	if a == sorted(a):
		ans.append('YES')
	else:
		ans.append('NO')
print('\n'.join(ans))


import sys
input = sys.stdin.readline
t = int(input())
for tests in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	if len(set(B)) == 2:
		print('Yes')
	elif sorted(A) == A:
		print('Yes')
	else:
		print('No')


n = int(input())
for i in range(n):
	m = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	if 1 in b and 0 in b:
		print('YES')
	elif a == sorted(a):
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().strip().split()))[:n]
	b = list(map(int, input().strip().split()))[:n]
	sorted = True
	for j in range(n - 1):
		if a[j + 1] < a[j]:
			sorted = False
			break
	zero = False
	one = False
	if 0 in b:
		zero = True
	if 1 in b:
		one = True
	if zero and one:
		print('YES')
	elif sorted:
		print('YES')
	else:
		print('NO')


from sys import *
from math import sqrt
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()
	typ = int_arr()
	if len(set(typ)) == 1 and arr == sorted(arr):
		print('Yes')
	elif typ.count(1) and typ.count(0) or arr == sorted(arr):
		print('Yes')
	else:
		print('No')


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	binn = list(map(int, input().split()))
	one = binn.count(1)
	if l == sorted(l) or 0 < one < n:
		print('Yes')
	else:
		print('No')


def check():
	check_arr = sorted(numbers)
	if check_arr == numbers:
		return 'Yes'
	(zero, one) = (0, 0)
	for n in range(N):
		if flag[n]:
			one += 1
		else:
			zero += 1
	return 'Yes' if one and zero else 'No'
for _ in range(int(input())):
	N = int(input())
	numbers = list(map(int, input().split()))
	flag = list(map(int, input().split()))
	print(check())


t = int(input())
p = []
for i in range(t):
	n = int(input())
	x = list(map(int, input().split()))
	y = list(map(int, input().split()))
	z = sorted(x)
	if z == x:
		r = 'Yes'
	else:
		listToStr = ' '.join([str(elem) for elem in y])
		f1 = listToStr.find('0')
		f2 = listToStr.find('1')
		if f1 == -1 or f2 == -1:
			r = 'No'
		else:
			r = 'Yes'
	p.append(r)
for i in range(len(p)):
	print(p[i])


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 bisect import bisect_left
from collections import Counter
import math
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	ls = list(map(int, input().split()))
	ans = sorted(arr)
	if ans == arr:
		print('Yes')
	elif ls == [0] * n or ls == [1] * n:
		print('No')
	else:
		print('Yes')


import sys
t = int(sys.stdin.readline())
while t:
	n = int(sys.stdin.readline())
	a = list(map(int, sys.stdin.readline().split()))
	b = list(map(int, sys.stdin.readline().split()))
	if sorted(a) == a:
		print('Yes')
	elif len(set(b)) == 1:
		print('No')
	else:
		print('Yes')
	t -= 1


import math
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if arr == sorted(arr):
		print('Yes')
	else:
		ta = []
		tb = []
		for i in range(n):
			if b[i] == 1:
				tb += [arr[i]]
			else:
				ta += [arr[i]]
		i = 0
		j = 0
		ans = []
		if ta and tb:
			ta.sort()
			tb.sort()
			while i < len(ta) and j < len(tb):
				if ta[i] <= tb[j]:
					ans += [ta[i]]
					i += 1
				else:
					ans += [tb[j]]
					j += 1
			while i < len(ta):
				ans += [ta[i]]
				i += 1
			while j < len(tb):
				ans += [tb[j]]
				j += 1
			if ans == sorted(arr):
				print('Yes')
			else:
				print('No')
		else:
			print('No')


for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [i for i in input().split()]
	type0 = type1 = False
	for i in range(n):
		if b[i] == '1':
			type1 = True
		else:
			type0 = True
	if type1 and type0:
		print('Yes')
	elif a == sorted(a):
		print('Yes')
	else:
		print('No')


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	z = []
	f = []
	for i in range(n):
		if b[i] == 0:
			z.append(a[i])
		else:
			f.append(a[i])
	lz = len(z)
	lf = len(f)
	flag = True
	if lz > 0 and lf > 0:
		flag = True
	elif lz > 0:
		for i in range(lz - 1):
			if z[i] > z[i + 1]:
				flag = False
				break
	elif lf > 0:
		for i in range(lf - 1):
			if f[i] > f[i + 1]:
				flag = False
				break
	if flag:
		print('Yes')
	else:
		print('No')


n = int(input())
for _ in range(n):
	l = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))

	def Trouble(a, b):
		if sorted(a) == a:
			return 'Yes'
		if b.count(0) == l or b.count(1) == l:
			return 'No'
		return 'Yes'
	print(Trouble(a, b))


t = int(input())
while t:
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	flag = True
	for ind in range(1, len(a)):
		if a[ind] < a[ind - 1]:
			flag = False
	if flag:
		print('Yes')
	else:
		(count1, count2) = (0, 0)
		for item in b:
			if item is 1:
				count1 += 1
			else:
				count2 += 1
		if count1 and count2:
			print('Yes')
		else:
			print('No')
	t -= 1


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	arr1 = list(map(int, input().split()))
	arr2 = list(map(int, input().split()))
	one = 0
	for i in arr2:
		if i == 1:
			one += 1
	if one == 0 or one == len(arr2):
		sx = sorted(arr1)
		if sx == arr1 or arr1 == sx[::-1]:
			print('Yes')
		else:
			print('No')
	else:
		print('Yes')


import math as mt
import sys, string
input = sys.stdin.readline
import collections
from heapq import heappush, heapify, heappop
L = lambda : list(map(int, input().split()))
Ls = lambda : list(input().split())
M = lambda : map(int, input().split())
I = lambda : int(input())
t = I()
for _ in range(t):
	n = I()
	a = L()
	b = L()
	if len(set(b)) > 1:
		print('Yes')
	elif len(set(b)) == 1:
		if a == sorted(a):
			print('Yes')
		else:
			print('No')
	else:
		print('No')


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	flag = 0
	for i in range(n):
		for j in range(n):
			if i < j and b[i] == b[j] and (a[i] > b[i]):
				flag = 1
	p = a + []
	p.sort()
	if len(list(set(b))) == 1 and a != p:
		print('No')
	else:
		print('Yes')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	l = a[:]
	l.sort()
	s = set()
	flag = True
	for i in range(n):
		s.add(b[i])
		if l[i] != a[i]:
			flag = False
	if flag:
		print('Yes')
	elif len(s) == 2:
		print('Yes')
	else:
		print('No')


from sys import stdin, stdout
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	A = list(map(int, stdin.readline().split()))
	B = list(map(int, stdin.readline().split()))
	if sorted(A) == A:
		stdout.write('Yes\n')
	elif len(set(B)) == 1:
		stdout.write('No\n')
	else:
		stdout.write('Yes\n')


for _ in range(int(input())):
	n = int(input())
	A = [int(a) for a in input().split()]
	B = [int(b) for b in input().split()]
	flag = True
	C = [a for a in A]
	C.sort()
	t0 = 0
	t1 = 0
	for i in range(n):
		if B[i] == 0:
			t0 += 1
		else:
			t1 += 1
	if t0 == n or t1 == n:
		if A == C:
			print('YES')
		else:
			print('NO')
	else:
		print('YES')


def read_int():
	return int(input())

def read_ints():
	return map(int, input().split())
t = read_int()
for _ in range(t):
	n = read_int()
	a = []
	b = []
	d = []
	a = list(read_ints())
	b = list(read_ints())
	d = list(a)
	a.sort()
	o = 0
	z = 0
	for i in range(n):
		if b[i] == 0:
			o += 1
		else:
			z += 1
	if a == d or (o > 0 and z > 0):
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.readline
from collections import *
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if 0 in b and 1 in b:
		print('Yes')
	else:
		c = a[:]
		c.sort()
		if a == c:
			print('Yes')
		else:
			print('No')


import sys
input = sys.stdin.readline

def N():
	return int(input())

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

def L():
	return list(NM())

def LN(n):
	return [N() for i in range(n)]

def LL(n):
	return [L() for i in range(n)]
t = N()

def f():
	n = N()
	a = L()
	b = L()
	if not (0 in b and 1 in b):
		for i in range(n - 1):
			if a[i + 1] < a[i]:
				return 'No'
	return 'Yes'
for i in range(t):
	print(f())


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
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')
read = lambda : list(map(int, input().strip().split(' ')))

def func(i, j):
	for row in range(n):
		if mat[row][j] == 0:
			mat[row][j] = -1
	for col in range(m):
		if mat[i][col] == 0:
			mat[i][col] = -1

def solve():
	for _ in range(int(input())):
		n = int(input())
		a = read()
		b = read()
		if a == sorted(a):
			print('YES')
			continue
		elif len(set(b)) == 1:
			print('NO')
			continue
		arr = list(zip(a, b))
		arr.sort()
		c = 0
		k = 0
		for i in range(n):
			if arr[i][1] != b[i]:
				c += 1
		if c % 2 == 0:
			print('YES')
		else:
			print('NO')
solve()


t = int(input())
while t:
	t -= 1
	n = int(input())
	ar = list(map(int, input().split()))
	br = list(map(int, input().split()))
	print('yes' if len(set(br)) > 1 or ar == sorted(ar) else 'no')


import copy
t = int(input())
for k in range(t):
	n = int(input())
	a = list(map(int, input().split()))[:n]
	b = list(map(int, input().split()))[:n]
	c = copy.copy(a)
	f = 0
	count1 = 0
	count0 = 0
	c.sort()
	for i in range(n):
		if a[i] == c[i]:
			continue
		else:
			f = 1
			break
	if f == 0:
		print('YES')
	else:
		for i in range(n):
			if b[i] == 1:
				count1 += 1
			else:
				count0 += 1
		if count1 > 0 and count0 > 0:
			print('YES')
		else:
			print('NO')


for _ in range(0, int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	b = list(map(int, input().split()))
	d = sorted(l)
	if len(set(b)) == 2 or d == l:
		print('YES')
	else:
		print('NO')


for test_i in range(int(input())):
	n = int(input())
	arr_vals = list(map(int, input().split()))
	arr_types = list(map(int, input().split()))
	if 1 in arr_types and 0 in arr_types:
		print('Yes')
	else:
		print('Yes' if arr_vals == sorted(arr_vals) else 'No')


def f():
	n = int(input())
	A = [int(s) for s in input().split()]
	B = [int(s) for s in input().split()]
	s = 0
	for b in B:
		s += b
	if s != 0 and s != n:
		print('Yes')
		return
	for i in range(n - 1):
		if A[i] > A[i + 1]:
			print('No')
			return
	print('Yes')
for t in range(int(input())):
	f()


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	print('Yes' if not b.count(0) in [0, n] or sorted(a) == a else 'No')


import sys, os, io
I = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
for tc in range(1, 1 + int(I())):
	n = int(I())
	a = list(map(int, I().split()))
	b = list(map(int, I().split()))
	f = True
	for i in range(1, n):
		if a[i] < a[i - 1]:
			f = False
			break
	if f or len(set(b)) > 1:
		print('Yes')
	else:
		print('No')


t = int(input())
for i in range(0, t):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	if n == 1:
		print('yes')
	else:
		s = 0
		for i in range(0, n - 1):
			if a[i + 1] - a[i] < 0:
				s = 1
				break
		l = len(set(b))
		if l > 1:
			print('yes')
		elif s == 0:
			print('yes')
		else:
			print('no')


num_cases = int(input())
for n in range(num_cases):
	num_nums = int(input())
	nums = [int(i) for i in input().split()]
	types = [int(i) for i in input().split()]
	if nums == sorted(nums):
		print('Yes')
		continue
	if len(set(types)) > 1:
		print('Yes')
	else:
		print('No')


for i in range(int(input())):
	N = int(input())
	array = [int(x) for x in input().split()]
	type = [int(x) for x in input().split()]
	if sorted(array) == array:
		print('Yes')
	elif 1 in type and 0 in type:
		print('Yes')
	else:
		print('No')


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if sum(b) == 0 or sum(b) == n:
		isSorted = True
		for i in range(1, n):
			if a[i] < a[i - 1]:
				isSorted = False
				break
		if isSorted:
			print('Yes')
		else:
			print('No')
	else:
		print('Yes')


def main():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	l = b[0]
	for i in range(n):
		if b[i] != l:
			print('Yes')
			return
	a_copy = list(sorted(a))
	if a != a_copy:
		print('No')
	else:
		print('Yes')
for _ in range(int(input())):
	main()


ni = int(input())
for ti in range(ni):
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	if l1 == sorted(l1):
		print('Yes')
	elif 1 in l2 and 0 in l2:
		print('Yes')
	else:
		print('No')


def task_B():
	t = int(input())
	for _ in range(t):
		n = int(input())
		array = list(map(int, input().split()))
		types = list(map(int, input().split()))
		array_0 = []
		array_1 = []
		for i in range(n):
			if types[i]:
				array_1.append(array[i])
			else:
				array_0.append(array[i])
		if (sorted(array_0) == array_0) & (sorted(array_1) == array_1):
			print('Yes')
		else:
			n_0 = len(array_0)
			n_1 = len(array_1)
			if n_0 != 0 and n_1 != 0:
				print('Yes')
			else:
				print('No')

def main():
	task_B()
main()


def R():
	return map(int, input().split())
(t,) = R()
exec(t * "R();a=[*R()];print('NYoe s'[{*R()}>{0}or a==sorted(a)::2]);")


def solve():
	n = int(input())
	arr = list(map(int, input().split(' ')))
	types = list(map(int, input().split(' ')))
	total = sum(types)
	if total != n and total != 0:
		return 'Yes'
	prev = -1
	for a in arr:
		if a < prev:
			return 'No'
		prev = a
	return 'Yes'
T = int(input())
for _ in range(T):
	print(solve())


from collections import Counter, defaultdict, deque
from math import *
import sys
input = sys.stdin.readline

def solve():
	n = int(input())
	arr = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	if not any(b) or all(b):
		if sorted(arr) == arr:
			print('Yes')
		else:
			print('No')
		return
	print('Yes')
tt = int(input())
for test in range(tt):
	solve()


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if sorted(a) == a or not all((x == b[0] for x in b)):
		print('Yes')
	else:
		print('No')


def solve(arr1, arr2):
	if sorted(arr1) == arr1:
		print('Yes')
		return
	if len(arr1) == arr2.count(0) or len(arr1) == arr2.count(1):
		print('NO')
		return
	print('Yes')

def main():
	t = int(input())
	for i in range(t):
		input()
		arr1 = list(map(int, input().split()))
		arr2 = list(map(int, input().split()))
		solve(arr1, arr2)
main()


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	N = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if sum(b) in range(1, N):
		print('Yes')
	elif a == sorted(a):
		print('Yes')
	else:
		print('No')


def sort_check(a):
	prev = a[0]
	for i in range(1, len(a)):
		if a[i] < prev:
			return False
		prev = a[i]
	return True
t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	if sort_check(a):
		print('Yes')
	else:
		print('Yes' if len(set(b)) == 2 else 'No')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a1 = a.copy()
	a1.sort()
	if a == a1:
		print('Yes')
		continue
	zc = b.count(0)
	if zc == 0 or zc == n:
		print('No')
	else:
		print('Yes')


def solve():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if sorted(a) == a:
		return 'Yes'
	if b.count(0) > 0 and b.count(1) > 0:
		return 'Yes'
	return 'No'
t = int(input())
for loop in range(t):
	print(solve())


t = int(input())
for i in range(t):
	n = int(input())
	lis1 = [int(x) for x in input().split()]
	lis2 = [int(x) for x in input().split()]
	if lis2.count(1) == 0 or lis2.count(0) == 0:
		val = 0
		for i in range(len(lis2) - 1):
			if lis1[i + 1] < lis1[i]:
				print('No')
				val = 1
				break
		if val == 0:
			print('Yes')
	else:
		print('Yes')


for _ in range(int(input())):
	n = int(input())
	lis = list(map(int, input().split()))
	typ = list(map(int, input().split()))
	a = sorted(lis)
	con = False
	for i in range(len(lis)):
		if lis[i] != a[i]:
			con = True
	if not con:
		print('Yes')
	elif list(set(typ)) == [0] or list(set(typ)) == [1]:
		print('No')
	else:
		print('Yes')


t = int(input())
for q in range(0, t):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	count1 = 0
	count0 = 0
	for i in range(0, n):
		if b[i] == 1:
			count1 += 1
		else:
			count0 += 1
	if count1 >= 1 and count0 >= 1:
		print('Yes')
	else:
		flag = 'Yes'
		for i in range(1, n):
			if a[i] < a[i - 1]:
				flag = 'No'
				break
		print(flag)


def answer(n, A, B):
	if n == 1:
		return 'Yes'
	count = 0
	for i in range(n):
		if B[i] == 1:
			count += 1
	if count == 0 or count == n:
		if A == sorted(A):
			return 'Yes'
		else:
			return 'No'
	else:
		return 'Yes'
t = int(input())
for i in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	print(answer(n, A, B))


from sys import stdin, stdout
import math
input = stdin.readline

def print(x):
	stdout.write(str(x) + '\n')

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	(c1, c2) = (False, False)
	for i in b:
		if i == 0:
			c1 = True
		elif i == 1:
			c2 = True
	if c1 and c2:
		print('Yes')
	else:
		flag = 0
		for i in range(n - 1):
			if a[i + 1] < a[i]:
				flag = 1
				break
		if flag:
			print('No')
		else:
			print('Yes')
t = 1
t = int(input())
for _ in range(t):
	solve()


t = int(input())
for i in range(0, t):
	a = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	if sorted(l1) == l1:
		print('YES')
	else:
		flag1 = 0
		flag2 = 0
		for i in l2:
			if i == 0:
				flag1 = 1
			if i == 1:
				flag2 = 1
		if flag1 == 1 and flag2 == 1:
			print('YES')
		else:
			print('NO')


tests = int(input())
for test in range(tests):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	res = 'Yes'
	if 1 not in b or 0 not in b:
		if a != sorted(a):
			res = 'No'
	print(res)


def ans(arr1, arr2, n):
	type0 = 0
	type1 = 0
	for i in range(n):
		if arr2[i] == 0:
			type0 += 1
		else:
			type1 += 1
	if type0 == 0 or type1 == 0:
		for i in range(n - 1):
			if arr1[i] > arr1[i + 1]:
				return 'No'
	return 'Yes'
m = int(input())
for j in range(m):
	n = int(input())
	A = input().split()
	B = input().split()
	arr = []
	arr2 = []
	for i in A:
		arr.append(int(i))
	for i in B:
		arr2.append(int(i))
	print(ans(arr, arr2, n))


t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	form = list(map(int, input().split()))
	if arr == sorted(arr):
		print('Yes')
	elif len(form) == form.count(0) or len(form) == form.count(1):
		print('No')
	else:
		print('Yes')


t = int(input())
for _ in range(t):
	n = int(input())
	al = list(map(int, input().split()))
	bl = list(map(int, input().split()))
	if al == sorted(al):
		print('YES')
		continue
	elif sum(bl) == n or sum(bl) == 0:
		print('NO')
		continue
	else:
		print('YES')
		continue


T = int(input())
for t_itr in range(T):
	N = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	has_0 = False
	has_1 = False
	for b in B:
		if b == 0:
			has_0 = True
		else:
			has_1 = True
		if has_1 and has_0:
			break
	if has_0 and has_1:
		print('Yes')
	else:
		t = A[0]
		sorted = True
		for i in range(len(A)):
			if t > A[i]:
				sorted = False
				t = A[i]
				break
		if sorted:
			print('Yes')
		else:
			print('No')


def sorted_list(size, no):
	j = 1
	flag = 0
	while j < len(size):
		if size[j] < size[j - 1]:
			flag = 1
			return flag
		j += 1
	return flag
n = int(input())
ans = []
for i in range(n):
	no = int(input())
	size = list(map(int, input().split()))
	key = list(map(int, input().split()))
	if 0 in key and 1 in key:
		ans.append('YES')
	elif sorted_list(size, key) == 0:
		ans.append('YES')
	else:
		ans.append('NO')
print('\n'.join(ans))


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	A = list(map(int, input().split(' ')))
	B = list(map(int, input().split(' ')))
	C = [i for i in A]
	C.sort()
	if C == A:
		print('Yes')
	elif B.count(0) > 0 and B.count(1) > 0:
		print('Yes')
	else:
		print('No')


import bisect
import sys
import math
input = sys.stdin.readline
from collections import defaultdict
from collections import Counter

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

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

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

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

def solve(case):
	n = inp()
	aa = inlt()
	bb = inlt()
	sorted = all((aa[i] >= aa[i - 1] for i in range(1, n)))
	bsum = sum(bb)
	if sorted or (bsum > 0 and bsum < n):
		return 'Yes'
	else:
		return 'No'
if len(sys.argv) > 1 and sys.argv[1].startswith('input'):
	f = open('./' + sys.argv[1], 'r')
	input = f.readline
T = inp()
for i in range(T):
	res = solve(i + 1)
	print(str(res))


z = lambda : int(input())
z1 = lambda : map(int, input().split())
z2 = lambda : input()
for _ in ' ' * z():
	a = z()
	b = list(z1())
	c = list(z1())
	b1 = sorted(b)
	if b == b1:
		print('Yes')
	elif c.count(0) != 0 and c.count(1) != 0:
		print('Yes')
	else:
		print('No')


for k in range(int(input())):
	n = int(input())
	l = [int(i) for i in input().split()]
	key = [int(i) for i in input().split()]
	if len(set(key)) == 1:
		if l == sorted(l):
			print('Yes')
		else:
			print('No')
	else:
		print('Yes')


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

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

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

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

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

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

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

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

def S():
	return input()

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

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

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def IF(c, t, f):
	return t if c else f

def main():
	t = I()
	rr = []
	for _ in range(t):
		n = I()
		a = LI()
		b = LI()
		r = True
		if len(set(b)) == 1:
			for i in range(n - 1):
				if a[i] > a[i + 1]:
					r = False
					break
		rr.append(IF(r, 'Yes', 'No'))
	return JA(rr, '\n')
print(main())


from collections import Counter
t = int(input())
while t > 0:
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if sorted(a) == a:
		print('Yes')
	elif len(Counter(b)) > 1:
		print('Yes')
	else:
		print('No')
	t -= 1


from collections import defaultdict
import sys, math
f = None
try:
	f = open('q1.input', 'r')
except IOError:
	f = sys.stdin
if 'xrange' in dir(__builtins__):
	range = xrange
sys.setrecursionlimit(10 ** 2)

def print_case_iterable(case_num, iterable):
	print('Case #{}: {}'.format(case_num, ' '.join(map(str, iterable))))

def print_case_number(case_num, iterable):
	print('Case #{}: {}'.format(case_num, iterable))

def print_iterable(A):
	print(' '.join(A))

def read_int():
	return int(f.readline().strip())

def read_int_array():
	return [int(x) for x in f.readline().strip().split(' ')]

def rns():
	a = [x for x in f.readline().split(' ')]
	return (int(a[0]), a[1].strip())

def read_string():
	return list(f.readline().strip())

def ri():
	return int(f.readline().strip())

def ria():
	return [int(x) for x in f.readline().strip().split(' ')]

def rns():
	a = [x for x in f.readline().split(' ')]
	return (int(a[0]), a[1].strip())

def rs():
	return list(f.readline().strip())

def bi(x):
	return bin(x)[2:]
from collections import deque
import math
NUMBER = 10 ** 9 + 7

def factorial(n):
	M = NUMBER
	f = 1
	for i in range(1, n + 1):
		f = f * i % M
	return f

def mult(a, b):
	return a * b % NUMBER

def minus(a, b):
	return (a - b) % NUMBER

def plus(a, b):
	return (a + b) % NUMBER

def egcd(a, b):
	if a == 0:
		return (b, 0, 1)
	else:
		(g, y, x) = egcd(b % a, a)
		return (g, x - b // a * y, y)

def modinv(a):
	m = NUMBER
	(g, x, y) = egcd(a, m)
	if g != 1:
		raise Exception('modular inverse does not exist')
	else:
		return x % m

def choose(n, k):
	if n < k:
		assert false
	return mult(factorial(n), modinv(mult(factorial(k), factorial(n - k))))
from collections import deque, defaultdict
import heapq

def solution(a, b, n):
	found_one = False
	found_zero = False
	for i in range(len(b)):
		if b[i] == 1:
			found_one = True
		if b[i] == 0:
			found_zero = True
	if found_one and found_zero or sorted(a) == a:
		return 'Yes'
	return 'No'

def main():
	T = ri()
	for i in range(T):
		n = ri()
		a = ria()
		b = ria()
		x = solution(a, b, n)
		if 'xrange' not in dir(__builtins__):
			print(x)
		else:
			(print >> output, str(x))
	if 'xrange' in dir(__builtins__):
		print(output.getvalue())
		output.close()
if 'xrange' in dir(__builtins__):
	import cStringIO
	output = cStringIO.StringIO()
main()


t = int(input(''))
while t > 0:
	n = int(input(''))
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a_2 = list(a)
	a.sort()
	if a == a_2:
		print('Yes')
	else:
		checker = b[0]
		for i in range(1, n):
			if b[i] != checker:
				print('Yes')
				break
		else:
			print('No')
	t -= 1


def sint():
	return int(input())

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

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

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

def main():
	n = sint()
	a = sara()
	b = sara()
	srtd = True
	dif = False
	for i in range(n - 1):
		if a[i] > a[i + 1]:
			srtd = False
		if b[i] != b[i + 1]:
			dif = True
	if srtd or dif:
		print('Yes')
	else:
		print('No')
t = sint()
while t:
	t -= 1
	main()


t = int(input())
i = 1
while i <= t:
	n = int(input())
	a = input()
	a = a.split()
	b = input()
	b = b.split()
	flag = 0
	j = 0
	while j < n - 1:
		if int(b[j]) != int(b[j + 1]):
			flag += 1
		j += 1
	if flag >= 1:
		print('Yes')
	else:
		k = 0
		a_flag = 0
		while k < n - 1:
			if int(a[k]) > int(a[k + 1]):
				a_flag += 1
			k += 1
		if a_flag == 0:
			print('Yes')
		else:
			print('No')
	i += 1


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

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

def si():
	return input()

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

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def solve():
	for _ in range(ii()):
		n = ii()
		a = li()
		b = li()
		if sorted(a) == a:
			print('YES')
			continue
		f = 0
		if 1 not in b or 0 not in b:
			f = 1
		if f == 0:
			print('YES')
		else:
			print('NO')
solve()


import copy
t = int(input())
for test in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	index = list(map(int, input().split()))
	flag = True
	if sum(index) == 0 or sum(index) == n:
		if arr != sorted(arr):
			flag = False
		else:
			flag = True
	if flag:
		print('Yes')
	else:
		print('No')


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	sign = list(map(int, input().split()))
	if arr == sorted(arr):
		print('Yes')
	elif sum(sign) == 0 or sum(sign) == n:
		print('No')
	else:
		print('Yes')


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	l0 = []
	l1 = []
	for i in range(n):
		if b[i] == 0:
			l0.append(a[i])
		else:
			l1.append(a[i])
	n0 = len(l0)
	n1 = len(l1)
	res = 'Yes'
	if n0 == 0 or n1 == 0:
		for i in range(max(n0 - 1, n1 - 1)):
			if i < n0 - 1:
				if l0[i + 1] < l0[i]:
					res = 'No'
					break
			if i < n1 - 1:
				if l1[i + 1] < l1[i]:
					res = 'No'
					break
	print(res)


import functools
import heapq as hp
import collections
import bisect
import math
import re

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

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

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

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

def range_n():
	return range(int(input()))

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

def counter(a):
	d = {}
	for x in a:
		if x in d:
			d[x] += 1
		else:
			d[x] = 1
	return d

def main():
	for _ in range_n():
		n = getint()
		a = l_unpack()
		b = l_unpack()
		if (all(b) or not any(b)) and a != sorted(a):
			print('No')
		else:
			print('Yes')
main()


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ok = True
	for i in range(1, n):
		if a[i] < a[i - 1]:
			ok = False
			break
	if not ok and (1 not in b or 0 not in b):
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	l1 = list(map(int, input().split()))
	(zeros, ones) = (0, 0)
	for i in l1:
		if i == 0:
			zeros += 1
		else:
			ones += 1
	if zeros == 0 or ones == 0:
		l2 = []
		for i in l:
			l2.append(i)
		l2.sort()
		if l == l2:
			print('Yes')
		else:
			print('No')
	else:
		print('Yes')


t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	b = list(map(int, input().split()))
	d = 0
	for i in range(1, len(arr)):
		if arr[i] >= arr[i - 1]:
			pass
		else:
			d = 1
	if d == 0:
		print('Yes')
	else:
		s = set(b)
		if len(s) == 1:
			print('No')
		else:
			print('Yes')


n = eval(input())
for i in range(n):
	m = eval(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if 1 in b and 0 in b:
		print('Yes')
		continue
	else:
		flag = 0
		for j in range(1, m):
			if a[j] < a[j - 1]:
				flag = 1
				break
		if flag == 0:
			print('Yes')
		else:
			print('No')


from math import inf as inf
from math import *
from collections import *
import sys
input = sys.stdin.readline
t = int(input())
while t:
	t -= 1
	n = int(input())
	a = list(map(int, input().split()))
	typ = list(map(int, input().split()))
	f = len(set(typ))
	b = a[:]
	b.sort()
	if b == a:
		print('Yes')
	elif f == 2:
		print('Yes')
	else:
		print('No')


from sys import stdin
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	arr = list(map(int, stdin.readline().split()))
	b = list(map(int, stdin.readline().split()))
	xx = sorted(arr)
	if xx == arr:
		print('YES')
	elif len(set(b)) == 2:
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.readline

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

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

def instr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
t = int(input())
for i in range(0, t):
	n = inp()
	(one, zero) = (False, False)
	(order, temp) = (True, -1)
	a = inlist()
	b = inlist()
	for j in range(0, n):
		if temp <= a[j]:
			temp = a[j]
		else:
			order = False
	for j in range(0, n):
		if b[j] == 0:
			zero = True
		else:
			one = True
	if one == True and zero == True or order == True:
		print('Yes\n')
	else:
		print('No\n')


I = lambda : map(int, input().split())
for _ in [0] * int(input()):
	n = int(input())
	a = list(I())
	b = list(I())
	if 0 < sum(b) < n:
		print('Yes')
	elif a == sorted(a):
		print('Yes')
	else:
		print('No')


T = int(input())
for t in range(T):
	N = int(input())
	ai = list(map(int, input().split()))
	bi = list(map(int, input().split()))
	final = sorted(ai)
	if 1 not in bi or 0 not in bi:
		if ai != final:
			print('No')
		else:
			print('Yes')
	else:
		print('Yes')


from sys import *
t = int(input())

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	b = set(map(int, input().split()))
	if len(b) > 1:
		print('Yes')
	else:
		fail = 0
		for i in range(n - 1):
			if a[i] > a[i + 1]:
				fail = 1
				break
		if fail:
			print('No')
		else:
			print('Yes')
for _ in range(t):
	solve()


import sys
import collections
input = sys.stdin.readline
t = int(input())
for ti in range(1, t + 1):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	(c, d) = ([], [])
	for i in range(n):
		if b[i]:
			d.append(a[i])
		else:
			c.append(a[i])
	sm = sum(b)
	if not (sm == 0 or sm == n) or a == sorted(a):
		print('Yes')
	else:
		print('No')


import sys
fast_reader = sys.stdin.readline

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

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

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

def bubbleSort(arr, b):
	n = len(arr)
	for i in range(n):
		for j in range(0, n - i - 1):
			if arr[j] > arr[j + 1] and b[j] != b[j + 1]:
				(arr[j], arr[j + 1]) = (arr[j + 1], arr[j])
				(b[j], b[j + 1]) = (b[j + 1], b[j])
	return arr
for _ in range(int(input())):
	n = int(input())
	a = list_input()
	b = list_input()
	if a == sorted(a):
		print('YES')
		continue
	if len(set(b)) == 1:
		print('NO')
		continue
	z = []
	o = []
	for i in range(n):
		if b[i] == 0:
			z.append(a[i])
		else:
			o.append(a[i])
	z.sort()
	o.sort()
	x = 0
	y = 0
	for i in range(n):
		if b[i] == 0:
			a[i] = z[x]
			x += 1
		else:
			a[i] = o[y]
			y += 1
	l = bubbleSort(a, b)
	if l == sorted(l):
		print('YES')
	else:
		print('NO')


import os
import sys
from io import BytesIO, IOBase

def solution(arr, brr, n):
	s_arr = sorted(arr)
	if arr == s_arr:
		write('Yes')
		return
	ones = brr.count(1)
	zero = n - ones
	if ones >= 1 and zero >= 1:
		write('Yes')
	else:
		write('No')

def main():
	for _ in range(r_int()):
		n = r_int()
		arr = r_array()
		brr = r_array()
		solution(arr, brr, n)
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))

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

def write(*args, end='\n'):
	for x in args[:-1]:
		sys.stdout.write(str(x) + ' ')
	sys.stdout.write(str(args[-1]))
	sys.stdout.write(end)

def r_array():
	return [int(x) for x in input().split()]

def r_int():
	return int(input())
main()


import math
from collections import defaultdict
ml = lambda : map(int, input().split())
ll = lambda : list(map(int, input().split()))
ii = lambda : int(input())
ip = lambda : input()
t = ii()
for _ in range(t):
	n = ii()
	a = ll()
	b = ll()
	f = 0
	if 0 in b and 1 in b:
		f = 1
	c = a[:]
	c.sort()
	if c == a or f:
		print('Yes')
	else:
		print('No')


t = int(input())
for _ in range(t):
	n = int(input())
	aa = list(map(int, input().split()))
	bb = list(map(int, input().split()))
	st = 0
	ac = [aa[i] for i in range(n) if bb[i] == 0]
	bc = [aa[i] for i in range(n) if bb[i] == 1]
	if len(ac) == 0 or len(bc) == 0:
		if len(ac) == 0:
			if bc != sorted(bc):
				print('No')
			else:
				print('Yes')
		elif sorted(ac) != ac:
			print('No')
		else:
			print('Yes')
	else:
		print('Yes')


def main():
	for _ in range(int(input())):
		n = int(input())
		aa = list(map(int, input().split()))
		print(('No', 'Yes')[0 < sum((c == '1' for c in input()[::2])) < n or aa == sorted(aa)])
main()


T = int(input())
for t in range(T):
	n = int(input())
	A = list(map(int, input().split()))
	b = list(map(int, input().split()))
	s = sum(b)
	if s != 0 and s != n:
		print('Yes')
	elif sorted(A) == A:
		print('Yes')
	else:
		print('No')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if a == sorted(a):
		print('Yes')
	else:
		ch0 = 0
		ch1 = 0
		for i in b:
			if i == 0:
				ch0 += 1
			else:
				ch1 += 1
		if ch1 == 0 or ch0 == 0:
			print('No')
		else:
			print('Yes')


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	flis = sorted(a)
	count = 0
	countz = 0
	counto = 0
	for i in range(n):
		if flis[i] != a[i]:
			count += 1
		if b[i] == 0:
			countz += 1
		else:
			counto += 1
	if countz * counto >= count - 1:
		print('Yes')
	else:
		print('No')


q = int(input())
for _ in range(q):
	n = int(input())
	dat1 = list(map(int, input().split()))
	dat2 = list(map(int, input().split()))
	if dat2.count(1) != 0 and dat2.count(0) != 0:
		print('Yes')
		continue
	can = True
	p = dat1[0]
	for i in range(n):
		if dat1[i] < p:
			can = False
			break
		p = dat1[i]
	print('Yes' if can else 'No')


c = int(0)
d = int(0)
t = int(input())
ans = []
for i in range(t):
	n = int(input())
	a = [int(j) for j in input().split(' ')]
	b = [int(k) for k in input().split(' ')]
	a1 = a.copy()
	a1.sort()
	if a != a1:
		if b.count(1) == n or b.count(0) == n:
			ans.append('No')
		else:
			ans.append('Yes')
	else:
		ans.append('Yes')
for i in ans:
	print(i)


def main():
	t = int(input())
	for it in range(t):
		n = int(input())
		a = list(map(int, input().split()))
		b = list(map(int, input().split()))
		sorted = True
		for i in range(1, n):
			if a[i] < a[i - 1]:
				sorted = False
		s = b[0]
		brake = False
		for i in range(1, n):
			if b[i] != b[i - 1]:
				brake = True
				break
		if sorted:
			print('Yes')
		elif brake == True:
			print('Yes')
		else:
			print('No')
main()


t = int(input())
for case in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if len(set(b)) == 2:
		print('Yes')
	elif a == sorted(a):
		print('Yes')
	else:
		print('No')


def solve():
	n = int(input())
	a = list(map(int, input().split(' ')))
	b = list(map(int, input().split(' ')))
	if 0 in b and 1 in b:
		print('YES')
	else:
		for i in range(n - 1):
			if a[i] > a[i + 1]:
				print('NO')
				return
		print('YES')

def main():
	t = int(input())
	while t > 0:
		solve()
		t -= 1
main()


def check(n):
	if st[0] == 1 and st[1] == 1:
		return True
	for i in range(n - 1):
		if a[i] > a[i + 1]:
			return False
	return True
st = [False, False]
T = eval(input())
while T > 0:
	st[0] = False
	st[1] = False
	n = eval(input())
	dta = input().split()
	a = [int(i) for i in dta]
	dta = input().split()
	for i in dta:
		st[int(i)] = True
	if check(n):
		print('Yes')
	else:
		print('No')
	T = T - 1


from math import sqrt
t = int(input())
for q in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	s = True
	one = False
	two = False
	if b[0] == 1:
		one = True
	else:
		two = True
	for i in range(1, n):
		if a[i] < a[i - 1]:
			s = False
		if b[i] == 1:
			one = True
		else:
			two = True
	if not s and (not (one and two)):
		print('No')
	else:
		print('Yes')


for p in range(int(input())):
	(n, x, y, f) = (int(input()), [], [], 0)
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if 0 in b and 1 in b:
		print('Yes')
	elif a == sorted(a):
		print('Yes')
	else:
		print('No')


def allequal(l):
	x = l[0]
	for i in l:
		if i != x:
			return 0
	return 1
t = int(input())
for you in range(t):
	n = int(input())
	l = input().split()
	val = [int(i) for i in l]
	l = input().split()
	num = [int(i) for i in l]
	if allequal(num) == 0:
		print('Yes')
	else:
		z = list(val)
		z.sort()
		if z == val:
			print('Yes')
		else:
			print('No')


for _ in range(int(input())):
	am = int(input())
	arr = list(map(int, input().split()))
	types = list(map(int, input().split()))
	if arr == sorted(arr):
		print('YES')
		continue
	elif types.count(1) > 0 and types.count(1) < am:
		print('YES')
	else:
		print('NO')


from collections import Counter

def solve(n, a, b):
	if a == sorted(a):
		return 'Yes'
	c = Counter(b)
	if c[0] > 0 and c[1] > 0:
		return 'Yes'
	return 'No'
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	print(solve(n, a, b))


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 = list(map(int, sys.stdin.readline().split()))
	z = 0
	o = 0
	for i in range(n):
		if temp[i]:
			o += 1
		else:
			z += 1
	if z != 0 and o != 0:
		print('YES')
	elif arr == sorted(arr):
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	if sorted(l1) == l1:
		print('Yes')
	elif sum(l2) == n or sum(l2) == 0:
		print('no')
	else:
		print('Yes')


t = int(input())
for test in range(0, t):
	n = int(input())
	a = list(map(int, input().split()))
	bin = list(map(int, input().split()))
	t0 = False
	t1 = False
	for i in range(0, n):
		if bin[i] == 1:
			t1 = True
		else:
			t0 = True
		if t0 and t1:
			break
	if t0 and t1:
		print('Yes')
	else:
		val = False
		for i in range(1, n):
			if a[i] < a[i - 1]:
				val = True
				break
		if val:
			print('No')
		else:
			print('Yes')


import math, sys, bisect
from collections import defaultdict, Counter, deque
from itertools import groupby, accumulate
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
ilele = lambda : map(int, input().split())
alele = lambda : list(map(int, input().split()))

def Y(c):
	print(['NO', 'YES'][c])

def y(c):
	print(['no', 'yes'][c])

def Yy(c):
	print(['No', 'Yes'][c])
for _ in range(int(input())):
	N = int(input())
	A = alele()
	B = alele()
	C = sorted(A)
	Yy(A == C or len(set(B)) != 1)


def issorted(l):
	for i in range(0, len(l) - 1):
		if l[i + 1] < l[i]:
			return False
	return True
t = int(input())
for _ in range(t):
	n = int(input())
	ls1 = list(map(int, input().split(' ')))
	ls2 = list(map(int, input().split(' ')))
	f = 0
	y = 0
	if ls2.count(0) == n or ls2.count(1) == n:
		if issorted(ls1):
			print('Yes')
		else:
			print('No')
	else:
		print('Yes')


t = int(input())
while t:
	t -= 1
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	if a == sorted(a):
		print('YES')
	elif len(set(b)) == 1:
		print('NO')
	else:
		print('YES')


import sys
TEST = 0
if TEST == 1:
	input_file = open('inputB.txt', 'r')
	input_from_file = input_file.readlines()

def read_int():
	if TEST:
		return int(input_from_file.pop(0))
	else:
		return int(sys.stdin.readline())

def read_ints():
	if TEST:
		return list(map(int, input_from_file.pop(0).rstrip().split()))
	else:
		return list(map(int, sys.stdin.readline().split()))

def read_str():
	if TEST:
		in1 = input_from_file.pop(0).rstrip()
	else:
		in1 = sys.stdin.readline().rstrip()
	return in1
t = read_int()
for test in range(t):
	n = read_int()
	a = read_ints()
	b = read_ints()
	haveZeros = False
	haveOnes = False
	alreadySorted = True
	for (i, a_i) in enumerate(a[:-1]):
		if a_i > a[i + 1]:
			alreadySorted = False
			break
	for b_i in b:
		if b_i == 0:
			haveZeros = True
			if haveOnes:
				break
		if b_i == 1:
			haveOnes = True
			if haveZeros:
				break
	if alreadySorted or (haveOnes and haveZeros):
		ans = 'Yes'
	else:
		ans = 'No'
	print(ans)


from collections import Counter
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	count = Counter(b)
	count.setdefault(0, 0)
	count.setdefault(1, 0)
	if count[1] == n or count[0] == n:
		if a == sorted(a):
			print('Yes')
		else:
			print('No')
	else:
		print('Yes')


def solve(n, a, b):
	if b.count(0) == 0 or b.count(1) == 0:
		for i in range(1, n):
			if a[i] < a[i - 1]:
				return False
	return True
t = int(input())
for we in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if solve(n, a, b):
		print('Yes')
	else:
		print('No')


import sys
input = sys.stdin.readline
f = lambda : list(map(int, input().split()))
for _ in range(int(input())):
	n = input()
	a = f()
	b = input()
	aa = sorted(a)
	if aa == a or (b.count('1') != 0 and b.count('0') != 0):
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	ar = list(map(int, input().split()))
	br = list(map(int, input().split()))
	li = ar.copy()
	li.sort()
	ze = 0
	on = 0
	for i in range(n):
		if br[i] == 0:
			on += 1
		else:
			ze += 1
	if li == ar:
		print('Yes')
	elif ze != 0 and on != 0:
		print('Yes')
	else:
		print('No')


from sys import stdin, stdout
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	b = set(map(int, stdin.readline().split()))
	f = 1
	if sorted(a) == a:
		print('Yes')
		continue
	if 0 in b and 1 in b:
		print('Yes')
	else:
		print('No')


def process(n, a):
	for i in range(1, n):
		if a[i] < a[i - 1]:
			print('No\n')
			return
	print('Yes\n')
test = int(input())
while test > 0:
	test -= 1
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	check = [0, 0]
	for x in b:
		check[x] = 1
	if check[0] == 1 and check[1] == 1:
		print('Yes\n')
	else:
		process(n, a)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	ty = list(map(int, input().split()))
	key = 1
	for j in range(n - 1):
		if a[j] > a[j + 1]:
			key = 0
			break
	if key == 1:
		print('YES')
	else:
		r = ty[0]
		temp = 0
		for j in range(1, n):
			if ty[j] != r:
				temp = 1
		if temp == 0:
			print('NO')
		else:
			print('YES')


t = int(input())
for i in range(t):
	n = int(input())
	arr = [int(i) for i in input().split()][:n]
	ty_ar = [int(i) for i in input().split()][:n]
	if arr == sorted(arr):
		print('Yes')
	else:
		c_1 = 0
		c_0 = 0
		for i in range(len(arr)):
			if ty_ar[i] == 0:
				c_0 += 1
			if ty_ar[i] == 1:
				c_1 += 1
		if c_1 >= 1 and c_0 >= 1:
			print('yes')
		else:
			print('no')


from collections import OrderedDict
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	flag = True
	for i in range(len(a) - 1):
		if a[i + 1] < a[i]:
			flag = False
			break
	if flag:
		print('yes')
	if not flag:
		(counter0, counter1) = (0, 0)
		for i in b:
			if i == 0:
				counter0 += 1
			else:
				counter1 += 1
		if counter0 == n or counter1 == n:
			print('no')
		else:
			print('yes')


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	ans = list(map(int, input().split()))
	temp = arr[:]
	temp.sort()
	x = ans.count(0)
	y = ans.count(1)
	if temp == arr:
		print('Yes')
	elif x == n or y == n:
		print('No')
	else:
		print('Yes')


t = int(input())
while t:
	t = t - 1
	n = int(input())
	arr = input().split()
	kind = input().split()
	arr = list(map(int, arr))
	kind = list(map(int, kind))
	if min(kind) == max(kind):
		if arr == sorted(arr):
			print('Yes')
		else:
			print('No')
	else:
		print('Yes')


def swap(a, b, value_arr, type_arr):
	(value_arr[a], value_arr[b]) = (value_arr[b], value_arr[a])
	(type_arr[a], type_arr[b]) = (type_arr[b], type_arr[a])

def trouble_sort(start, value_arr, type_arr):
	if len(value_arr[start:]) <= 1 and len(type_arr[start:]) <= 1:
		return True
	min_value = min(value_arr[start:])
	min_index = value_arr.index(min_value)
	if min_index <= start:
		return trouble_sort(start + 1, value_arr, type_arr)
	min_type = type_arr[min_index]
	if type_arr[start] != min_type:
		swap(start, min_index, value_arr, type_arr)
		return trouble_sort(start + 1, value_arr, type_arr)
	else:
		try:
			alt_index = type_arr.index(1 - min_type)
		except ValueError:
			return False
		swap(start, alt_index, value_arr, type_arr)
		swap(start, min_index, value_arr, type_arr)
		swap(min_index, alt_index, value_arr, type_arr)
		return trouble_sort(start + 1, value_arr, type_arr)
for _ in range(int(input())):
	n = int(input())
	values = list(map(int, input().split()))
	types = list(map(int, input().split()))
	if trouble_sort(0, values, types) is True:
		print('Yes')
	else:
		print('No')


import sys
sys.setrecursionlimit(10 ** 5)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

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

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

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

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

def SI():
	return sys.stdin.readline()[:-1]

def main():
	for _ in range(II()):
		n = II()
		aa = LI()
		bb = LI()
		if aa == sorted(aa):
			print('Yes')
			continue
		s = sum(bb)
		if s == 0 or s == n:
			print('No')
			continue
		print('Yes')
main()


from collections import Counter as C, defaultdict as D, deque as Q
from operator import itemgetter as I
from itertools import product as P
from bisect import bisect_left as BL, bisect_right as BR
from heapq import heappush as HPUSH, heappop as HPOP
from math import floor as MF, ceil as MC, gcd as MG, factorial as F, sqrt as SQRT, inf as INFINITY

def player1():
	print('')

def player2():
	print('')

def isPrime(n):
	for i in range(2, MC(SQRT(n)) + 1):
		if n % i == 0:
			return False
	return True

def main():
	for _ in range(int(input())):
		n = int(input())
		a = list(map(int, input().split()))
		zz = list(map(int, input().split()))
		(z, o) = (0, 0)
		b = sorted(a)
		count = 0
		for i in range(n):
			if a[i] != b[i]:
				count += 1
			if zz[i] == 0:
				z += 1
			else:
				o += 1
		if count == 0:
			ans = 'YES'
		elif z and (not o) or (o and (not z)):
			ans = 'NO'
		else:
			ans = 'YES'
		print(ans)
main()


from sys import stdin
input = stdin.readline

def main():
	test = int(input())
	for _ in range(test):
		n = int(input())
		a = [int(i) for i in input().split(' ')]
		b = [int(i) for i in input().split(' ')]
		one = b.count(1)
		zero = b.count(0)
		flag = True
		if min(one, zero) == 0:
			for i in range(n - 1):
				if a[i] > a[i + 1]:
					flag = False
					break
		if flag:
			print('Yes')
		else:
			print('No')
main()


t = int(input())
while t > 0:
	n = int(input())
	arr = input().split()
	arr = [int(i) for i in arr]
	types = input().split()
	types = [int(i) for i in types]
	if arr == sorted(arr):
		print('Yes')
	elif types.count(0) > 0 and types.count(1) > 0:
		print('Yes')
	else:
		print('No')
	t -= 1


for _ in range(int(input())):
	n = input()
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = sorted(a)
	if a == c:
		print('YES')
	elif 0 not in b:
		print('NO')
	elif 1 not in b:
		print('NO')
	else:
		print('YES')


from sys import stdin, stdout
from collections import Counter

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

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

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

def op(ans):
	return stdout.write(str(ans) + '\n')
for i in range(ip()):
	n = ip()
	a = ai()
	b = ai()
	if sorted(a) == a:
		print('YES')
	elif b.count(1) == 0:
		print('NO')
	elif b.count(0) == 0:
		print('NO')
	else:
		print('YES')


import time, math
from sys import stdin, stdout

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

def Is():
	return str(stdin.readline())

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

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

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

def Si():
	return sorted(list(map(int, stdin.readline().split())), reverse=True)

def P(x):
	return stdout.write(str(x) + ' ')

def Pi(x):
	return stdout.write(str(x))

def solve():
	for i in range(I()):
		n = I()
		l = L()
		b = L()
		p = sorted(l)
		res = True
		res = all((ele == b[0] for ele in b))
		if p == l:
			P('Yes')
		elif res:
			P('No')
		else:
			P('Yes')
solve()


import sys
from typing import List
input = sys.stdin.readline
import math

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

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

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

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

def from_file(f):
	return f.readline

def solution(A: List[int], B: List[int]):
	(a0, a1) = (-float('inf'), -float('inf'))
	(c0, c1) = (0, 0)
	for (ai, bi) in zip(A, B):
		if bi == 0:
			c0 += 1
			if ai >= a0:
				a0 = ai
			else:
				a0 = float('inf')
		else:
			c1 += 1
			if ai >= a1:
				a1 = ai
			else:
				a1 = float('inf')
	if a0 < float('inf') and a1 < float('inf'):
		return 'Yes'
	if a0 == float('inf') and a1 == float('inf'):
		if c0 > 0 and c1 > 0:
			return 'Yes'
		return 'No'
	if a1 == float('inf'):
		(a0, a1) = (a1, a0)
		(c0, c1) = (c1, c0)
	if c1 > 0:
		return 'Yes'
	return 'No'
t = inp()
for _ in range(t):
	n = inp()
	A = inlt()
	B = inlt()
	print(solution(A, B))


def read_many_bool():
	return list(map(lambda x: x == '1', input().split()))

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

def read_int():
	return int(input())
for test_case in range(read_int()):
	n = read_int()
	ass = read_many()
	bss = read_many()
	sorted_a = sorted(ass)
	if sorted_a == ass:
		print('Yes')
	elif sum(bss) == 0 or sum(bss) == n:
		print('No')
	else:
		print('Yes')


t = int(input())
for ii in range(t):
	n = int(input())
	lis = list(map(int, input().split()))
	bi = list(map(int, input().split()))
	xx = 0
	for i in range(n - 1):
		if lis[i + 1] - lis[i] < 0:
			xx = 1
			break
	if xx:
		x = 0
		for i in range(n - 1):
			if bi[i] - bi[i + 1] != 0:
				x = 1
				break
		if x == 1:
			print('Yes')
		else:
			print('No')
	else:
		print('Yes')


def solve(krr, arr, nrr):
	arr.sort()
	if krr == arr:
		return 1
	if nrr.count(1) > 0 and nrr.count(0) > 0:
		return 1
	else:
		return 0
test = int(input())
for i in range(test):
	n = int(input())
	arr = list(map(int, input().split()))
	nrr = list(map(int, input().split()))
	if solve(arr, arr.copy(), nrr) == 1:
		print('Yes')
	else:
		print('No')


t = int(input())
for l in range(t):
	n = int(input())
	m = 1
	j = -1
	a = input().split()
	for i in range(n):
		if int(a[i]) < j:
			m = 0
		j = int(a[i])
	b = input().split()
	k = 0
	for i in range(n):
		k += int(b[i])
	if (k == n or k == 0) and m == 0:
		print('No')
	else:
		print('Yes')


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	flag = 0
	for i in range(n - 1):
		if a[i + 1] < a[i]:
			flag = 1
	if flag == 0:
		print('Yes')
	elif (1 in b and 0 in b) and n != 1:
		print('Yes')
	elif n == 1:
		print('Yes')
	else:
		print('No')


from collections import defaultdict
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = []
	f = 0
	for i in range(n):
		c.append(a[i])
	for i in range(n - 1):
		if b[i] != b[i + 1]:
			f = 1
			break
	if f == 1:
		print('Yes')
	elif f == 0:
		d = sorted(a)
		if d == c:
			print('Yes')
		else:
			print('No')


def is_sorted(a):
	for (ai, ai1) in zip(a, a[1:]):
		if ai > ai1:
			return False
	return True
for _ in range(int(input())):
	input()
	if is_sorted(tuple(map(int, input().split()))) | (len(set(input().split())) > 1):
		print('Yes')
	else:
		print('No')


from sys import stdin, stdout
t = int(stdin.readline())
for _ in range(t):
	n = int(stdin.readline())
	arr = list(map(int, stdin.readline().strip().split()))
	chk = list(map(int, stdin.readline().strip().split()))
	dup = sorted(arr)
	if 0 in chk and 1 in chk or sorted(arr) == arr:
		print('Yes')
	else:
		print('No')


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = sorted(a)
	if a == c:
		print('Yes')
	else:
		d = set(b)
		if len(d) == 2:
			print('Yes')
		else:
			print('No')


t = int(input())
for i in range(t):
	n = int(input())
	s = list(map(int, input().split()))
	b = sorted(s)
	t = list(map(int, input().split()))
	print('Yes' if len(set(t)) == 2 or b == s else 'No')


t = int(input())
for _ in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	if len(set(B)) == 1:
		flag = True
		for i in range(n - 1):
			if A[i] > A[i + 1]:
				flag = False
				break
		if flag:
			print('Yes')
		else:
			print('No')
	else:
		print('Yes')


for _ in range(int(input())):
	N = int(input())
	A = [int(x) for x in input().split()]
	B = [int(x) for x in input().split()]
	if B.count(0) == N or B.count(1) == N:
		if A == sorted(A):
			print('Yes')
		else:
			print('No')
	else:
		print('Yes')


import sys
input = sys.stdin.buffer.readline

def solution():
	for _ in range(int(input())):
		n = int(input())
		a = list(map(int, input().split()))
		b = list(map(int, input().split()))
		z = sorted(a)
		if z == a:
			print('YES')
			continue
		x = b.count(0)
		if x == n or x == 0:
			print('NO')
		else:
			print('YES')
solution()


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	one = 0
	zero = 0
	flag = True
	for i in b:
		if i == 1:
			one += 1
		else:
			zero += 1
	if zero > 0 and one == 0 or (zero == 0 and one > 0):
		aux = a.copy()
		a.sort()
		if aux == a:
			print('yes')
		else:
			print('no')
	else:
		print('yes')


for cas in range(int(input())):
	m = eval(input())
	s = list(map(int, input().split()))
	t = list(map(int, input().split()))
	if m == 1:
		print('Yes')
		continue
	i = 1
	while i < m:
		if t[i] != t[i - 1]:
			break
		i += 1
	if i >= m:
		fg = 1
		for j in range(1, m):
			if s[j] < s[j - 1]:
				fg = 0
				break
		if fg:
			print('Yes')
		else:
			print('No')
	else:
		print('Yes')


T = int(input())
for _ in range(T):
	n = int(input())
	s = list(map(int, input().split()))
	b = list(map(int, input().split()))
	s1 = sorted(s)
	if s1 == s:
		print('Yes')
	elif b.count(0) == n or b.count(1) == n:
		print('No')
	else:
		print('Yes')


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	f = False
	for i in range(n - 1):
		if a[i] > a[i + 1]:
			f = True
	if f == True:
		allone = True
		for i in range(n):
			if b[i] == 0:
				allone = False
				break
		allzero = True
		for i in range(n):
			if b[i] == 1:
				allzero = False
				break
		if allone or allzero:
			print('No')
		else:
			print('Yes')
	else:
		print('Yes')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	u = 0
	for (i, j) in zip(sorted(a), a):
		if i != j:
			u = 1
			break
	if u == 0:
		print('Yes')
	elif sum(b) == n or sum(b) == 0:
		print('No')
	else:
		print('Yes')


from sys import stdin

def inp():
	return stdin.buffer.readline().rstrip().decode('utf8')

def itg():
	return int(stdin.buffer.readline())

def mpint():
	return map(int, stdin.buffer.readline().split())
for case in range(itg()):
	n = itg()
	a = list(mpint())
	b = len(set(mpint())) == 2
	if b or a == sorted(a):
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	n = int(input())
	value = list(map(int, input().split()))
	type = list(map(int, input().split()))
	if type.count(1) > 0 and type.count(0) > 0:
		print('Yes')
	elif value == sorted(value):
		print('Yes')
	else:
		print('No')


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	o = b.count(1)
	z = b.count(0)
	ans = 'Yes'
	for i in range(n - 1):
		if (o == 0 or z == 0) and a[i] > a[i + 1]:
			ans = 'No'
			break
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	arr1 = [int(x) for x in input().split()]
	arr2 = [int(x) for x in input().split()]
	tmp = sum(arr2)
	if tmp == 0 or tmp == n:
		if sorted(arr1) == arr1:
			print('Yes')
		else:
			print('No')
	else:
		print('Yes')


test_cases = int(input())
for z in range(test_cases):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = sorted(a)
	ans = ''
	zero = 0
	one = 0
	if c == a:
		ans = 'Yes'
	else:
		for i in b:
			if i == 0:
				zero = 1
			if i == 1:
				one = 1
			if zero == 1 and one == 1:
				ans = 'Yes'
				break
		if zero == 0 or one == 0:
			ans = 'No'
	print(ans)


import math as mt
import sys, string
input = sys.stdin.readline
L = lambda : list(map(int, input().split()))
Ls = lambda : list(input().split())
M = lambda : map(int, input().split())
I = lambda : int(input())
from collections import defaultdict
t = I()
for _ in range(t):
	n = I()
	l = L()
	s = L()
	if len(set(s)) == 1:
		if l == sorted(l):
			print('Yes')
		else:
			print('No')
	else:
		print('Yes')


t = int(input())
for i in range(t):
	n = int(input())
	lst = list(map(int, input().split()))
	b = list(map(int, input().split()))
	count = 0
	for i in range(len(b) - 1):
		if b[i] != b[i + 1]:
			count += 1
	ans = []
	for i in range(len(lst)):
		ans.append(lst[i])
	ans.sort()
	if count == 0 and ans != lst:
		print('NO')
	else:
		print('YES')


import sys
import copy
input = sys.stdin.buffer.readline
t = int(input())
while t:
	t -= 1
	n = int(input())
	ans = []
	arr = list(map(int, input().split()))
	na = copy.deepcopy(arr)
	na.sort()
	arr1 = list(map(int, input().split()))
	count0 = 0
	count1 = 0
	for x in arr1:
		if x == 0:
			count1 += 1
		else:
			count0 += 1
	if count0 > 0 and count1 > 0:
		print('Yes')
	elif na == arr:
		print('Yes')
	else:
		print('No')


for _ in range(int(input())):
	n = int(input())
	value = list(map(int, input().split()))
	type = list(map(int, input().split()))
	flag = 0
	for i in range(len(value) - 1):
		if value[i + 1] < value[i]:
			flag = 1
			break
	if flag == 0:
		print('Yes')
	else:
		set_type = set(type)
		if len(set_type) > 1:
			print('Yes')
		else:
			print('No')


def solve():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = []
	d = []
	for i in range(n):
		if b[i]:
			c.append(a[i])
		else:
			d.append(a[i])
	if c and d:
		print('Yes')
		return
	for i in range(len(c) - 1):
		if c[i] > c[i + 1]:
			print('No')
			return
	for i in range(len(d) - 1):
		if d[i] > d[i + 1]:
			print('No')
			return
	print('Yes')
	return
t = int(input())
for _ in range(t):
	solve()


from sys import stdin, stdout, setrecursionlimit
for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	if a == sorted(a):
		print('Yes')
	elif 0 in b and 1 in b:
		print('Yes')
	else:
		print('No')


from collections import Counter
from sys import stdin
t = int(input())
result = ''
res_table = {False: 'No', True: 'Yes'}
for _ in range(t):

	def check_ascending(both):
		for i in range(len(both) - 1):
			if both[i] > both[i + 1]:
				return False
		return True
	n = int(input())
	vals = [int(i) for i in stdin.readline().split()]
	types = [int(i) for i in stdin.readline().split()]
	both = [(i, j) for (i, j) in zip(vals, types)]
	flag = False
	counter = Counter(types)
	if 1 in counter and 0 in counter:
		flag = True
	elif check_ascending(vals):
		flag = True
	result += res_table[flag] + '\n'
print(result[:-1])


import sys
import math
from collections import defaultdict

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

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

def input():
	return sys.stdin.readline().strip()
for _ in range(int(input())):
	n = int(input())
	a = get_array()
	b = get_array()
	d = defaultdict(list)
	for i in range(n):
		d[b[i]].append(a[i])
	if d[0] == [] or d[1] == []:
		c = sorted(a)
		if c == a:
			ans = 'Yes'
		else:
			ans = 'No'
	else:
		ans = 'Yes'
	print(ans)


for _ in range(int(input())):
	n = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	C = []
	for i in A:
		C.append(i)
	C.sort()
	if C == A:
		print('YES')
		continue
	if B.count(0) >= 1 and B.count(1) >= 1:
		print('YES')
	else:
		print('NO')


for i in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	if sorted(a) == a:
		print('YES')
	elif len(set(b)) == 1:
		print('NO')
	else:
		print('YES')


nt = int(input())
for test in range(nt):
	n = input()
	a = input()
	a = str(a).split(' ')
	a = [int(q) for q in a]
	b = input()
	b = str(b).split(' ')
	b = [int(q) for q in b]
	if len(set(b)) == 2:
		print('Yes')
	else:
		sa = sorted(a)
		if sa == a:
			print('Yes')
		else:
			print('No')


T = int(input())
for t in range(T):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if a == sorted(a) or (0 in b and 1 in b):
		print('Yes')
	else:
		print('No')


import sys
import math
import bisect
import heapq
from bisect import bisect_right
from sys import stdin, stdout

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

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

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

def get_list_of_list(n):
	return [list(map(int, sys.stdin.readline().strip().split())) for _ in range(n)]

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

def myceil(x, y):
	return (x + y - 1) // y

def issorted(a):
	for i in range(1, len(a)):
		if a[i] < a[i - 1]:
			return False
	return True

def Solution(a, b, n):
	s = sum(b)
	if s > 0 and s < n or issorted(a):
		print('YES')
	else:
		print('NO')

def main():
	for _ in range(get_int()):
		n = get_int()
		a = get_ints_in_list()
		b = get_ints_in_list()
		Solution(a, b, n)
main()


def get_info():
	n = int(input())
	numbers = list(map(int, input().split()))
	values = list(map(int, input().split()))
	return (n, numbers, values)

def check_result(n, list1, list2):
	a = []
	b = []
	for (i, j) in zip(list1, list2):
		if j == 0:
			a.append(i)
		else:
			b.append(i)
	if 1 in list2 and 0 in list2:
		print('Yes')
	elif a == sorted(a) and b == sorted(b):
		print('Yes')
	else:
		print('No')
t = int(input())
for _ in range(t):
	(n, list1, list2) = get_info()
	check_result(n, list1, list2)


t = int(input())
for _ in range(t):
	n = int(input())
	arr = [int(p) for p in input().split()]
	typ = [int(p) for p in input().split()]
	if sorted(arr) == arr:
		print('Yes')
	elif min(typ.count(0), typ.count(1)) >= 1:
		print('Yes')
	else:
		print('No')


import math, sys
from sys import stdin, stdout
from collections import Counter, defaultdict, deque
input = stdin.readline
I = lambda : int(input())
li = lambda : list(map(int, input().split()))

def solve():
	n = I()
	a = li()
	b = li()
	c = []
	c = a.copy()
	c.sort()
	if a == c:
		print('Yes')
		return
	if 1 in b and 0 in b:
		print('Yes')
	else:
		print('No')
for _ in range(I()):
	solve()


from sys import stdin, stdout
import sys
from math import *
input = stdin.buffer.readline
for __ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ar = []
	for i in range(n):
		ar.append([a[i], b[i]])
	ar.sort()
	s = []
	for i in range(n):
		s.append(ar[i][0])
	if sum(b) == 1 or sum(b) == n - 1:
		print('Yes')
	elif 1 in b and 0 in b:
		print('Yes')
	elif s == a:
		print('Yes')
	else:
		print('No')


test = int(input())
for i in range(test):
	n = int(input())
	a = [int(x) for x in input().split(' ')]
	b = [int(x) for x in input().split(' ')]
	l1 = 0
	l0 = 0
	a0 = []
	a1 = []
	for i in range(n):
		if b[i] == 0:
			l0 += 1
			a0.append(a[i])
		else:
			l1 += 1
			a1.append(a[i])
	if l0 != 0 and l1 != 0:
		print('Yes')
	else:
		if l0 == 0:
			if sorted(a1) == a1:
				print('Yes')
			else:
				print('No')
		if l1 == 0:
			if sorted(a0) == a0:
				print('Yes')
			else:
				print('No')


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	types = list(map(int, input().split()))
	srt = True
	for i in range(1, len(arr)):
		if arr[i] < arr[i - 1]:
			srt = False
	if srt or (1 in types and 0 in types):
		print('Yes')
	else:
		print('No')


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = [a[i] for i in range(len(a))]
	c.sort()
	ze = b.count(0)
	on = b.count(1)
	if ze >= 1 and on >= 1:
		print('Yes')
	elif c == a:
		print('Yes')
	else:
		print('No')


n = int(input())
for i in range(0, n):
	y = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	countA = 0
	countB = 0
	z = [0] * y
	for j in range(0, y):
		z[j] = a[j]
	for j in range(0, y):
		if b[j] == 0:
			countA += 1
		else:
			countB += 1
	z.sort()
	if countA >= 1 and countB >= 1:
		print('Yes')
	elif z == a:
		print('Yes')
	else:
		print('No')


for _ in range(int(input())):
	i = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if len(set(b)) == 2:
		print('Yes')
	elif a == sorted(a):
		print('Yes')
	else:
		print('No')


import sys
from math import *

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

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

def finput():
	return float(input())

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

def linput():
	return list(input())

def rinput():
	return map(int, tinput())

def fiinput():
	return map(float, tinput())

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

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

def main():
	n = iinput()
	(a, b) = (rlinput(), rlinput())
	q = a.copy()
	q.sort()
	if b.count(0) and b.count(1) or a == q:
		print('Yes')
	else:
		print('No')
for inytd in range(iinput()):
	main()


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = a.copy()
	d = 0
	for i in b:
		if i == 0:
			d += 1
	if d == 0 or d == n:
		a.sort()
		if a == c:
			print('Yes')
		else:
			print('No')
	else:
		print('Yes')


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	for i in range(n - 1):
		if a[i] > a[i + 1]:
			break
	else:
		print('YES')
		continue
	if sum(b) == 0 or sum(b) == n:
		print('NO')
	else:
		print('YES')


from sys import stdin, stdout
t = int(input())
for _ in range(t):
	n = int(input())
	alist = list(map(int, stdin.readline().strip().split()))
	blist = list(map(int, stdin.readline().strip().split()))
	if alist == sorted(alist):
		print('Yes')
	elif 1 in blist and 0 in blist:
		print('Yes')
	else:
		print('No')


import sys

def swap(x, y, a):
	temp = a[x]
	a[x] = a[y]
	a[y] = temp
	return a

def solve():
	return None

def main():
	q = []
	for line in sys.stdin.readlines():
		q.append(line)
	for i in range(len(q)):
		q[i] = q[i].rstrip().split(' ')
		q[i] = [int(x) for x in q[i]]
	for i in range(2, len(q), 3):
		a = q[i]
		indices = q[i + 1]
		if a == sorted(a):
			print('Yes')
		elif len(set(indices)) == 1:
			print('No')
		else:
			print('Yes')
main()


import io
import os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def get_str():
	return input().decode().strip()

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

def oint():
	return int(input())
t = oint()
for _ in range(t):
	n = oint()
	a = list(rint())
	b = list(rint())
	a_sorted = sorted(a)
	if a_sorted == a:
		print('YES')
		continue
	if b.count(0) and b.count(1):
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	if sorted(l1) != l1 and l2.count(1) == 0 or (sorted(l1) != l1 and l2.count(0) == 0):
		print('No')
	else:
		print('Yes')


t = int(input())
for i in range(t):
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	s = set(l2)
	if 0 in s and 1 in s:
		print('Yes')
	else:
		c = 0
		for j in range(0, len(l1)):
			if j == 0:
				continue
			elif l1[j] < l1[j - 1]:
				c = 1
				break
		if c:
			print('No')
		else:
			print('Yes')


from copy import copy

def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		a = list(map(int, input().split()))
		pos = list(map(int, input().split()))
		b = copy(a)
		b.sort()
		count0 = count1 = 0
		for i in pos:
			if i == 1:
				count1 += 1
			else:
				count0 += 1
		if count1 == n or count0 == n:
			if a == b:
				print('Yes')
			else:
				print('No')
		else:
			print('Yes')
main()


import math
from collections import defaultdict

def r():
	return int(input())

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

def rl():
	return list(map(int, input().split()))
for _ in range(r()):
	c = r()
	a = rl()
	b = rl()
	zeros = 0
	ones = 0
	nondecre = True
	for i in range(1, c):
		if a[i] < a[i - 1]:
			nondecre = False
		if b[i] == 1:
			ones += 1
		else:
			zeros += 1
	if b[0] == 0:
		zeros += 1
	else:
		ones += 1
	if zeros == 0 or ones == 0:
		if nondecre:
			print('Yes')
		else:
			print('No')
	else:
		print('Yes')


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	s = set(map(int, input().split()))
	if len(s) > 1 or sorted(l) == l:
		print('YES')
		continue
	else:
		print('NO')
		continue


t = int(input())
for i in range(t):
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	flag1 = True
	flag2 = False
	flag3 = False
	for j in range(1, n):
		if l1[j] >= l1[j - 1]:
			continue
		else:
			flag1 = False
			break
	for j in range(n):
		if l2[j] == 0:
			flag2 = True
		else:
			flag3 = True
	if flag2 and flag3:
		print('Yes')
	elif flag1:
		print('Yes')
	else:
		print('No')


def isSorted(n, a):
	for i in range(1, n):
		if a[i - 1] > a[i]:
			return False
	return True

def solve(n, a, b):
	if n <= 1:
		return True
	if isSorted(n, a):
		return True
	ct = set()
	for v in b:
		ct.add(v)
	return len(ct) > 1
tests = int(input())
for test in range(tests):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	print('Yes' if solve(n, a, b) else 'No')


for test in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	is_zero = False
	is_one = False
	i = 0
	while i < n and (not is_one or not is_zero):
		if b[i] == 0:
			is_zero = True
		else:
			is_one = True
		i += 1
	if is_one and is_zero:
		print('Yes')
	else:
		is_sort = True
		i = 1
		while i < n and is_sort:
			if a[i] < a[i - 1]:
				is_sort = False
			i += 1
		if is_sort:
			print('Yes')
		else:
			print('No')


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().strip().split()))
	b = list(map(int, input().strip().split()))
	if b.count(0) >= 1 and b.count(1) >= 1:
		print('Yes')
	elif sorted(a) == a:
		print('Yes')
	else:
		print('No')


for _ in range(int(input())):
	n = int(input())
	lst1 = [int(x) for x in input().split()]
	lst2 = [int(x) for x in input().split()]
	lt = sorted(lst1)
	if lt == lst1:
		print('Yes')
	else:
		(n_1, n_0) = (0, 0)
		for i in lst2:
			if i == 0:
				n_0 += 1
			if i == 1:
				n_1 += 1
		if n_0 >= 1 and n_1 >= 1:
			print('Yes')
		else:
			print('No')


t = int(input())
for _ in range(t):
	n = int(input())
	arr = [int(x) for x in input().split()]
	typ = [int(x) for x in input().split()]
	flag = True
	sort = True
	tip = typ[0]
	for i in range(1, n):
		if tip != typ[i]:
			break
	else:
		for i in range(1, n):
			if arr[i - 1] > arr[i]:
				flag = False
				break
		if flag:
			print('Yes')
		else:
			print('No')
		continue
	print('Yes')


from collections import Counter
from collections import defaultdict
from collections import deque
import math
import heapq
import sys
import io, os
input = sys.stdin.readline
from bisect import *
rs = lambda : input().strip()
ri = lambda : int(input())
rl = lambda : list(map(int, input().split()))
rls = lambda : list(map(str, input().split()))
t = int(input())
for _ in range(0, t):
	n = int(input())
	a = rl()
	k = rl()
	f1 = 1
	f2 = 1
	x0 = 0
	x1 = 0
	a1 = 0
	a2 = 0
	for i in range(0, n):
		if k[i] == 0:
			a1 = a1 + 1
		else:
			a2 = a2 + 1
	if a1 == 0 or a2 == 0:
		if a == sorted(a):
			print('Yes')
		else:
			print('No')
	else:
		print('Yes')


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if 1 in b and 0 in b:
		print('Yes')
	else:
		data = [num[1] for num in sorted([[a[i], [i, b[i]]] for i in range(n)])]
		b1 = [i for (i, bi) in data if bi == 1]
		b0 = [i for (i, bi) in data if bi == 0]
		if b1 == sorted(b1) and b0 == sorted(b0):
			print('Yes')
		else:
			print('No')


for q in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = []
	b.extend(a)
	type = list(map(int, input().split()))
	n1 = type.count(0)
	n2 = type.count(1)
	b.sort()
	if a == b:
		print('Yes')
	elif n1 == len(a) or n2 == len(a):
		print('No')
	else:
		print('Yes')


t = int(input())
while t:
	n = int(input())
	sorted = 1
	count0 = 0
	count1 = 0
	value = [int(x) for x in input().split()]
	ty = [int(x) for x in input().split()]
	for i in range(n):
		if i >= 1 and value[i] < value[i - 1]:
			sorted = 0
	for i in range(n):
		if ty[i] == 0:
			count0 = 1
		else:
			count1 = 1
	if count0 == 1 and count1 == 1:
		print('Yes')
	elif sorted == 1:
		print('Yes')
	else:
		print('No')
	t -= 1


for t in range(int(input())):
	n = int(input())
	ai = list(map(int, input().split()))
	bi = list(map(int, input().split()))
	a0 = ai[0]
	order = True
	for ii in ai:
		if ii >= a0:
			a0 = ii
		else:
			order = False
			break
	num0 = 0
	num1 = 0
	for ii in bi:
		if ii == 1:
			num1 = 1
		if ii == 0:
			num0 = 1
	if order:
		print('YES')
	elif num0 == 1 and num1 == 1:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	n = int(input())
	a = [x for x in map(int, input().split(' '))]
	b = [x for x in map(int, input().split(' '))]
	asc = True
	for i in range(n - 1):
		if a[i + 1] < a[i]:
			asc = False
			break
	if asc:
		print('Yes')
	elif 0 in b and 1 in b:
		print('Yes')
	elif n == 1:
		print('Yes')
	else:
		print('No')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	(x, y) = (0, 0)
	for i in b:
		if i:
			x += 1
		else:
			y += 1
	c = sorted(a)
	if x >= 1 and y >= 1 or a == c:
		print('Yes')
	else:
		print('No')


t = int(input())
ans = []
for kek in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	x = sum(b)
	if x != n and x != 0:
		ans.append('Yes')
	else:
		c = a.copy()
		c.sort()
		if a == c:
			ans.append('Yes')
		else:
			ans.append('No')
print(*ans, sep='\n')


t = int(input())
while t != 0:
	t -= 1
	n = int(input())
	a = list(map(int, input().strip().split()))[:n]
	b = list(map(int, input().strip().split()))[:n]
	k = []
	for i in range(len(a)):
		k.append(a[i])
	k.sort()
	if k == a:
		print('Yes')
	elif b.count(1) > 0 and b.count(0) > 0:
		print('Yes')
	else:
		print('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')
from math import gcd, ceil

def pre(s):
	n = len(s)
	pi = [0] * n
	for i in range(1, n):
		j = pi[i - 1]
		while j and s[i] != s[j]:
			j = pi[j - 1]
		if s[i] == s[j]:
			j += 1
		pi[i] = j
	return pi

def prod(a):
	ans = 1
	for each in a:
		ans = ans * each
	return ans

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

def binary(x, length=16):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y
for _ in range(int(input()) if True else 1):
	n = int(input())
	a = list(map(int, input().split()))
	x = list(map(int, input().split()))
	z = []
	o = []
	for i in range(n):
		if x[i] == 0:
			z += [a[i]]
		else:
			o += [a[i]]
	print('Yes' if o and z or (sorted(o) == o and sorted(z) == z) else 'No')


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	A = list(map(int, input().split()))
	T = list(map(int, input().split()))
	ordered = True
	last = 0
	for i in range(n):
		if A[i] < last:
			ordered = False
		last = A[i]
	if ordered:
		print('Yes')
		continue
	print('Yes' if len(set(T)) == 2 else 'No')


t = int(input())
for _ in range(t):
	n = int(input())
	x = list(map(int, input().split()))
	z = list(x)
	y = list(map(int, input().split()))
	c = 0
	if 0 in y:
		c += 1
	if 1 in y:
		c += 1
	if c == 2:
		print('YES')
	else:
		z.sort()
		if z == x:
			print('YES')
		else:
			print('NO')


for _ in range(int(input())):
	x = int(input())
	data = list(map(int, input().split()))
	labels = list(map(int, input().split()))
	flag = True
	for i in range(x - 1):
		if data[i] > data[i + 1]:
			flag = False
			break
	if flag == False:
		zeroCount = labels.count(0)
		if zeroCount == x or zeroCount == 0:
			print('No')
		else:
			print('Yes')
	else:
		print('Yes')


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	k = list(map(int, input().split()))
	l1 = []
	l0 = []
	flag = 0
	for i in range(n - 1):
		if l[i] > l[i + 1]:
			flag = 1
			break
	if flag == 0:
		print('YES')
		continue
	zc = 0
	oc = 0
	for i in k:
		if i == 0:
			zc += 1
		else:
			oc += 1
	if zc > 0 and oc > 0:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if a == sorted(a):
		print('YES')
	else:
		zero = []
		one = []
		for i in range(n):
			if b[i] == 1:
				one.append(a[i])
			else:
				zero.append(a[i])
		if len(one) >= 1 and len(zero) >= 1:
			print('YES')
		elif zero == sorted(zero) and one == sorted(one):
			print('YES')
		else:
			print('NO')


for _ in range(int(input())):
	a = input()
	z = list(map(int, input().split()))
	x = set(map(int, input().split()))
	if len(x) == 1 and z == sorted(z) or len(x) == 2:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	s0 = 0
	s1 = 0
	for i in b:
		if i == 0:
			s0 = 1
		else:
			s1 = 1
	ans = 'NO'
	if s0 and s1:
		ans = 'YES'
	temp = a.copy()
	a.sort()
	if a == temp:
		ans = 'YES'
	print(ans)


import sys
t = int(sys.stdin.readline())
for _ in range(t):
	n = int(sys.stdin.readline())
	a_s = [int(i) for i in sys.stdin.readline().split()]
	b_s = [int(i) for i in sys.stdin.readline().split()]
	isSorted = a_s == sorted(a_s)
	homo = sum(b_s) == n or sum(b_s) == 0
	if isSorted or not homo:
		print('YES')
	else:
		print('NO')


T = int(input())
for t in range(T):
	n = int(input())
	A = [int(i) for i in input().split()]
	B = [int(i) for i in input().split()]
	if len(set(B)) == 2:
		print('Yes')
	else:
		for i in range(n - 1):
			if A[i + 1] < A[i]:
				print('No')
				break
		else:
			print('Yes')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = set(map(int, input().split()))
	flag = False
	for i in range(n - 1):
		if a[i] > a[i + 1]:
			flag = True
			break
	if flag:
		print('YNeos'[len(b) != 2::2])
	else:
		print('Yes')


def ar(arr, n):
	for i in range(n - 1):
		if arr[i + 1] < arr[i]:
			return False
	return True
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	arr2 = list(map(int, input().split()))
	arr2 = set(arr2)
	if len(arr2) == 1:
		if ar(arr, n):
			print('Yes')
		else:
			print('No')
	else:
		print('Yes')


import sys

def input():
	return sys.stdin.readline().rstrip()
t = int(input())
answers = []

def check_non_dec(array):
	for i in range(len(array) - 1):
		if array[i + 1] < array[i]:
			return False
	return True
for _ in range(t):
	n = int(input())
	array = [int(i) for i in input().split()]
	bs = [int(i) for i in input().split()]
	arr1 = []
	arr2 = []
	for i in range(n):
		if bs[i] == 0:
			arr1.append(array[i])
		else:
			arr2.append(array[i])
	ans = True
	if len(arr1) == 0 or len(arr2) == 0:
		ans = check_non_dec(arr1) and check_non_dec(arr2)
	if ans:
		answers.append('Yes')
	else:
		answers.append('No')
print(*answers, sep='\n')


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if sorted(a) == a:
		print('yes')
	else:
		ar = [0, 0]
		for i in b:
			ar[i] += 1
		if ar[0] > 0 and ar[1] > 0:
			print('yes')
		else:
			print('no')


ncases = int(input())
for i in range(ncases):
	length = input()
	values = input().split(' ')
	types = input().split(' ')
	c_values = []
	c_types = []
	d1 = {}
	for (a, b) in zip(values, types):
		a = int(a)
		b = int(b)
		c_values.append(a)
		c_types.append(b)
		if a not in d1:
			d1[a] = b
	cc_values = c_values[:]
	cc_values.sort()
	if cc_values == c_values:
		print('yes')
	elif 0 not in c_types or 1 not in c_types:
		print('no')
	else:
		print('yes')


t = int(input())
for i in range(t):
	n = int(input())
	keys = [int(j) for j in input().split()]
	vals = [int(k) for k in input().split()]
	keysort = sorted(keys)
	if keys == keysort:
		print('Yes')
	elif 1 in vals and 0 in vals:
		print('Yes')
	else:
		print('No')


from collections import defaultdict as dfd
import math
import sys
import heapq

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

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

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

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

def main():
	for _ in range(int(input())):
		N = II()
		A = LI()
		B = LI()
		val = list(A)
		val.sort()
		C = list(set(B))
		if val == A:
			print('Yes')
		elif len(C) == 2:
			print('Yes')
		else:
			print('No')
main()


from sys import *
input = stdin.readline
for u in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	d = list(map(int, input().split()))
	if l == sorted(l):
		print('Yes')
	elif len(set(d)) == 2:
		print('Yes')
	else:
		print('No')


import sys
readline = sys.stdin.readline
ns = lambda : readline().rstrip()
ni = lambda : int(readline().rstrip())
nm = lambda : map(int, readline().split())
nl = lambda : list(map(int, readline().split()))

def solve():
	n = ni()
	a = nl()
	b = nl()
	if 0 < sum(b) < n:
		print('Yes')
	else:
		print('Yes' if a == sorted(a) else 'No')
	return
T = int(input())
for _ in range(T):
	solve()


for _ in range(int(input())):
	n = int(input())
	lst = list(map(int, input().split()))
	lst2 = list(map(int, input().split()))
	if len(set(lst2)) == 2 or lst == sorted(lst):
		print('Yes')
	else:
		print('No')


for _ in range(int(input())):
	N = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	res = 'Yes'
	if 0 not in b or 1 not in b:
		for i in range(1, N):
			if a[i - 1] > a[i]:
				res = 'No'
	print(res)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	s = a.copy()
	s.sort()
	if b.count(1) == 0 or b.count(0) == 0:
		if a == s:
			print('Yes')
		else:
			print('No')
	else:
		print('Yes')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	new = a.copy()
	new.sort()
	arr0 = [0] * n
	arr1 = [1] * n
	if new == a:
		print('Yes')
	elif new != a and (b == arr0 or b == arr1):
		print('No')
	else:
		print('Yes')


T = int(input())
while T > 0:
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	already = True
	prev = 0
	zeros = 0
	for i in range(n):
		if a[i] < prev:
			already = False
		else:
			prev = a[i]
		if b[i] == 0:
			zeros += 1
	if already is True:
		print('Yes')
	else:
		ones = n - zeros
		if ones > 0 and zeros > 0:
			print('Yes')
		else:
			print('No')
	T -= 1


import sys
input = sys.stdin.readline

def solve(n, a, b):
	if 1 in b and 0 in b or a == sorted(a):
		return 'Yes'
	else:
		return 'No'
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	print(solve(n, a, b))


t = int(input())
for _ in range(t):
	flag = False
	n = int(input())
	num = input() + ' '
	tip = input()
	dif = -1
	for tp in tip[::2]:
		if tp != dif and dif != -1:
			flag = True
			break
		dif = tp
	if flag:
		print('Yes')
		continue
	flag = True
	el = ''
	max_el = 1
	for nm in num:
		if nm == ' ':
			el = int(el)
			if el < max_el:
				flag = False
				print('No')
				break
			max_el = el
			el = ''
		else:
			el += nm
	if flag:
		print('Yes')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	fOne = False
	fZero = False
	for i in range(len(b)):
		if b[i] == 0:
			fZero = True
		elif b[i] == 1:
			fOne = True
		if fZero and fOne:
			print('YES')
			break
	else:
		for j in range(len(a) - 1):
			if a[j] > a[j + 1]:
				print('NO')
				break
		else:
			print('YES')


def solve(array1, array2):
	sorted = True
	for i in range(len(array1) - 1):
		if array1[i] > array1[i + 1]:
			sorted = False
	typeA = 0
	typeB = 0
	for elem in array2:
		if elem == 0:
			typeA += 1
		else:
			typeB += 1
	if typeA == 0 or typeB == 0:
		if sorted:
			return 'Yes'
		return 'No'
	return 'Yes'
input()
while True:
	try:
		ig = input()
		vals = input().split(' ')
		val = input().split(' ')
		arr = []
		for i in range(len(val)):
			vals[i] = int(vals[i])
			arr.append(int(val[i]))
		print(solve(vals, arr))
	except EOFError:
		break


from math import *
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	k = b.count(1)
	m = n - k
	r = a.copy()
	r.sort()
	x = min(m, k)
	if x >= 1:
		print('YES')
	else:
		for i in range(n):
			if a[i] != r[i]:
				print('NO')
				break
		else:
			print('YEs')


from sys import stdin, exit, setrecursionlimit
from collections import deque
from heapq import _heappop_max, heappush, heappop
from math import gcd
from math import ceil, log2
setrecursionlimit(10000000)
from collections import deque
input = stdin.readline
lmi = lambda : list(map(int, input().split()))
mi = lambda : map(int, input().split())
si = lambda : input().strip('\n')
ssi = lambda : input().strip('\n').split()
for _ in range(int(input())):
	n = int(input())
	a = lmi()
	b = lmi()
	print('No' if len(set(b)) <= 1 and a != sorted(a) else 'Yes')


t = int(input())
for _ in range(t):
	n = int(input())
	num = list(map(int, input().split()))
	types = list(map(int, input().split()))
	sorted = []
	for i in num:
		sorted.append(i)
	sorted.sort()
	zero = 0
	ones = 0
	for i in types:
		if i == 0:
			zero += 1
		else:
			ones += 1
	if zero != 0 and ones != 0:
		print('YES')
	elif num == sorted:
		print('YES')
	else:
		print('NO')


def main():
	t = int(input())
	for i in range(t):
		n = int(input())
		values = list(map(int, input().split()))
		types = list(map(int, input().split()))
		count_0 = 0
		count_1 = 0
		for i in types:
			if i == 0:
				count_0 += 1
			else:
				count_1 += 1
		if count_0 != 0 and count_1 != 0:
			print('Yes')
		else:
			cop = values[:]
			cop.sort()
			if cop == values:
				print('Yes')
			else:
				print('No')
main()


def modinv(n, p):
	return pow(n, p - 2, p)

def main():
	for case in range(int(input())):
		n = int(input())
		a = [int(x) for x in input().split()]
		v = [int(x) for x in input().split()]
		if len(set(v)) == 1:
			temp = [x for x in a]
			temp.sort()
			if temp == a:
				print('yes')
			else:
				print('no')
		else:
			print('yes')
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

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

class IOWrapper(IOBase):

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


t = int(input())
for test in range(t):
	n = int(input())
	nums = [int(x) for x in input().split()]
	type = [int(x) for x in input().split()]
	t1 = 0
	t2 = 0
	for i in range(n):
		if type[i] == 0:
			t1 = 1
		if type[i] == 1:
			t2 = 1
	if t1 == 1 and t2 == 1:
		print('Yes')
	else:
		nums2 = sorted(nums)
		flag = 0
		for i in range(n):
			if nums[i] != nums2[i]:
				flag = 1
				break
		if flag == 1:
			print('No')
		else:
			print('Yes')


t = int(input())
for i in range(t):
	l = int(input())
	arr1 = [int(x) for x in input().split()]
	arr2 = [int(x) for x in input().split()]
	if sum(arr2) == l or sum(arr2) == 0:
		print('YES' if sorted(arr1) == arr1 else 'NO')
	else:
		print('YES')


t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	sorteda = sorted(a)
	if a == sorteda:
		print('yes')
	elif 0 in b and 1 in b:
		print('yes')
	else:
		print('no')


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	temp = sorted(a)
	if a == temp:
		print('YES')
		continue
	count = 0
	for i in b:
		if i == 0:
			count += 1
	if count == 0 or count == n:
		print('NO')
	else:
		print('YES')


def read_int():
	return int(input())

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

def dec(x):
	return x - 1

def inc(x):
	return x + 1

def odd(x):
	return x % 2 != 0

def update_type(x, b):
	(t_0, t_1) = b
	if x == 0:
		return (inc(t_0), t_1)
	else:
		return (t_0, inc(t_1))

def is_sorted(lst):

	def update_flag(lst, idx):
		return lst[dec(idx)] >= lst[dec(dec(idx))]

	def is_sorted_helper(lst, idx, flag):
		if idx == 1:
			return flag
		else:
			return is_sorted_helper(lst, dec(idx), flag and update_flag(lst, idx))
	return is_sorted_helper(lst, len(lst), True)

def is_sortable(lst_item, lst):

	def are_both_types_count_equal(lst, idx, type_01):
		(type_0, type_1) = type_01
		if idx == 0:
			if type_0 != 0 and type_1 != 0:
				return abs(type_0 - type_1) >= 1 or type_0 == type_1
			else:
				return False
		else:
			return are_both_types_count_equal(lst, dec(idx), update_type(lst[idx - 1], (type_0, type_1)))
	if is_sorted(lst_item) or are_both_types_count_equal(lst, len(lst), (0, 0)):
		return 'Yes'
	else:
		return 'No'

def trouble_sort_handler(test_cases):
	if test_cases != 0:
		size = read_int()
		lst = read_lst()
		type_info_lst = read_lst()
		print(is_sortable(lst, type_info_lst))
		return trouble_sort_handler(dec(test_cases))

def main():
	test_cases = read_int()
	trouble_sort_handler(test_cases)
main()


import sys
input = sys.stdin.readline
t = int(input())
for t1 in range(t):
	n = int(input())
	l = list(map(int, input().split(' ')))
	l1 = list(map(int, input().split(' ')))
	if l == sorted(l):
		print('Yes')
	elif len(list(set(l1))) > 1:
		print('Yes')
	else:
		print('No')


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

def inin():
	return int(input())

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

def ar(element, size):
	return [element for i in range(size)]

def yes():
	print('Yes')

def no():
	print('No')
Testcase = inin()
for _ in range(Testcase):
	n = inin()
	arr = inar()
	b = inar()
	a = list(sorted(arr))
	cnt0 = 0
	cnt1 = 0
	for i in b:
		if i == 0:
			cnt0 += 1
		else:
			cnt1 += 1
	if arr == a:
		yes()
	elif cnt0 > 0 and cnt1 > 0 and (arr != a):
		yes()
	else:
		no()


a = int(input())
for i in range(a):
	m = int(input())
	z = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a1 = []
	a2 = []
	if b.count(0) == 0 or b.count(1) == 0:
		m = sorted(z)
		if m == z:
			print('Yes')
		else:
			print('No')
	else:
		print('Yes')


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if a == sorted(a):
		print('Yes')
	elif b.count(0) == len(b) or b.count(1) == len(b):
		print('No')
	else:
		l = []
		for i in range(len(a)):
			l.append([a[i], b[i]])
		l.sort()
		temp = []
		for j in range(len(l)):
			temp.append(l[i][1])
		if temp != b:
			print('Yes')
		else:
			print('No')


import sys

def input():
	return sys.stdin.readline()[:-1]

def main():
	for _ in range(int(input())):
		n = int(input())
		a = list(map(int, input().split()))
		b = sorted(list(map(int, input().split())))
		c = sorted(a)
		if n == 1:
			print('Yes')
		elif b[0] != b[-1]:
			print('Yes')
		else:
			print('Yes' if a == c else 'No')
main()


import sys
input = sys.stdin.readline

def solve():
	N = int(input())
	L1 = list(map(int, input().split()))
	L2 = list(map(int, input().split()))
	if sorted(L1) == L1:
		print('YES')
	else:
		(f1, f2) = (0, 0)
		for i in L2:
			if i == 0:
				f1 = 1
			else:
				f2 = 1
		if f1 == 1 and f2 == 1:
			print('YES')
		else:
			print('NO')
for _ in range(int(input())):
	solve()


t = int(input())

def isSorted(a):
	if a == sorted(a):
		return True
	else:
		return False

def solve(a, b):
	if isSorted(a):
		return 'Yes'
	if 1 in b and 0 in b:
		return 'Yes'
	else:
		return 'No'
while t > 0:
	n = input()
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	print(solve(a, b))
	t -= 1


import sys
input = sys.stdin.readline

def solve(values, types):
	acc = types[0]
	for t in types:
		if t != acc:
			return 'Yes'
	for i in range(len(values)):
		if i > 0 and values[i] < values[i - 1]:
			return 'No'
	return 'Yes'
N = int(input())
for ii in range(N):
	n = int(input())
	values = list(map(int, input().split()))
	types = list(map(int, input().split()))
	print(solve(values, types))


import sys
import math
t = int(sys.stdin.readline().strip())
for i in range(t):
	n = int(sys.stdin.readline().strip())
	a = list(map(int, sys.stdin.readline().strip().split(' ')))
	b = list(map(int, sys.stdin.readline().strip().split(' ')))
	ones = set([])
	zeros = set([])
	for i in range(n):
		if b[i] == 1:
			ones.add(i)
		else:
			zeros.add(i)
	if len(ones) == 0 or len(zeros) == 0:
		possible = True
		for i in range(1, len(a)):
			if a[i] < a[i - 1]:
				possible = False
				break
		if possible:
			print('Yes')
		else:
			print('No')
	else:
		print('Yes')


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ones = zeroes = 0
	for num in b:
		if num:
			ones += 1
		else:
			zeroes += 1
	if ones and (not zeroes) or (not ones and zeroes):
		flag = True
		for i in range(1, n):
			if a[i - 1] > a[i]:
				flag = False
				break
		if flag:
			print('Yes')
		else:
			print('No')
	elif ones > 0 and zeroes > 0:
		print('Yes')
	else:
		print('No')


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	g = list(map(int, input().split()))
	m = l[:]
	m.sort()
	if l == m:
		print('Yes')
	elif g.count(0) > 0 and g.count(1) > 0:
		print('Yes')
	else:
		print('No')


import sys
I = sys.stdin.readline
ans = ''
for _ in range(int(I())):
	n = int(I())
	val = list(map(int, I().split()))
	typ = list(map(int, I().split()))
	if 0 in typ and 1 in typ:
		ans += 'Yes\n'
	elif val == sorted(val):
		ans += 'Yes\n'
	else:
		ans += 'No\n'
print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	if len(set(b)) == 2:
		print('YES')
	elif sorted(a) == a:
		print('YES')
	else:
		print('NO')


T = int(input())
for _ in range(T):
	n = int(input())
	a1 = list(map(int, input().split()))
	a2 = list(map(int, input().split()))
	print('No' if a2.count(1) % n == 0 and a1 != sorted(a1) else 'Yes')


t = int(input())
for T in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	if 0 in b and 1 in b:
		print('Yes')
	else:
		Yes = True
		for i in range(1, n):
			if a[i] < a[i - 1]:
				Yes = False
				break
		if Yes:
			print('Yes')
		else:
			print('No')


T = int(input())
for t in range(T):
	n = int(input())
	A = [int(_) for _ in input().split()]
	B = [int(_) for _ in input().split()]
	if A == sorted(A):
		print('YES')
	elif 1 in B and 0 in B:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	n = int(input())
	vetor = list(map(int, input().split()))
	aux = list(map(int, input().split()))
	if len(list(set(aux))) == 1:
		flag = True
		for a in range(1, n):
			if vetor[a - 1] > vetor[a]:
				flag = False
				break
		if not flag:
			print('No')
		else:
			print('Yes')
	else:
		print('Yes')


import sys
input = sys.stdin.readline
from sys import stdin, stdout

def main():

	def is_sorted(l):
		for i in range(1, len(l)):
			if l[i] < l[i - 1]:
				return 0
		return 1
	for _ in range(int(input())):
		n = int(input())
		a = [int(s) for s in input().split()]
		b = [int(s) for s in input().split()]
		if len(set(b)) == 1:
			if is_sorted(a):
				print('Yes')
			else:
				print('No')
		else:
			print('Yes')
main()


for _ in range(int(input())):
	tam = int(input())
	val = [int(i) for i in input().split()]
	tip = [int(i) for i in input().split()]
	test = tip[0]
	flag = False
	for i in tip:
		if i != test:
			flag = True
			break
	if flag:
		print('Yes')
	else:
		flag = True
		for i in range(tam - 1):
			if val[i] > val[i + 1]:
				flag = False
		if flag:
			print('Yes')
		else:
			print('No')


for _ in range(int(input())):
	n = int(input())
	a = [int(__) for __ in input().split()]
	b = [int(___) for ___ in input().split()]
	c = sorted(a)
	if 1 in b and 0 in b:
		print('Yes')
	elif c == a:
		print('Yes')
	else:
		print('No')


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if sorted(a) != a:
		if 0 not in b or 1 not in b:
			print('No')
			continue
	print('Yes')


import math

def WaaZnA():
	for _ in range(int(input())):
		n = int(input())
		arr = list(map(int, input().split()))
		brr = list(map(int, input().split()))
		srt = True
		for i in range(n - 1):
			if arr[i] > arr[i + 1]:
				srt = False
				break
		one = zero = 0
		for i in brr:
			if i & 1:
				one += 1
			else:
				zero += 1
		if srt or (zero and one):
			print('Yes')
		else:
			print('No')
WaaZnA()


import sys
input = sys.stdin.buffer.readline

def prog():
	for _ in range(int(input())):
		n = int(input())
		a = list(map(int, input().split()))
		b = list(map(int, input().split()))
		ones = 0
		zeros = 0
		for i in b:
			if i == 0:
				zeros += 1
			else:
				ones += 1
		if ones > 0 and zeros > 0:
			print('Yes')
		else:
			non_decreasing = True
			for i in range(n - 1):
				if a[i] > a[i + 1]:
					non_decreasing = False
					break
			if non_decreasing:
				print('Yes')
			else:
				print('No')
prog()


def is_sortable(n, a, b):
	if len(set(b)) != 1:
		return 'Yes'
	elif all((a[i] <= a[i + 1] for i in range(len(a) - 1))):
		return 'Yes'
	else:
		return 'No'
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	print(is_sortable(n, a, b))


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	t = list(map(int, input().split()))
	c0 = t.count(0)
	c1 = t.count(1)
	if c1 != 0 and c0 != 0:
		print('Yes')
	else:
		temp = arr.copy()
		temp.sort()
		if temp == arr:
			print('Yes')
		else:
			print('No')


from collections import defaultdict
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().strip().split()))
	typ = list(map(int, input().strip().split()))
	if sorted(arr) == arr:
		print('Yes')
	elif typ.count(0) == 0 or typ.count(0) == n:
		print('No')
	else:
		print('Yes')


def issorted(arr):
	return all((arr[i] <= arr[i + 1] for i in range(len(arr) - 1)))

def soln(arr):
	prev = arr[0][1]
	for (a, b) in arr:
		if b != prev:
			return 'Yes'
	if issorted([a for (a, b) in arr]):
		return 'Yes'
	return 'No'

def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		aVals = [int(x) for x in input().split()]
		bVals = [int(x) for x in input().split()]
		arr = [(a, b) for (a, b) in zip(aVals, bVals)]
		result = soln(arr)
		print(result)
main()


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	k = list(map(int, input().split()))
	p = l
	if sorted(p) == l:
		print('Yes')
	else:
		o = k.count(0)
		e = k.count(1)
		if o > 0 and e > 0:
			print('Yes')
		else:
			print('No')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = []
	for (i, j) in zip(a, b):
		c.append((i, j))
	c.sort(key=lambda x: x[0])
	total_0 = b.count(0)
	total_diff = 0
	for i in range(n):
		if c[i][0] != a[i]:
			total_diff += 1
	if total_diff == 0:
		print('YES')
	elif total_0 == 0 or total_0 == n:
		print('NO')
	else:
		print('YES')


from collections import Counter
for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	l = list(map(int, input().split()))
	b = []
	b.extend(a)
	b.sort()
	if b == a:
		print('YES')
	else:
		c = Counter(l)
		if c[1] > 0 and c[1] < n:
			print('YES')
		else:
			print('NO')


from random import randint, random
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if (sum(b) == len(b) or sum(b) == 0) and sorted(a) != a and (len(a) > 1):
		print('No')
	else:
		print('Yes')


t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	all_the_same = True
	for i in range(1, n):
		if b[0] != b[i]:
			all_the_same = False
			break
	if not all_the_same:
		print('Yes')
		continue
	c = sorted(a)
	is_sorted = True
	for i in range(n):
		if a[i] != c[i]:
			is_sorted = False
			break
	if is_sorted:
		print('Yes')
	else:
		print('No')


def swap(a, i, j):
	temp = a[i]
	a[i] = a[j]
	a[j] = temp
for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = a.copy()
	c.sort()
	if a == c:
		print('Yes')
	elif set(b) == {0, 1}:
		print('Yes')
	else:
		print('No')


for _ in range(int(input())):
	n = int(input())
	lis = list(map(int, input().split()))
	lib = list(map(int, input().split()))
	s = set()
	for i in lib:
		s.add(i)
	ll = sorted(lis)
	if len(s) == 1 and ll != lis:
		print('No')
	else:
		print('Yes')


for _ in range(int(input())):
	input()
	li = list(map(int, input().split()))
	li2 = list(map(int, input().split()))
	if li == sorted(li):
		print('YES')
	elif li2.count(0) != 0 and li2.count(1) != 0:
		print('YES')
	else:
		print('NO')


for cas in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	flag = True
	binary = True
	for i in range(n - 1):
		if a[i] <= a[i + 1]:
			pass
		else:
			flag = False
		if b[i] != b[i + 1]:
			binary = False
	if flag:
		print('Yes')
		continue
	if not binary:
		print('Yes')
	else:
		print('No')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	li0 = []
	li1 = []
	for i in range(len(a)):
		if b[i] == 0:
			li0.append(a[i])
		else:
			li1.append(a[i])
	if sorted(li1) == li1 and sorted(li0) == li0:
		print('Yes')
	elif len(li1) > 0 and len(li0) > 0:
		print('Yes')
	else:
		print('No')


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	d = sum(b)
	q = a[::-1]
	q.sort()
	if q == a:
		print('Yes')
	elif d == 0:
		print('No')
	elif d == n:
		print('No')
	else:
		print('Yes')


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

def readn():
	return int(input())
for _ in range(readn()):
	n = readn()
	A = readintlst()
	B = readintlst()
	ones = sum(B)
	ans = 'yes' if A == sorted(A) else 'no' if ones in (0, n) else 'yes'
	print(ans)


T = int(input().strip())
for t in range(T):
	n = int(input().strip())
	a = list(map(int, input().strip().split()))[:n]
	tipes = list(map(int, input().strip().split()))[:n]
	if len(set(tipes)) != 1:
		print('Yes')
		continue
	elif sorted(a) == a:
		print('Yes')
	else:
		print('No')


def solve(n, a, b):
	has0 = has1 = False
	for (x, t) in zip(a, b):
		if t == 0:
			has0 = True
		else:
			has1 = True
	if has0 and has1:
		return True
	for i in range(1, n):
		if a[i] < a[i - 1]:
			return False
	return True
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	print('Yes' if solve(n, a, b) else 'No')


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	k = list(map(int, input().split()))
	sort = l[:]
	sort.sort()
	if sort == l:
		print('Yes')
	elif k.count(1) != 0 and k.count(0) != 0:
		print('Yes')
	else:
		print('No')


MI = lambda : map(int, input().split())
for _ in range(int(input())):
	(n, a, b) = (int(input()), list(MI()), list(MI()))
	ans = b.count(0) in [0, n] and a != sorted(a)
	print(['NO', 'YES'][not ans])


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	o = list(map(int, input().split()))
	c1 = 0
	c2 = 0
	li = l[:]
	li.sort()
	for i in o:
		if i == 1:
			c1 += 1
		else:
			c2 += 1
	if c1 > 0 and c2 > 0 or li == l:
		print('YES')
	else:
		print('NO')


for tt in range(int(input())):
	n = int(input())
	arr = [int(_) for _ in input().split()]
	flag_arr = [int(_) for _ in input().split()]
	a2 = sorted(arr)
	if 0 in flag_arr and 1 in flag_arr or a2 == arr:
		print('Yes')
	else:
		print('No')


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ohno = 0
	nice = 0
	milse = True
	for i in b:
		if i == 1:
			nice += 1
		else:
			ohno += 1
	for j in range(n - 1):
		if a[j] > a[j + 1]:
			milse = False
	if milse:
		print('Yes')
	elif ohno == 0 or nice == 0:
		print('No')
	else:
		print('Yes')


t = int(input())
for i in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	e = a.copy()
	r = a.copy()
	e.sort()
	r.sort(reverse=True)
	x = b.count(0)
	y = b.count(1)
	if e == a:
		print('YES')
	elif x != n and y != n:
		print('YES')
	else:
		print('NO')


from sys import stdin
import copy
input = stdin.readline
for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	sb = sum(b)
	if sb == 0 or sb == n:
		c = copy.copy(a)
		c.sort()
		print('Yes' if a == c else 'No')
	else:
		print('Yes')


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	aso = sorted(a)
	for (e1, e2) in zip(a, aso):
		if e1 != e2:
			break
	else:
		print('Yes')
		continue
	one = 0
	zero = 0
	for e in b:
		if e == 0:
			zero += 1
		else:
			one += 1
	if one and zero:
		print('Yes')
	else:
		print('No')


from sys import stdin
input = stdin.buffer.readline
for _ in range(int(input())):
	n = int(input())
	(*a,) = map(int, input().split())
	b = sum(map(int, input().split()))
	if a == sorted(a):
		print('Yes')
		continue
	if b == n or not b:
		print('No')
	else:
		print('Yes')


import sys
input = lambda : sys.stdin.readline().rstrip()
mod = 10 ** 9 + 7
from collections import deque
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	zeros = []
	ones = []
	for i in range(n):
		if b[i] == 0:
			zeros.append(a[i])
		else:
			ones.append(a[i])
	ones_sorted = sorted(ones)
	zeros_sorted = sorted(zeros)
	if len(zeros) == 0:
		if ones_sorted == ones:
			print('Yes')
		else:
			print('No')
	elif len(ones) == 0:
		if zeros_sorted == zeros:
			print('Yes')
		else:
			print('No')
	else:
		print('Yes')


def prov(nach):
	global a, b, r, n
	for i in range(n):
		h = a[i:].index(r[i]) + i
		while h != i:
			if b[h] != b[h - 1]:
				(b[h], b[h - 1]) = (b[h - 1], b[h])
				(a[h], a[h - 1]) = (a[h - 1], a[h])
				h -= 1
			else:
				return False
		if h != i:
			return False
	return True
tests = int(input())
for _ in range(tests):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	r = sorted(a)
	ans = []
	ans1 = []
	for i in range(n):
		if b[i] == 0:
			ans.append(a[i])
		else:
			ans1.append(a[i])
	if len(ans) == 0 and ans1 != sorted(ans1) or (len(ans1) == 0 and ans != sorted(ans)):
		print('No')
	else:
		print('Yes')


for _ in range(int(input())):
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	l3 = l1.copy()
	l3.sort()
	if l1 == l3:
		print('YES')
	elif l2.count(0) == 0 or l2.count(1) == 0:
		print('NO')
	else:
		print('YES')


import sys
from sys import stdin
input = sys.stdin.readline
for _ in range(int(input())):
	N = int(input())
	arr = [int(x) for x in input().split()]
	brr = [int(x) for x in input().split()]
	a = []
	for i in arr:
		a.append(i)
	a.sort()
	if len(set(brr)) == 1:
		if arr == a:
			print('Yes')
		else:
			print('No')
	else:
		print('Yes')


for testcase in range(int(input())):
	input()
	numbers = list(map(int, input().split()))
	prev = numbers[0]
	for i in numbers[1:]:
		if i < prev:
			break
		prev = i
	else:
		print('Yes')
		input()
		continue
	types = input()
	if '1' not in types or '0' not in types:
		print('No')
	else:
		print('Yes')


from __future__ import division, print_function
from sys import stdin, stdout
import bisect
import math
import heapq
i_m = 9223372036854775807

def inin():
	return int(input())

def stin():
	return input()

def spin():
	return map(int, stin().split())

def lin():
	return list(map(int, stin().split()))

def matrix(n):
	return [list(map(int, input().split())) for i in range(n)]

def count2Dmatrix(i, list):
	return sum((c.count(i) for c in list))

def modinv(n, p):
	return pow(n, p - 2, p)

def GCD(x, y):
	x = abs(x)
	y = abs(y)
	if min(x, y) == 0:
		return max(x, y)
	while y:
		(x, y) = (y, x % y)
	return x

def Divisors(n):
	l = []
	for i in range(1, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n // i == i:
				l.append(i)
			else:
				l.append(i)
				l.append(n // i)
	return l
prime = []

def SieveOfEratosthenes(n):
	global prime
	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
	f = []
	for p in range(2, n):
		if prime[p]:
			f.append(p)
	return f
q = []

def dfs(n, d, v, c):
	global q
	v[n] = 1
	x = d[n]
	q.append(n)
	j = c
	for i in x:
		if i not in v:
			f = dfs(i, d, v, c + 1)
			j = max(j, f)
	return j
for _ in range(inin()):
	n = inin()
	a = lin()
	b = lin()
	if a == sorted(a):
		print('Yes')
		continue
	elif len(set(a)) == 1 or len(set(b)) == 1:
		print('No')
		continue
	if b.count(0) >= 1 and b.count(1) >= 1:
		print('Yes')
	else:
		print('No')


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	l1 = list(map(int, input().split()))
	c1 = 0
	c2 = 0
	f = 0
	for i in l1:
		if i == 0:
			c1 += 1
		else:
			c2 += 1
		if c1 > 0 and c2 > 0:
			print('Yes')
			f = 1
			break
	if f == 1:
		continue
	l1 = l.copy()
	l1.sort()
	if l1 == l:
		print('Yes')
	else:
		print('No')


from sys import stdin
input = iter(stdin.readlines()).__next__
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if n == 1:
		print('Yes')
		continue
	(zero, one) = (False, False)
	for bi in b:
		if bi == 0:
			zero = True
		else:
			one = True
	if zero and one:
		print('Yes')
	elif all((a[i] <= a[i + 1] for i in range(0, n - 1))):
		print('Yes')
	else:
		print('No')


import sys
input = sys.stdin.readline

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

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

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

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

def can_sort(arr, arr_type):
	if sorted(arr) == arr:
		return True
	else:
		if arr_type.count(0) == len(arr) or arr_type.count(1) == len(arr):
			return False
		return True
num_tests = inp()
for _ in range(num_tests):
	n = inp()
	arr = inlt()
	arr_type = inlt()
	if can_sort(arr, arr_type):
		print('Yes')
	else:
		print('No')


t = int(input())
while t > 0:
	t = t - 1
	n = int(input())
	a = input().split()
	b = input().split()
	for i in range(n):
		a[i] = int(a[i])
		b[i] = int(b[i])
	l = sorted(a)
	if str(l) != str(a) and (b.count(0) == 0 or b.count(0) == n):
		print('No')
	else:
		print('Yes')


testCases = int(input())
while testCases > 0:
	size = int(input())
	elements = list(map(int, input().split()))
	pairity = list(map(int, input().split()))
	zeroParity = False
	oneParity = False
	for b in pairity:
		if b == 0:
			zeroParity = True
		else:
			oneParity = True
	if zeroParity == oneParity:
		print('Yes')
	else:
		ordered = True
		for i in range(size - 1):
			if elements[i] > elements[i + 1]:
				ordered = False
				break
		if ordered is True:
			print('Yes')
		else:
			print('No')
	testCases -= 1


import functools

def A():
	t = int(input())
	for _ in range(t):
		(n, m) = map(int, input().split())
		a = [[]] * n
		for j in range(n):
			a[j] = list(map(int, input().split()))
		free_str_state = [1] * n
		free_col_state = [1] * m
		for i in range(n):
			for j in range(m):
				if a[i][j]:
					free_str_state[i] = 0
					free_col_state[j] = 0
		res = min(sum(free_str_state), sum(free_col_state))
		if res % 2 == 1:
			print('Ashish')
		else:
			print('Vivek')

def B():
	t = int(input())
	for _ in range(t):
		n = int(input())
		a = list(map(int, input().split()))
		b = list(map(int, input().split()))
		el0_cnt = len([e for e in b if e == 0])
		el1_cnt = n - el0_cnt
		if el0_cnt == 0 or el1_cnt == 0:
			sorted_a = sorted(a)
			ans = sorted_a == a
		else:
			ans = True
		print('Yes' if ans else 'No')
B()


MOD = 1000000007
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
ls = lambda : list(input())
from collections import *
for _ in range(ii()):
	n = ii()
	a = il()
	b = il()
	k = []
	c = 0
	for i in range(0, n):
		k.append(a[i])
	k.sort()
	for i in range(0, n):
		if a[i] == k[i]:
			c = c + 1
	if n == 1:
		print('Yes')
	elif c == n:
		print('Yes')
	elif b.count(1) >= 1 and b.count(0) >= 1:
		print('Yes')
	else:
		print('No')


import math

def DenTofieM():
	for _ in range(int(input())):
		sz = int(input())
		ar = list(map(int, input().split()))
		br = list(map(int, input().split()))
		change = True
		for i in range(1, sz):
			if ar[i - 1] > ar[i]:
				change = False
				break
		zero = one = 0
		for i in range(sz):
			if br[i] & 1:
				one += 1
			else:
				zero += 1
		if change or (zero and one):
			print('Yes')
		else:
			print('No')
DenTofieM()


from sys import stdin
inp = lambda : stdin.readline().strip()
n = int(inp())
for i in range(1, n + 1):
	n = int(inp())
	a = [int(x) for x in inp().split()]
	b = [int(x) for x in inp().split()]
	if len(set(b)) > 1:
		print('YES')
	elif a == sorted(a):
		print('yes')
	else:
		print('no')


def solve():
	n = int(input())
	la = list(map(int, input().split()))
	lb = list(map(int, input().split()))
	ordem = True
	for i in range(0, n - 1):
		if la[i] > la[i + 1]:
			ordem = False
	if ordem:
		print('Yes')
		return
	(zero, um) = (False, False)
	for i in lb:
		if i:
			um = True
		else:
			zero = True
	if zero and um:
		print('Yes')
	else:
		print('No')

def main():
	t = int(input())
	for i in range(0, t):
		solve()
main()


def factorise(m):
	ans = []
	p = 2
	while m != 1:
		if m % p != 0:
			p += 1
			continue
		e = 0
		while m % p == 0:
			m //= p
			e += 1
		ans.append([p, e])
		p += 1
	return ans

def mulmod(a, b, c):
	result = a * b
	if result >= c:
		result %= c
	return result

def mod_inverse(a, n):
	N = n
	xx = 0
	yy = 1
	y = 0
	x = 1
	while n > 0:
		q = a // n
		t = n
		n = a % n
		a = t
		t = xx
		xx = x - q * xx
		x = t
		t = yy
		yy = y - q * yy
		y = t
	x %= N
	x += N
	x %= N
	return x

def expo(a, b):
	x = 1
	y = a
	while b > 0:
		if b & 1:
			x = x * y
		y = y * y
		b >>= 1
	return x

def power(a, b, c):
	x = 1
	y = a
	while b > 0:
		if b & 1:
			x = mulmod(x, y, c)
		y = mulmod(y, y, c)
		b >>= 1
	return x

def init(p, pk):
	fact = []
	fact.append(1)
	for i in range(1, pk):
		red = i
		if red % p == 0:
			red = 1
		fact.append(mulmod(fact[i - 1], red, pk))
	return fact

def fact_mod(n, p, pk, fact):
	result = 1
	while n > 0:
		tame = n // pk
		result = mulmod(result, power(fact[pk - 1], tame, pk), pk)
		result = mulmod(result, fact[n % pk], pk)
		n //= p
	return result

def count_fact(n, p):
	ans = 0
	while n > 0:
		ans += n // p
		n //= p
	return ans

def ncr_pk(n, r, p, e):
	if r > n or r < 0:
		return 0
	if r == 0 or n == r:
		return 1
	_e = count_fact(n, p) - count_fact(r, p) - count_fact(n - r, p)
	assert _e >= 0
	if _e >= e:
		return 0
	pk = expo(p, e)
	fact = init(p, pk)
	ans = fact_mod(n, p, pk, fact)
	ans = mulmod(ans, mod_inverse(fact_mod(r, p, pk, fact), pk), pk)
	ans = mulmod(ans, mod_inverse(fact_mod(n - r, p, pk, fact), pk), pk)
	ans = mulmod(ans, expo(p, _e), pk)
	return ans

def pre_process(rem, mods):
	crt = []
	a = 1
	b = 1
	m = mods[0]
	crt.append([mods[0], a, b])
	L = len(mods)
	for i in range(1, L):
		a = mod_inverse(m, mods[i])
		b = mod_inverse(mods[i], m)
		crt.append([m, a, b])
		m *= mods[i]
	assert len(crt) == len(mods)
	return crt

def find_crt(rem, mods, crt):
	assert len(crt) == len(mods)
	ans = rem[0]
	m = crt[0][0]
	L = len(mods)
	for i in range(1, L):
		a = crt[i][1]
		b = crt[i][2]
		m = crt[i][0]
		_m = m * mods[i]
		ans = mulmod(ans, b * mods[i], _m)
		ans = (ans + mulmod(rem[i], a * m, _m)) % _m
	return ans

def ncr(n, r, m):
	pf = factorise(m)
	rem = []
	mods = []
	L = len(pf)
	for i in range(L):
		get = ncr_pk(n, r, pf[i][0], pf[i][1])
		rem.append(get)
		mods.append(expo(pf[i][0], pf[i][1]))
	crt = pre_process(rem, mods)
	ans = find_crt(rem, mods, crt)
	return ans

def add(a, b, c):
	result = a + b
	if result >= c:
		return result - c
	else:
		return result

def mod(a, b, c):
	result = a * b
	if result >= c:
		return result % c
	else:
		return result

def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a

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

def expo(a, b):
	(x, y) = (1, a)
	while b > 0:
		if b & 1:
			x = x * y
		y = y * y
		b >>= 1
	return x

def power(a, b, m):
	(x, y) = (1,)
	while b > 0:
		if b & 1:
			x = mod(x, y, m)
		y = mod(y, y, m)
		b >>= 1
	return x

def inv(a, m):
	return power(a, m - 2, m)

def mod_inverse(a, n):
	N = n
	xx = 0
	yy = 1
	y = 0
	x = 1
	while n > 0:
		q = a // n
		t = n
		n = a % n
		a = t
		t = xx
		xx = x - q * xx
		x = t
		t = yy
		yy = y - q * yy
		y = t
	x %= N
	x += N
	x %= N
	return x
import random

def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a

def expo(a, b):
	(x, y) = (1, a)
	while b > 0:
		if b & 1:
			x = x * y
		y = y * y
		b >>= 1
	return x
primes = [0] * 100000

def sieve():
	primes[1] = 1
	primes[2] = 2
	j = 4
	while j < 100000:
		primes[j] = 2
		j += 2
	j = 3
	while j < 100000:
		if primes[j] == 0:
			primes[j] = j
			i = j * j
			k = j << 1
			while i < 100000:
				primes[i] = j
				i += k
		j += 2

def rabin_miller(p):
	if p < 100000:
		return primes[p] == p
	if p % 2 == 0:
		return False
	s = p - 1
	while s % 2 == 0:
		s >>= 1
	for i in range(5):
		a = random.randrange(p - 1) + 1
		temp = s
		mod = pow(a, temp, p)
		while temp != p - 1 and mod != 1 and (mod != p - 1):
			mod = mod * mod % p
			temp = temp * 2
		if mod != p - 1 and temp % 2 == 0:
			return False
	return True

def brent(N):
	if N % 2 == 0:
		return 2
	if N < 100000:
		return primes[N]
	(y, c, m) = (random.randint(1, N - 1), random.randint(1, N - 1), random.randint(1, N - 1))
	(g, r, q) = (1, 1, 1)
	while g == 1:
		x = y
		for i in range(r):
			y = (y * y % N + c) % N
		k = 0
		while k < r and g == 1:
			ys = y
			for i in range(min(m, r - k)):
				y = (y * y % N + c) % N
				q = q * abs(x - y) % N
			g = gcd(q, N)
			k = k + m
		r = r * 2
	if g == N:
		while True:
			ys = (ys * ys % N + c) % N
			g = gcd(abs(x - ys), N)
			if g > 1:
				break
	return g

def sieve():
	t = int(input())
	for _ in range(t):
		n = int(input())
		L = factorise(n)
		L.sort()
		i = 0
		while i < len(L):
			cnt = L.count(L[i])
			(print('%s^%s' % (L[i], cnt)),)
			i += cnt
		print

def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a

def mod_inverse(a, n):
	N = n
	xx = 0
	yy = 1
	y = 0
	x = 1
	while n > 0:
		q = a // n
		t = n
		n = a % n
		a = t
		t = xx
		xx = x - q * xx
		x = t
		t = yy
		yy = y - q * yy
		y = t
	x %= N
	x += N
	x %= N
	return x
primes = [0] * 1000000

def sieve():
	primes[1] = 1
	primes[2] = 2
	j = 4
	while j < 1000000:
		primes[j] = 2
		j += 2
	j = 3
	while j < 1000000:
		if primes[j] == 0:
			primes[j] = j
			i = j * j
			k = j << 1
			while i < 1000000:
				primes[i] = j
				i += k
		j += 2
from random import *
import time

def ilog2(n):
	return 0 if n <= 0 else n.bit_length() - 1

def pack(pack, shamt):
	size = len(pack)
	while size > 1:
		npack = []
		for i in range(0, size - 1, 2):
			npack += [pack[i] | pack[i + 1] << shamt]
		if size & 1:
			npack += [pack[-1]]
		(pack, size, shamt) = (npack, size + 1 >> 1, shamt << 1)
	return pack[0]

def unpack(M, size, shamt):
	(s, sizes) = (size, [])
	while s > 1:
		sizes += [s]
		s = s + 1 >> 1
	ret = [M]
	for size in sizes[::-1]:
		(mask, nret) = ((1 << shamt) - 1, [])
		for c in ret:
			nret += [c & mask, c >> shamt]
		(ret, shamt) = (nret[:size], shamt >> 1)
	return ret

def poly_mul(f, g, mod=1000000007):
	size = min(len(f), len(g))
	shift = ((mod - 1) ** 2 * size).bit_length()
	rsize = len(f) + len(g) - 1
	h = unpack(pack(f, shift) * pack(g, shift), rsize, shift * (1 << ilog2(rsize - 1)))
	return [int(x % mod) for x in h]
for cas in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	flag = True
	binary = True
	for i in range(n - 1):
		if a[i] <= a[i + 1]:
			pass
		else:
			flag = False
		if b[i] != b[i + 1]:
			binary = False
	if flag:
		print('Yes')
		continue
	if not binary:
		print('Yes')
	else:
		print('No')


import sys
input = lambda : sys.stdin.readline().strip()
t = int(input())
while t:
	t -= 1
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if a == list(sorted(a)):
		print('Yes')
		continue
	if b.count(1) == 0 or b.count(0) == 0:
		print('No')
	else:
		print('Yes')


import sys
for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	tmp = sorted(a)
	if b == [1] * n or b == [0] * n:
		print('YES') if a == tmp else print('NO')
	else:
		print('YES')


t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	b = set(b)
	if len(b) == 2:
		print('Yes')
	elif a == sorted(a):
		print('Yes')
	else:
		print('No')


t = int(input())
while t:
	t -= 1
	n = int(input())
	array = [[0, 0] for x in range(n)]
	for i in range(2):
		tem = list(map(int, input().split()))
		for y in range(n):
			array[y][i] = tem[y]
	ck = array[0][1]
	ok = False
	for i in range(1, n, 1):
		if array[i][1] != ck:
			print('YES')
			ok = True
			break
	if ok:
		continue
	for i in range(1, n, 1):
		if array[i][0] < array[i - 1][0]:
			print('NO')
			ok = True
			break
	if ok == False:
		print('YES')


import sys, os
import math
from fractions import Fraction

def linput():
	return list(minput())

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

def main():
	n = minput()
	a = linput()
	b = linput()
	c = list(a)
	c.sort()
	if a == c:
		return 'Yes'
	(x, y) = (0, 0)
	for i in b:
		if i == 0:
			x += 1
		else:
			y += 1
	if x != 0 and y != 0:
		return 'Yes'
	else:
		return 'No'
tc = int(input())
while tc != 0:
	tc -= 1
	print(main())


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	is_sorted = True
	zeroes = 0
	ones = 0
	if b[0] == 1:
		ones += 1
	else:
		zeroes += 1
	for i in range(1, n):
		if a[i] < a[i - 1]:
			is_sorted = False
		if b[i] == 1:
			ones += 1
		else:
			zeroes += 1
	if is_sorted or (ones >= 1 and zeroes >= 1):
		print('YES')
	else:
		print('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')
testcases = int(input())
for j in range(testcases):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	broke = False
	for s in range(1, n):
		if a[s - 1] > a[s]:
			broke = True
			break
	if len(set(b)) == 2 or broke == False:
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.buffer.readline
t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	isSorted = True
	for i in range(n - 1):
		if a[i] > a[i + 1]:
			isSorted = False
			break
	if isSorted:
		print('Yes')
	elif len(set(b)) == 1:
		print('No')
	else:
		print('Yes')


t = int(input())
for i in range(t):
	n = int(input())
	arr1 = list((int(x) for x in input().split()))
	arr2 = list((int(x) for x in input().split()))

	def fun(arr1, arr2):
		if len(set(arr2)) > 1:
			return 1
		if arr1 == sorted(arr1):
			return 1
		else:
			return 0
	if fun(arr1, arr2) == 1:
		print('Yes')
	else:
		print('No')


import math
from decimal import *
getcontext().prec = 30
t = int(input())
while t:
	t -= 1
	n = int(input())
	l = list(map(int, input().split()))
	a = list(map(int, input().split()))
	if a.count(0) and a.count(1):
		print('Yes')
	else:
		b = sorted(l)
		if b == l:
			print('Yes')
		else:
			print('No')


for k in range(int(input())):
	a = int(input())
	t = list(map(int, input().split()))
	g = list(map(int, input().split()))
	f = []
	for k in range(a):
		f.append([t[k], g[k]])
	f.sort()
	u = 0
	for s in range(a):
		if f[s][0] == t[s]:
			pass
		else:
			u += 1
	if u == 0:
		print('Yes')
	elif len(set(g)) == 1:
		print('No')
	else:
		print('Yes')


def issort(l1):
	for i in range(1, len(l1)):
		if l1[i] < l1[i - 1]:
			return False
	return True
for _ in range(int(input())):
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	if issort(l1):
		print('Yes')
		continue
	if sum(l2) == 0 or sum(l2) == n:
		print('No')
	else:
		print('Yes')


for i in range(int(input())):
	a = int(input())
	t = list(map(int, input().split()))
	s = list(map(int, input().split()))
	if len(set(s)) == 2:
		print('Yes')
	else:
		h = 0
		if a == 1:
			print('Yes')
		else:
			for k in range(a - 1):
				if t[k + 1] < t[k]:
					h += 1
					break
			if h > 0:
				print('No')
			else:
				print('Yes')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = set(map(int, input().split()))
	if len(b) == 2:
		print('Yes')
	else:
		prev = 0
		valid = True
		for i in a:
			if prev > i:
				valid = False
				break
			prev = i
		print('Yes') if valid else print('No')


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	g = all([i == 1 for i in b])
	h = all([i == 0 for i in b])
	flag = 0
	if g or h:
		y = a.copy()
		a.sort()
		if a != y:
			print('No')
			flag = 1
	if flag == 0:
		print('Yes')


import sys
input = sys.stdin.readline
import heapq
import copy
import math

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

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

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

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

class Node:

	def _init_(self, val):
		self.data = val
		self.left = None
		self.right = None

def pre_sum(arr):
	p = [0]
	for i in arr:
		p.append(p[-1] + i)
	p.pop(0)
	return p

def pre_back(arr):
	p = [0]
	for i in arr:
		p.append(p[-1] + i)
	p.pop(0)
	return p

def bin_search(arr, l, r, val):
	if arr[r] <= val:
		return r + 1
	if r - l < 2:
		if arr[l] > val:
			return l
		else:
			return r
	mid = int((l + r) / 2)
	if arr[mid] <= val:
		return bin_search(arr, mid, r, val)
	else:
		return bin_search(arr, l, mid, val)

def search_leftmost(arr, val):

	def helper(arr, l, r, val):
		print(l, r)
		if arr[l] == val:
			return l
		if r - l <= 1:
			if arr[r] == val:
				return r
			else:
				print('not found')
				return
		mid = int((r + l) / 2)
		if arr[mid] >= val:
			return helper(arr, l, mid, val)
		else:
			return helper(arr, mid, r, val)
	return helper(arr, 0, len(arr) - 1, val)

def search_rightmost(arr, val):

	def helper(arr, l, r, val):
		print(l, r)
		if arr[r] == val:
			return r
		if r - l <= 1:
			if arr[l] == val:
				return r
			else:
				print('not found')
				return
		mid = int((r + l) / 2)
		if arr[mid] > val:
			return helper(arr, l, mid, val)
		else:
			return helper(arr, mid, r, val)
	return helper(arr, 0, len(arr) - 1, val)

def pr_list(a):
	print(*a, sep=' ')

def main():
	tests = inp()
	mod = 1000000007
	limit = 10 ** 18
	for test in range(tests):
		n = inp()
		a = inlt()
		b = inlt()
		if sum(b) != n and sum(b) != 0:
			print('Yes')
		else:
			flag = 0
			for i in range(1, n):
				if a[i] < a[i - 1]:
					flag = 1
					break
			if flag == 1:
				print('No')
			else:
				print('Yes')
main()


def solve():
	n = int(input())
	mas = [int(s) for s in input().split()]
	bin = [int(s) for s in input().split()]
	mas1 = mas.copy()
	if bin.count(1) == 0 or bin.count(1) == n:
		mas1.sort()
		if mas1 == mas:
			print('Yes')
			return
		else:
			print('No')
			return
	print('Yes')
for _ in range(int(input())):
	solve()


t = int(input())
for hh in range(0, t):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	s = sum(b)
	if s == n or s == 0:
		if sorted(a) == a:
			print('Yes')
		else:
			print('No')
	else:
		print('Yes')


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	x = sum(b)
	z = a.copy()
	a.sort()
	if x == 0 or x == n:
		if a == z:
			print('Yes')
		else:
			print('No')
	else:
		print('Yes')


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	in_order = True
	for i in range(n):
		if i > 0:
			if a[i - 1] > a[i]:
				in_order = False
	a = list(map(int, input().split()))
	has_0 = False
	has_1 = False
	for i in range(n):
		if a[i] == 0:
			has_0 = True
		if a[i] == 1:
			has_1 = True
	solved = has_1 and has_0 or in_order
	if solved:
		print('Yes')
	else:
		print('No')


t = int(input())
i = 0
while i < t:
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	r = False
	rows = sorted(a)
	if rows == a:
		print('Yes')
	else:
		c = b.count(1)
		d = b.count(0)
		if c >= 1 and d >= 1:
			print('Yes')
		else:
			print('No')
	i = i + 1


t = int(input())
for test in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	flag = True
	for i in range(n - 1):
		if a[i + 1] < a[i]:
			flag = False
			break
	if flag:
		print('Yes')
	else:
		ones = 0
		zeros = 0
		for i in range(n):
			if b[i] == 0:
				zeros += 1
			else:
				ones += 1
		if ones and zeros:
			print('Yes')
		else:
			print('No')


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	l = b.count(b[0])
	if l == n:
		p = 0
		for i in range(n - 1):
			if a[i + 1] < a[i]:
				p += 1
		if p == 0:
			print('YES')
		else:
			print('NO')
	else:
		print('YES')


MOD = 10 ** 9 + 7
INT_MAX = 10 ** 20 + 7

def INPUT():
	return list((int(i) for i in input().split()))

def LIST_1D_ARRAY(n):
	return [0 for _ in range(n)]

def LIST_2D_ARRAY(m, n):
	return [[0 for _ in range(n)] for _ in range(m)]

def power(a, x):
	res = 1
	while x > 0:
		if x & 1:
			res = res * a % MOD
		a = a * a % MOD
		x //= 2
	return res % MOD

def NCR_MOD(n, r):
	num = 1
	for i in range(n, n - r, -1):
		num = num * i % MOD
	for j in range(1, r + 1):
		num = num * power(j, MOD - 2) % MOD
	return num
import math
from collections import deque

def calc(n, val, type):
	x = LIST_1D_ARRAY(n)
	for i in range(n):
		x[i] = val[i]
	x.sort()
	if x == val:
		return True
	sum = 0
	for i in range(n):
		sum += type[i]
	if sum == 0 or sum == n:
		return False
	return True
for i in range(int(input())):
	n = int(input())
	val = INPUT()
	type = INPUT()
	if calc(n, val, type):
		print('YES')
	else:
		print('NO')
	print()