You are given an array of integers $a$ of length $n$. The elements of the array can be either different or the same.

Each element of the array is colored either blue or red. There are no unpainted elements in the array. One of the two operations described below can be applied to an array in a single step:

either you can select any blue element and decrease its value by $1$;

or you can select any red element and increase its value by $1$.

Situations in which there are no elements of some color at all are also possible. For example, if the whole array is colored blue or red, one of the operations becomes unavailable.

Determine whether it is possible to make $0$ or more steps such that the resulting array is a permutation of numbers from $1$ to $n$?

In other words, check whether there exists a sequence of steps (possibly empty) such that after applying it, the array $a$ contains in some order all numbers from $1$ to $n$ (inclusive), each exactly once.


-----Input-----

The first line contains an integer $t$ ($1 \leq t \leq 10^4$) — the number of input data sets in the test.

The description of each set of input data consists of three lines. The first line contains an integer $n$ ($1 \leq n \leq 2 \cdot 10^5$) — the length of the original array $a$. The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ ($-10^9 \leq a_i \leq 10^9$) — the array elements themselves.

The third line has length $n$ and consists exclusively of the letters 'B' and/or 'R': $i$th character is 'B' if $a_i$ is colored blue, and is 'R' if colored red.

It is guaranteed that the sum of $n$ over all input sets does not exceed $2 \cdot 10^5$.


-----Output-----

Print $t$ lines, each of which contains the answer to the corresponding test case of the input. Print YES as an answer if the corresponding array can be transformed into a permutation, and NO otherwise.

You can print the answer in any case (for example, the strings yEs, yes, Yes, and YES will be recognized as a positive answer).


-----Examples-----

Input
8
4
1 2 5 2
BRBR
2
1 1
BB
5
3 1 4 2 5
RBRRB
5
3 1 3 1 3
RBRRB
5
5 1 5 1 5
RBRRB
4
2 2 2 2
BRBR
2
1 -2
BR
4
-2 -1 4 0
RRRR
Output
YES
NO
YES
YES
NO
YES
YES
YES


-----Note-----

In the first test case of the example, the following sequence of moves can be performed:

choose $i=3$, element $a_3=5$ is blue, so we decrease it, we get $a=[1,2,4,2]$;

choose $i=2$, element $a_2=2$ is red, so we increase it, we get $a=[1,3,4,2]$;

choose $i=3$, element $a_3=4$ is blue, so we decrease it, we get $a=[1,3,3,2]$;

choose $i=2$, element $a_2=2$ is red, so we increase it, we get $a=[1,4,3,2]$.

We got that $a$ is a permutation. Hence the answer is YES.

Source: codeforces | Difficulty: EASY
Tags: Sorting

Mathematics

Greedy algorithms


Solutions:
import sys
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

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

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

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

def LI1():
	return list(map(int1, sys.stdin.readline().split()))

def LLI1(rows_number):
	return [LI1() for _ in range(rows_number)]

def SI():
	return sys.stdin.readline().rstrip()
inf = 4294967295
md = 998244353
from heapq import *

def solve():
	n = II()
	aa = LI1()
	cc = [c == 'R' for c in SI()]
	lr = []
	for (a, c) in zip(aa, cc):
		if c:
			lr.append((a, n))
		else:
			lr.append((0, a + 1))
	lr.sort(key=lambda x: -x[0])
	hp = []
	for i in range(n):
		while lr and lr[-1][0] <= i:
			(l, r) = lr.pop()
			heappush(hp, r)
		if not hp:
			print('NO')
			return
		r = heappop(hp)
		if i >= r:
			print('NO')
			return
	print('YES')
for testcase in range(II()):
	solve()


import sys
import os
import math
import bisect
from collections import *
import heapq
from sys import stdin, stdout
from math import gcd, floor, sqrt, log
from collections import defaultdict as dd
from bisect import bisect_left as bl, bisect_right as br
from itertools import *
from functools import *
import random
sys.setrecursionlimit(100000000)
inp = lambda : int(input())
strng = lambda : input().strip()
jn = lambda x, l: x.join(map(str, l))
strl = lambda : list(input().strip())
mul = lambda : map(int, input().strip().split())
mulf = lambda : map(float, input().strip().split())
seq = lambda : list(map(int, input().strip().split()))
ceil = lambda x: int(x) if x == int(x) else int(x) + 1
ceildiv = lambda x, d: x // d if x % d == 0 else x // d + 1
flush = lambda : stdout.flush()
stdstr = lambda : stdin.readline()
stdint = lambda : int(stdin.readline())
stdpr = lambda x: stdout.write(str(x))
INF = float('inf')
MOD = 1000000007
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 solve():
	n = inp()
	arr = seq()
	s = input()
	b = []
	r = []
	for i in range(n):
		if s[i] == 'B':
			b.append(arr[i])
		else:
			r.append(arr[i])
	b.sort()
	r.sort(reverse=True)
	for i in range(len(b)):
		if b[i] < i + 1:
			print('NO')
			return
	for i in range(len(r)):
		if r[i] > n - i:
			print('NO')
			return
	print('YES')
t = 1
t = inp()
for _ in range(t):
	solve()


import sys
from bisect import bisect_left as lb
from bisect import bisect_right as rb
from collections import deque
from queue import PriorityQueue as pq
from math import gcd
input_ = lambda : sys.stdin.readline().strip('\r\n')
ii = lambda : int(input_())
il = lambda : list(map(int, input_().split()))
ilf = lambda : list(map(float, input_().split()))
lii = lambda : list(map(int, list(ip())))
ip = lambda : input_()
fi = lambda : float(input_())
ap = lambda ab, bc, cd: ab[bc].append(cd)
li = lambda : list(input_())
pr = lambda x: print(x)
prinT = lambda x: print(x)
f = lambda : sys.stdout.flush()
inv = lambda x: pow(x, mod - 2, mod)
mod = 10 ** 9 + 7
mod1 = 998244353
for _ in range(ii()):
	n = ii()
	a = il()
	s = list(ip())
	b = []
	c = []
	for i in range(n):
		if s[i] == 'B':
			b.append(a[i])
		else:
			c.append(a[i])
	p = 1
	fl = 1
	b.sort()
	c.sort()
	for i in b:
		if p <= i:
			p += 1
			continue
		else:
			fl = 0
			break
	if fl == 0:
		print('NO')
		continue
	for i in c:
		if p >= i:
			p += 1
		else:
			fl = 0
			break
	if fl:
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.readline

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

def st():
	return input().rstrip('\n')

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

def ma():
	return map(int, input().split())
t = inp()
while t:
	t -= 1
	n = inp()
	a = lis()
	s = st()
	ra = []
	for i in range(n):
		if s[i] == 'B':
			if a[i] <= 0:
				continue
			r = min(n, a[i])
			ra.append([1, r])
		else:
			if a[i] > n:
				continue
			l = max(1, a[i])
			ra.append([l, n])
	if len(ra) != n:
		print('NO')
		continue
	ra.sort()
	po = 1
	fl = 0
	for i in range(n):
		if po >= ra[i][0] and po <= ra[i][1]:
			po += 1
		else:
			fl = 1
	if fl:
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	s = input()
	b = []
	r = []
	ans = True
	for i in range(n):
		if s[i] == 'B':
			b.append(arr[i])
		else:
			r.append(arr[i])
	b.sort()
	r.sort(reverse=True)
	for i in range(len(b)):
		if b[i] <= i:
			ans = False
			break
	for i in range(len(r)):
		if r[i] > n - i:
			ans = False
			break
	if ans:
		print('YES')
	else:
		print('NO')


import sys

def solve():
	T = int(sys.stdin.readline().rstrip())
	for _ in range(T):
		N = int(sys.stdin.readline().rstrip())
		S = list(map(int, sys.stdin.readline().rstrip().split(' ')))
		directions = sys.stdin.readline().rstrip()
		R = []
		B = []
		for i in range(N):
			if directions[i] == 'R':
				R.append(S[i])
			else:
				B.append(S[i])
		R.sort(reverse=True)
		B.sort()
		answer = 'YES'
		for i in range(len(B)):
			if i + 1 > B[i]:
				answer = 'NO'
				break
		for i in range(len(R)):
			if N - i < R[i]:
				answer = 'NO'
				break
		print(answer)
solve()


def blue_red(n, arr, clr):
	Reds = []
	Blues = []
	for i in range(n):
		if clr[i] == 'R':
			Reds.append(arr[i])
		if clr[i] == 'B':
			Blues.append(arr[i])
	Reds.sort()
	Blues.sort()
	for i in range(len(Reds)):
		if Reds[i] > n - len(Reds) + i + 1:
			return 'NO'
	for i in range(len(Blues)):
		if Blues[i] < i + 1:
			return 'NO'
	return 'YES'
t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	clr = str(input())
	print(blue_red(n, arr, clr))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	s = list(input())
	test = 0
	blues = [a[i] for i in range(n) if s[i] == 'B']
	reds = [a[i] for i in range(n) if s[i] == 'R']
	blues.sort()
	reds.sort()
	for i in range(len(blues)):
		if blues[i] < i + 1:
			test = 1
			break
	if test:
		print('NO')
	else:
		x = len(blues)
		for i in range(len(reds)):
			if reds[i] > x + i + 1:
				test = 1
				break
		if test:
			print('NO')
		else:
			print('YES')


for i in range(int(input())):
	n = int(input())
	a = [int(num) for num in input().split()]
	c = input()
	B = []
	R = []
	for j in range(n):
		if c[j] == 'B':
			B.append(a[j])
		else:
			R.append(a[j])
	R.sort()
	B.sort()
	result = True
	for j in range(len(B)):
		if B[j] < j + 1:
			result = False
			break
	for j in range(len(R)):
		if R[j] > len(B) + j + 1:
			result = False
			break
	if result:
		print('YES')
	else:
		print('NO')


t = int(input())
for asd in range(t):
	n = int(input())
	l = [int(i) for i in input().split()]
	rb = input()
	r = []
	b = []
	for i in range(n):
		if rb[i] == 'R':
			r.append(l[i])
		else:
			b.append(l[i])
	b = sorted(b)
	r = sorted(r, reverse=True)
	flag = 1
	for i in range(len(b)):
		if b[i] < i + 1:
			flag = 0
			break
	for i in range(len(r)):
		if r[i] > n - i:
			flag = 0
			break
	if flag:
		print('YES')
	else:
		print('NO')


t = int(input())
for inputIndex in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	c = list(input())
	b = sorted(list(zip(c, a)))
	i = 0
	isRun = True
	while i < n and isRun:
		if b[i][0] == 'B':
			if not b[i][1] >= i + 1:
				isRun = False
		elif not b[i][1] <= i + 1:
			isRun = False
		i += 1
	print('YES' if isRun else 'NO')


from collections import defaultdict
t = int(input())
for j in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	s = input()
	(b, r) = ([], [])
	for i in range(n):
		if s[i] == 'B':
			b.append(a[i])
		else:
			r.append(a[i])
	b.sort()
	r.sort()
	f = 0
	for i in range(len(b)):
		if b[i] < i + 1:
			f = 1
			break
	for i in range(len(r)):
		if r[i] > len(b) + i + 1:
			f = 1
			break
	print('YES' if f == 0 else 'NO')


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	s = input()
	b = []
	r = []
	for i in range(n):
		if s[i] == 'R':
			r.append(l[i])
		else:
			b.append(l[i])
	b = sorted(b)
	r = sorted(r)[::-1]
	ok = True
	for i in range(len(b)):
		if b[i] < i + 1:
			ok = False
	for i in range(len(r)):
		if r[i] > n - i:
			ok = False
	print('YES') if ok else print('NO')


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	c = list(input())
	up = []
	down = []
	for i in range(n):
		if c[i] == 'B':
			down.append(a[i])
		else:
			up.append(a[i])
	up.sort()
	down.sort()
	flag = False
	i = j = 0
	k = 1
	while i < len(up) and j < len(down):
		if down[j] >= k:
			j += 1
			k += 1
		elif up[i] <= k:
			i += 1
			k += 1
		else:
			flag = True
			break
	if flag:
		print('NO')
		continue
	while i < len(up):
		if up[i] <= k:
			i += 1
			k += 1
		else:
			flag = True
			break
	if flag:
		print('NO')
		continue
	while j < len(down):
		if down[j] >= k:
			j += 1
			k += 1
		else:
			flag = True
			break
	if flag:
		print('NO')
	else:
		print('YES')


def prove(blue, red):
	for i in range(1, len(blue) + 1):
		if i > blue[i - 1]:
			print('NO')
			return
	for i in range(len(blue) + 1, size + 1):
		if i < red[i - len(blue) - 1]:
			print('NO')
			return
	print('YES')
	return
n = int(input())
for i in range(n):
	size = int(input())
	l = list(map(int, input().strip().split()))
	colors = str(input())
	red = []
	blue = []
	for i in range(size):
		if colors[i] == 'B':
			blue.append(l[i])
		else:
			red.append(l[i])
	blue.sort()
	red.sort()
	prove(blue, red)


I = lambda : map(int, input().split())
for _ in [0] * int(input()):
	n = int(input())
	b = []
	r = []
	ff = 1
	for (i, j) in zip(I(), input()):
		if j == 'R':
			r.append(i)
		else:
			b.append(i)
	k = n
	for i in sorted(r, reverse=1):
		if i > k:
			ff = 0
			break
		k = k - 1
	else:
		k = 1
		for i in sorted(b):
			if i < k:
				ff = 0
				break
			k = k + 1
	print('YNEOS'[int(ff == 0)::2])


arr = [1, 2, 5, 2]
s = 'BRBR'

def answer(arr, s):
	from collections import defaultdict
	curr = defaultdict(list)
	dic = {}
	blue = 0
	b = []
	red = 0
	r = []
	for i in range(len(arr)):
		if s[i] == 'B':
			blue += 1
			b.append(arr[i])
		else:
			red += 1
			r.append(arr[i])
	b.sort()
	r.sort(reverse=True)
	count = 1
	for i in b:
		if i >= count:
			count += 1
		else:
			return 'NO'
	count = len(arr)
	for i in r:
		if i <= count:
			count -= 1
		else:
			return 'NO'
	return 'YES'
t = int(input())
for k in range(t):
	num = int(input())
	inp = input().split()
	arr = []
	for i in inp:
		arr.append(int(i))
	s = input()
	print(answer(arr, s))


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	s = input()
	l1 = []
	l2 = []
	for j in range(n):
		if s[j] == 'B':
			l1.append(a[j])
		else:
			l2.append(a[j])
	l1.sort()
	l2.sort()
	flag = True
	for j in range(len(l1)):
		if l1[j] >= j + 1:
			continue
		else:
			flag = False
			break
	for j in range(len(l2)):
		if l2[j] <= len(l1) + j + 1:
			continue
		else:
			flag = False
			break
	if flag == True:
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	a = map(int, input().split())
	c = input()
	(blue, red) = ([], [])
	for (i, x) in enumerate(a):
		if c[i] == 'B':
			blue.append(x)
		else:
			red.append(x)
	blue.sort()
	red.sort()
	b = len(blue)
	for i in range(b - 2, -1, -1):
		blue[i] = min(blue[i], blue[i + 1] - 1)
	r = len(red)
	(bi, ri) = (0, 0)
	ans = 'YES'
	for x in range(1, n + 1):
		if bi < b and x <= blue[bi]:
			bi += 1
		elif ri < r and x >= red[ri]:
			ri += 1
		else:
			ans = 'NO'
	print(ans)


from sys import stdin
t = int(stdin.readline())
for _ in range(t):
	stdin.readline()
	numbers = [int(d) for d in stdin.readline().strip().split()]
	colors = stdin.readline().strip()
	numbers = zip(colors, numbers)
	numbers = sorted(numbers)
	current = 1
	result = True
	for n in numbers:
		if n[0] == 'B' and n[1] < current:
			result = False
		if n[0] == 'R' and n[1] > current:
			result = False
		current += 1
	print('YES' if result else 'NO')


t = int(input())

def solve():
	n = int(input())
	nums = list(map(int, input().split()))
	color = list(input())
	redNums = []
	blueNums = []
	for i in range(n):
		if color[i] == 'R':
			redNums.append(nums[i])
		else:
			blueNums.append(nums[i])
	redNums.sort()
	blueNums.sort()
	for (idx, val) in enumerate(blueNums):
		if val < idx + 1:
			print('NO')
			return
	for (idx, val) in enumerate(redNums):
		if val > idx + len(blueNums) + 1:
			print('NO')
			return
	print('YES')
	return
for i in range(t):
	solve()


from __future__ import print_function
from math import *
from collections import deque
import os
import sys
from io import BytesIO, IOBase

def main():
	pass
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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

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

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

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

def invr():
	return map(int, input().split())
for _ in range(inp()):
	n = inp()
	l = inlt()
	m = input()
	rd = []
	bd = []
	s = set()
	for i in range(n):
		if l[i] not in s:
			s.add(l[i])
	for i in range(n):
		if m[i] == 'B':
			bd.append(l[i])
		else:
			rd.append(l[i])
	f = 1
	bd.sort(reverse=1)
	rd.sort(reverse=1)
	bp = len(bd) - 1
	rp = len(rd) - 1
	for i in range(n):
		tf = 0
		if bp >= 0:
			if i + 1 <= bd[bp]:
				bp -= 1
				tf = 1
		if tf == 0:
			if rp >= 0:
				if i + 1 >= rd[rp]:
					rp -= 1
					tf = 1
		if tf == 0:
			f = 0
			break
	if f:
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	a = [int(ai) for ai in input().split()]
	colors = [char for char in input().strip()]
	red = []
	blue = []
	for (ai, color) in zip(a, colors):
		if color == 'R':
			red.append(ai)
		else:
			blue.append(ai)
	flag = 1
	red.sort()
	for ind in range(len(red) - 1, -1, -1):
		if red[ind] > n:
			flag = 0
		n -= 1
	m = 1
	blue.sort()
	for ind in range(len(blue)):
		if blue[ind] < m:
			flag = 0
		m += 1
	print('YES' if flag else 'NO')


t = int(input())
for i in range(t):
	n = int(input())
	A = list(map(int, input().split(' ')))
	C = list(input())
	if [j + 1 for j in range(n)] == sorted(A):
		print('YES')
	else:
		res = 0
		B_color = []
		R_color = []
		for j in range(n):
			if C[j] == 'B':
				B_color.append(A[j])
			else:
				R_color.append(A[j])
		B_color.sort()
		R_color.sort(reverse=True)
		if R_color:
			for (j, r) in enumerate(R_color):
				if r > n - j:
					res += 1
					break
		if B_color:
			for (j, b) in enumerate(B_color):
				if b < j + 1:
					res += 1
					break
		if res == 0:
			print('YES')
		else:
			print('NO')


import os
import sys
from math import *
from bisect import *
from io import BytesIO, IOBase
from typing import overload

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')
ALPHA = 'abcdefghijklmnopqrstuvwxyz'
M = int(1000000000.0 + 7)
EPS = 1e-06

def Ceil(a, b):
	return a // b + int(a % b > 0)

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()
	col = input()
	blue = []
	red = []
	for i in range(n):
		if col[i] == 'B':
			blue.append(a[i])
		else:
			red.append(a[i])
	blue.sort()
	red.sort()
	ok = 'YES'
	k = 1
	for i in blue:
		if i < k:
			ok = 'NO'
		k += 1
	for i in red:
		if i > k:
			ok = 'NO'
		k += 1
	print(ok)


def f():
	n = int(input())
	l = list(map(int, input().split()))
	s = input()
	a = []
	b = []
	for i in range(n):
		if l[i] < 1 and s[i] == 'B' or (l[i] > n and s[i] == 'R'):
			return 'NO'
		if s[i] == 'R':
			a.append(l[i])
		else:
			b.append(l[i])
	a.sort(reverse=True)
	b.sort()
	t = n
	for i in a:
		if i > t:
			return 'NO'
		t -= 1
	t = 1
	for i in b:
		if i < t:
			return 'NO'
		t += 1
	return 'YES'
for _ in range(int(input())):
	print(f())


T = int(input())
while T > 0:
	T -= 1
	n = int(input())
	array = [int(x) for x in input().split()]
	color_string = input()
	blue = []
	red = []
	ans = 'YES'
	for i in range(len(array)):
		if color_string[i] == 'B':
			blue.append(array[i])
		else:
			red.append(array[i])
	blue = sorted(blue)
	red = sorted(red)
	for i in range(len(blue)):
		if i >= blue[i]:
			ans = 'NO'
	for i in range(len(red)):
		if len(red) - i - 1 > n - red[i]:
			ans = 'NO'
	print(ans)


import sys
r_input = sys.stdin.readline
t = int(r_input())
for _ in range(t):
	n = int(r_input())
	a_list = map(int, r_input().split())
	colors = r_input().rstrip()
	blue = []
	red = []
	for (ind, val) in enumerate(a_list):
		if colors[ind] == 'B':
			blue.append(val)
		else:
			red.append(val)
	blue.sort(reverse=True)
	red.sort(reverse=True)
	flag = 1
	for ind in range(1, n + 1):
		if blue and blue[-1] >= ind:
			blue.pop()
			continue
		if red and red[-1] <= ind:
			red.pop()
			continue
		flag = 0
		break
	print(['NO', 'YES'][flag])


import sys
DEBUG_ENABLED = True

def debug(*args, **kwargs):
	if DEBUG_ENABLED:
		print(*args, file=sys.stderr, **kwargs)

def solve_case(case_num: int) -> str:
	n = int(input())
	array = list(map(int, input().split()))
	barvs = input()
	red = []
	blue = []
	for i in range(n):
		if barvs[i] == 'R':
			red.append(array[i])
		else:
			blue.append(array[i])
	red.sort(reverse=True)
	blue.sort(reverse=False)
	for i in range(len(red)):
		if n - red[i] < i:
			return 'NO'
	for i in range(len(blue)):
		if blue[i] <= i:
			return 'NO'
	return 'YES'
T = int(input())
for tt in range(T):
	result = solve_case(tt + 1)
	print(result)
pass


for _ in range(int(input())):
	n = int(input())
	num = list(map(int, input().split()))
	color = list(input())
	r = []
	b = []
	for i in range(len(color)):
		if color[i] == 'R':
			r.append(num[i])
		else:
			b.append(num[i])
	sb = sorted(b)
	sr = sorted(r)[::-1]
	for i in range(len(sb)):
		if sb[i] < i + 1:
			print('NO')
			break
	else:
		for i in range(len(sr)):
			if sr[i] > n - i:
				print('NO')
				break
		else:
			print('YES')


import sys
N = int(200000.0 + 5)
sys.setrecursionlimit(N)
n = int()

def charming():
	global n
	n = int(input())
	a = list(map(int, input().split()))
	s = input()
	red = list()
	blue = list()
	for i in range(n):
		if s[i] == 'R':
			red.append(a[i])
		else:
			blue.append(a[i])
	red.sort(reverse=True)
	blue.sort()
	p1 = n + 1
	p2 = 0
	ok = True
	for i in red:
		if p1 <= i:
			ok = False
			break
		else:
			p1 -= 1
	for i in blue:
		if p2 >= i:
			ok = False
			break
		else:
			p2 += 1
	print('YES' if ok == True and p1 == p2 + 1 else 'NO')
for t in range(int(input())):
	charming()


import sys, os, io
import math
from collections import defaultdict
from heapq import heappush, heappop, heapify

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

def li():
	return list(map(int, input().split()))
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def solve():
	n = ii()
	a = li()
	s = list(input())
	b = []
	r = []
	for i in range(n):
		if s[i] == 'R':
			r.append(a[i] - 1)
		else:
			b.append(a[i] - 1)
	r.sort()
	b.sort()
	openn = 0
	f = [0] * (n + 1)
	if b and b[0] < 0:
		print('NO')
		return
	for i in b:
		if i >= n:
			continue
		f[min(n, i)] += 1
	x = 0
	for i in range(n):
		if f[i] == 0:
			x += 1
		else:
			if f[i] == 1:
				continue
			if f[i] - 1 > x:
				print('NO')
				return
			x -= f[i] - 1
	if r and r[-1] >= n:
		print('NO')
		return
	f = [0] * n
	for i in r:
		if i >= 0:
			f[max(0, i)] += 1
	x = 0
	for i in range(n - 1, -1, -1):
		if f[i] == 0:
			x += 1
		else:
			if f[i] == 1:
				continue
			if f[i] - 1 > x:
				print('NO')
				return
			x -= f[i] - 1
	print('YES')
t = 1
t = ii()
for _ in range(t):
	solve()


from itertools import accumulate
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	st = input()
	red_arr = [0 for i in range(n + 2)]
	blue_arr = [0 for i in range(n + 2)]
	count = 0
	for i in range(n):
		if st[i] == 'B':
			if arr[i] <= 0:
				count += 1
				continue
			if arr[i] > n:
				arr[i] = n
			blue_arr[arr[i]] += 1
		else:
			if arr[i] > n:
				count += 1
				continue
			if arr[i] <= 0:
				arr[i] = 1
			red_arr[arr[i]] += 1
	if count > 0:
		print('NO')
		continue
	blue_berry = list(accumulate(blue_arr))
	red_arr = red_arr[::-1]
	red_chilly = list(accumulate(red_arr))
	flag = 0
	for i in range(1, n + 1):
		if blue_berry[i] > i or red_chilly[i] > i:
			flag = -1
			break
	if flag == -1:
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	s = input()
	left = []
	right = []
	for i in range(n):
		if s[i] == 'B':
			left.append(arr[i])
		else:
			right.append(arr[i])
	left.sort()
	right.sort(reverse=True)
	alright = True
	for i in range(len(left)):
		if left[i] < i + 1:
			alright = False
	for i in range(len(right)):
		if right[i] > n - i:
			alright = False
	print('YES') if alright else print('NO')


t = int(input())
while t != 0:
	n = int(input())
	a = list(map(int, input().split()))
	s = input()
	(red, blue) = ([], [])
	for i in range(n):
		if s[i] == 'B':
			blue.append(a[i])
		else:
			red.append(a[i])
	blue.sort()
	red.sort()
	ok = 1
	curr = 1
	for i in range(len(blue)):
		if blue[i] < curr:
			ok = 0
			break
		curr += 1
	for i in range(len(red)):
		if red[i] > curr:
			ok = 0
			break
		curr += 1
	if ok == 1:
		print('YES')
	else:
		print('NO')
	t -= 1


tc = int(input())
for _ in range(tc):
	n = int(input())
	l = list(map(int, input().split()))
	s = input()
	(b, r) = ([], [])
	for i in range(n):
		if s[i] == 'B':
			b.append(l[i])
		else:
			r.append(l[i])
	r.sort(reverse=True)
	b.sort()
	c = 'YES'
	for i in range(len(b)):
		if b[i] < i + 1:
			c = 'NO'
			break
	for i in range(len(r)):
		if r[i] > n - i:
			c = 'NO'
			break
	print(c)


import bisect
mod = 10 ** 9 + 7
eps = 10 ** (-9)

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

def __lcm(a, b):
	return a * b / __gcd(a, b)

def __fact(n):
	return 1 if n == 1 else n * __fact(n - 1)

def __mex(a):
	mex = 0
	a.sort()
	for x in a:
		if x <= mex:
			mex += 1
		else:
			break
	return mex

def __dist(x1, y1, x2, y2):
	return (x1 - x2) ** 2 + (y1 - y2) ** 2

def __getprimes(n):
	isprime = [True for i in range(n + 1)]
	primes = []
	for i in range(2, n + 1):
		if isprime[i]:
			for j in range(i * i, n + 1, i):
				isprime[j] = False
	for i in range(2, n + 1):
		if isprime[i]:
			primes.append(i)
	return primes

def __cntprimediv(n):
	ret = 0
	x = n
	i = 2
	while i * i <= x:
		while n % i == 0:
			n //= i
			ret += 1
		i += 1
	if n > 1:
		ret += 1
	return ret

def __primefactors(n):
	ret = []
	x = n
	i = 2
	while i * i <= x:
		while n % i == 0:
			ret.append(i)
			n //= i
		i += 1
	if n > 1:
		ret.append(n)
	return ret

def __sumdigit(n):
	ret = 0
	while n > 0:
		ret += n % 10
		n //= 10
	return ret

def __zfunc(s):
	n = len(s)
	z = [0 for i in range(n)]
	l = 0
	r = 0
	for i in range(1, n):
		if r >= i:
			z[i] = min(z[i - l], r - i + 1)
		while z[i] + i < n and s[z[i]] == s[z[i] + i]:
			z[i] += 1
		if i + z[i] - 1 > r:
			l = i
			r = i + z[i] - 1
	return z

def __to(n, x):
	ret = ''
	while n > 0:
		q = n % x
		if q < 10:
			ret += str(q)
		else:
			ret += chr(q - 10 + ord('a'))
		n //= x
	return ret[::-1]

def solve(t):
	n = int(input())
	a = list(map(int, input().split()))
	s = input()
	d = []
	u = []
	for i in range(n):
		if s[i] == 'B':
			d.append(a[i])
		else:
			u.append(a[i])
	ok = True
	d.sort()
	u.sort()
	d_ind = 0
	u_ind = 0
	for i in range(1, n + 1):
		if d_ind < len(d) and d[d_ind] >= i:
			d_ind += 1
		elif u_ind < len(u) and u[u_ind] <= i:
			u_ind += 1
		else:
			ok = False
			break
	print('YES' if ok else 'NO')
t = 1
t = int(input())
for i in range(t):
	solve(i + 1)


from sys import stdin, stdout, setrecursionlimit
stdin.readline

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

def it():
	return int(stdin.readline().strip())
from collections import defaultdict as dd, Counter as C, deque
from math import ceil, gcd, sqrt, factorial, log2, floor
from bisect import bisect_right as br, bisect_left as bl
from heapq import *
mod = 10 ** 9 + 7
inf = 1 << 60
for _ in range(it()):
	n = it()
	l = mp()
	s = list(input())
	(r, b) = ([], [])
	for i in range(n):
		if s[i] == 'R':
			r.append(l[i])
		else:
			b.append(l[i])
	b.sort()
	r.sort()
	ans = 'YES'
	curr = 1
	b = deque(b)
	while b:
		if curr <= b[0]:
			b.popleft()
			curr += 1
		else:
			ans = 'NO'
			break
	if ans == 'NO':
		print(ans)
		continue
	r = deque(r)
	while r:
		if curr >= r[0]:
			curr += 1
			r.popleft()
		else:
			ans = 'NO'
			break
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	s = input()
	dec = []
	inc = []
	for i in range(n):
		if s[i] == 'B':
			dec.append(a[i])
		else:
			inc.append(a[i])
	inc.sort()
	dec.sort()
	flag = 0
	for i in range(n, 0, -1):
		if len(inc) > 0:
			if inc[-1] > i:
				flag = 1
				break
			else:
				inc.pop()
		elif dec[-1] < i:
			flag = 1
			break
		else:
			dec.pop()
	if flag == 1:
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	s = input()
	(r, b) = ([], [])
	for i in range(n):
		if s[i] == 'R':
			r.append(arr[i])
		else:
			b.append(arr[i])
	r.sort()
	b.sort()
	done = 1
	for i in range(len(b)):
		if b[i] < i + 1:
			done = 0
			break
	if done:
		for i in range(len(r)):
			if r[i] > len(b) + 1 + i:
				done = 0
				break
	if not done:
		print('NO')
	else:
		print('YES')


t = int(input())
for i in range(t):
	n = int(input())
	s = input().split()
	cl = input()
	red = []
	blue = []
	for j in range(n):
		if cl[j] == 'B':
			blue.append(int(s[j]))
		else:
			red.append(int(s[j]))
	blue.sort()
	red.sort()
	kt = True
	lenBlue = len(blue)
	for j in range(lenBlue):
		if blue[j] < j + 1:
			kt = False
			break
	if kt == False:
		print('NO')
	else:
		index = n - lenBlue - 1
		for j in range(n, lenBlue, -1):
			if red[index] > j:
				kt = False
				break
			index -= 1
		if kt == False:
			print('NO')
		else:
			print('YES')


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	s = list(input())
	blue = []
	red = []
	res = True
	for i in range(n):
		if s[i] == 'B':
			blue.append(arr[i])
		else:
			red.append(arr[i])
	blue.sort()
	red.sort(reverse=True)
	a = 0
	b = n + 1
	for i in blue:
		if i > a:
			a += 1
		else:
			res = False
	for i in red:
		if i < b:
			b -= 1
		else:
			res = False
	if res == False:
		print('NO')
	else:
		print('YES')


for test in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	colors = list(input())
	range_of_nos = []
	flag = 0
	for (i, j) in zip(arr, colors):
		if j == 'B':
			if 1 <= i:
				if i > n:
					range_of_nos.append([1, n])
				else:
					range_of_nos.append([1, i])
			else:
				flag = 1
				break
		elif j == 'R':
			if i <= n:
				if i < 1:
					range_of_nos.append([1, n])
				else:
					range_of_nos.append([i, n])
			else:
				flag = 1
				break
	if flag == 1:
		print('NO')
	else:
		range_of_nos.sort()
		for i in range(1, n + 1):
			if range_of_nos[i - 1][0] <= i <= range_of_nos[i - 1][-1]:
				pass
			else:
				flag = 1
				break
		if flag == 1:
			print('NO')
		else:
			print('YES')


from sys import stdin, stdout
import sys
import math
import itertools
from collections import defaultdict
sys.setrecursionlimit(10 ** 6)

def main():
	t = int(stdin.readline().strip())
	for j in range(1, t + 1):
		n = int(stdin.readline().strip())
		arr = [int(x) for x in stdin.readline().split()]
		colors = stdin.readline().strip()
		mapping = {'B': [], 'R': []}
		for i in range(n):
			mapping[colors[i]].append(arr[i])
		ans = 'YES'
		mapping['R'].sort(reverse=True)
		empty = 0
		prev = n + 1
		flag = 0
		for num in mapping['R']:
			if num < prev - 1:
				empty += prev - 1 - num
			elif num > prev - 1:
				empty -= 1
			prev = num
			if empty < 0:
				flag = 1
				break
		if flag == 1:
			ans = 'NO'
		mapping['B'].sort()
		empty = 0
		prev = 0
		flag = 0
		for num in mapping['B']:
			if num > prev + 1:
				empty += num - (prev + 1)
			elif num < prev + 1:
				empty -= 1
			prev = num
			if empty < 0:
				flag = 1
				break
		if flag == 1:
			ans = 'NO'
		if mapping['R'] and max(mapping['R']) > n or (mapping['B'] and min(mapping['B']) < 1):
			ans = 'NO'
		stdout.write(ans + '\n')
main()


test_cases = int(input())
for t in range(test_cases):
	n = int(input())
	a = list(map(int, input().split()))
	st = input()
	blue = []
	red = []
	for i in range(len(st)):
		ch = st[i]
		if ch == 'B':
			blue.append(a[i])
		elif ch == 'R':
			red.append(a[i])
	blue.sort()
	red.sort()
	cur_window = 0
	flag = 1
	for e in blue:
		if e >= cur_window + 1:
			cur_window += 1
		else:
			flag = 0
			break
	for e in red:
		if e <= cur_window + 1:
			cur_window += 1
		else:
			flag = 0
			break
	if flag == 0:
		print('NO')
	else:
		print('YES')


def findAnswer(numbers, colours):
	blueList = []
	redList = []
	key = 0
	for i in range(len(colours)):
		if colours[i] == 'R':
			redList.append(numbers[i])
		else:
			blueList.append(numbers[i])
	blueList.sort()
	redList.sort()
	if len(blueList) > 0:
		if blueList[0] < 1:
			key = 1
	if len(redList) > 0:
		if redList[-1] > len(numbers):
			key = 1
	for i in range(len(blueList)):
		if blueList[i] - (i + 1) < 0:
			key = 1
	redList = list(map(lambda x: x - len(blueList), redList))
	for i in range(len(redList)):
		if redList[i] - (i + 1) > 0:
			key = 1
	if key == 0:
		return 'YES'
	else:
		return 'NO'
t = int(input())
for i in range(t):
	n = int(input())
	nums = list(map(int, input().split()))[:n]
	colors = list(input())
	print(findAnswer(nums, colors))


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

def main():
	t = int(input())
	while t:
		n = int(input())
		a = list(map(int, input().split()))
		s = str(input())
		(r, b) = ([], [])
		for i in range(n):
			if s[i] == 'B':
				b.append(a[i])
			else:
				r.append(a[i])
		r.sort()
		b.sort()
		ok = True
		for i in range(len(b)):
			if b[i] < i + 1:
				ok = False
				break
		tt = len(b) + 1
		for i in range(len(r)):
			if r[i] > tt:
				ok = False
				break
			tt += 1
		print('YES' if ok else 'NO')
		t -= 1
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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

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()


import sys
from collections import defaultdict

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

def solve(n, a, BR):
	b = []
	r = []
	for (i, c) in zip(a, BR):
		if c == 'B':
			b.append(i)
		else:
			r.append(i)
	b = sorted(b)
	r = sorted(r)
	for i in range(len(b)):
		if b[i] < i + 1:
			return 0
	for i in range(len(r)):
		if r[i] > len(b) + i + 1:
			return 0
	return 1
T = int(input())
for i in range(T):
	n = int(input())
	a = get_ints()
	BR = input()
	ans = solve(n, a, BR)
	if ans:
		print('YES')
	else:
		print('NO')


from math import *
from bisect import bisect_left as bl
from bisect import bisect_right as br
from collections import Counter as ctr
from collections import deque as dq
from array import array
from re import search
li = lambda : list(map(int, input().split()))
arr = lambda a: array('i', a)
bi = lambda n: bin(n).replace('0b', '')
yn = lambda f: print('NYOE S'[f::2])
sbstr = lambda a, s: search('.*'.join(a), s)

def solve():
	for _ in range(int(input())):
		n = int(input())
		a = li()
		c = list(input())
		b = []
		r = []
		for i in range(n):
			if c[i] == 'B':
				b.append(a[i])
			else:
				r.append(a[i])
		b.sort()
		r.sort()
		f = True
		l = len(b)
		for i in range(l):
			if b[i] < i + 1:
				f = False
				break
		for i in range(len(r)):
			if r[i] > i + l + 1:
				f = False
				break
		yn(f)
solve()


def solve():
	n = int(input())
	l = list(map(int, input().split()))
	s = input()
	b = list()
	r = list()
	(bcnt, rcnt) = (0, 0)
	for i in range(len(s)):
		if s[i] == 'B':
			b.append(l[i])
			bcnt += 1
		else:
			r.append(l[i])
			rcnt += 1
	b.sort()
	r.sort()
	for i in range(0, bcnt):
		if i + 1 > b[i]:
			print('NO')
			return
	for i in range(bcnt, n):
		if i + 1 < r[i - bcnt]:
			print('NO')
			return
	print('YES')
t = int(input())
for i in range(t):
	solve()


for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	s = input()
	v = [False] * (n + 1)
	(b, r) = ([], [])
	res = 'YES'
	c = 0
	for i in range(n):
		if s[i] == 'R':
			r += [a[i]]
		else:
			b += [a[i]]
	(i, j) = (n, 1)
	r = sorted(r)
	for k in r[::-1]:
		if k <= i:
			i -= 1
		else:
			res = 'NO'
			break
	b = sorted(b)
	for k in b:
		if k >= j:
			j += 1
		else:
			res = 'NO'
			break
	print(res)


import sys
from os import path
if path.exists('input.txt'):
	sys.stdout = open('output.txt', 'w')
	sys.stdin = open('input.txt', 'r')

def main():
	inp = [x for x in sys.stdin.buffer.read().split()]
	ii = 0
	out = []
	t = int(inp[ii])
	ii += 1
	for _ in range(t):
		n = int(inp[ii])
		ii += 1
		arr = list(map(int, inp[ii:ii + n]))
		ii += n
		s = str(inp[ii])[2:-1]
		ii += 1
		blues = []
		reds = []
		for i in range(n):
			if s[i] == 'R':
				reds.append(arr[i])
			else:
				blues.append(arr[i])
		blues.sort()
		reds.sort()
		if blues and blues[0] <= 0:
			out.append('NO')
			continue
		if reds and reds[-1] > n:
			out.append('NO')
			continue
		pointer = 0
		ans = ''
		for i in range(n):
			num = i + 1
			while pointer < len(blues) and blues[pointer] <= num:
				pointer += 1
			if pointer > num:
				ans = 'NO'
				break
		pointer = len(reds) - 1
		count = 0
		for i in range(n - 1, -1, -1):
			num = i + 1
			while pointer >= 0 and reds[pointer] >= num:
				pointer -= 1
				count += 1
			if count > n - num + 1:
				ans = 'NO'
				break
		if ans == 'NO':
			out.append('NO')
		else:
			out.append('YES')
	out_str = '\n'.join((str(x) for x in out))
	sys.stdout.write(out_str)
main()


def solve():
	n = int(input())
	arr = list(map(int, input().split()))
	col = input().strip()
	red = [arr[i] for i in range(n) if col[i] == 'R']
	blue = [arr[i] for i in range(n) if col[i] == 'B']
	red.sort(reverse=True)
	blue.sort(reverse=True)
	for i in range(1, n + 1):
		if len(blue) and blue[-1] >= i:
			blue.pop()
		elif len(red) and red[-1] <= i:
			red.pop()
		else:
			return 'NO'
	return 'YES'
n = int(input())
for i in range(n):
	print(solve())


import sys
for t in range(int(input())):
	n = int(sys.stdin.readline())
	a = list(map(int, sys.stdin.readline().split()))
	s = sys.stdin.readline()
	b = []
	r = []
	for i in range(n):
		if s[i] == 'B':
			b.append(a[i])
		else:
			r.append(a[i])
	b.sort()
	r.sort()
	(bj, rj) = (0, 0)
	for i in range(1, n + 1):
		if bj < len(b) and b[bj] >= i:
			bj += 1
			continue
		if rj < len(r) and r[rj] <= i:
			rj += 1
			continue
		print('NO')
		break
	else:
		print('YES')


import sys
import bisect
from bisect import bisect_left as lb
from bisect import bisect_right as rb
input_ = lambda : sys.stdin.readline().strip('\r\n')
from math import log
from math import gcd
from math import atan2, acos
from random import randint
sa = lambda : input_()
sb = lambda : int(input_())
sc = lambda : input_().split()
sd = lambda : list(map(int, input_().split()))
sflo = lambda : list(map(float, input_().split()))
se = lambda : float(input_())
sf = lambda : list(input_())
flsh = lambda : sys.stdout.flush()
mod = 10 ** 9 + 7
mod1 = 998244353
gp = []
cost = []
dp = []
mx = []
ans1 = []
ans2 = []
special = []
specnode = []
a = 0
kthpar = []

def dfs2(root, par):
	if par != -1:
		dp[root] = dp[par] + 1
	for i in range(1, 20):
		if kthpar[root][i - 1] != -1:
			kthpar[root][i] = kthpar[kthpar[root][i - 1]][i - 1]
	for child in gp[root]:
		if child == par:
			continue
		kthpar[child][0] = root
		dfs(child, root)
ans = 0
a = []
(n, k) = (0, 0)
b = []
vis = []
tot = 0
time = []
time1 = []
adj = []
mx = -1
eps = 1e-07
x = 0
pref = []
lvl = []

def update_it(bit, i, val):
	n = len(bit)
	while i < n:
		bit[i] += val
		i += i & -i

def get_ans(bit, i):
	n = len(bit)
	tot = 0
	while i > 0:
		tot += bit[i]
		i -= i & -i
	return tot
prime = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]

def hnbhai(tc):
	n = sb()
	a = sd()
	s = sa()
	r = []
	b = []
	for i in range(n):
		if s[i] == 'R':
			r.append(a[i])
		else:
			b.append(a[i])
	r.sort()
	b.sort()
	chiye = 1
	hai = 0
	for i in b:
		if chiye <= i:
			chiye += 1
		else:
			print('NO')
			return
	for i in r:
		if chiye >= i:
			chiye += 1
		else:
			print('NO')
			return
	print('YES')
for _ in range(sb()):
	hnbhai(_ + 1)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	s = input()
	red = []
	blue = []
	for i in range(n):
		if s[i] == 'B':
			blue.append(a[i])
		else:
			red.append(a[i])
	blue.sort()
	red.sort(reverse=True)
	good = True
	for i in range(len(blue)):
		if blue[i] < i + 1:
			good = False
	for i in range(len(red)):
		if red[i] > n - i:
			good = False
	if good:
		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')
t = int(input())

def solve(r, b):
	upper = n
	ans = set()
	r.sort()
	while r:
		curr = r.pop()
		while True:
			if upper not in ans:
				break
			else:
				upper -= 1
		if curr > upper:
			return False
		else:
			ans.add(upper)
	b.sort(reverse=True)
	lower = 1
	while b:
		curr = b.pop()
		while True:
			if lower in ans:
				lower += 1
			else:
				break
		if curr < lower:
			return False
		else:
			ans.add(lower)
	if len(ans) != n:
		return False
	return True
while t:
	t -= 1
	n = int(input())
	arr = [int(x) for x in input().split()]
	s = input()
	r = []
	b = []
	for i in range(n):
		if s[i] == 'B':
			if arr[i] >= 1:
				b.append(arr[i])
		elif arr[i] <= n:
			r.append(arr[i])
	if solve(r, b):
		print('YES')
	else:
		print('NO')


t = int(input())
for test_case in range(t):
	n = int(input())
	arr = [int(el) for el in input().split(' ')]
	colors = input()
	blues = []
	reds = []
	for i in range(len(arr)):
		if colors[i] == 'R':
			reds.append(arr[i])
		else:
			blues.append(arr[i])
	s_blues = sorted(blues)
	s_reds = sorted(reds)
	res = ''
	for j in range(len(blues)):
		if s_blues[j] < j + 1:
			res = 'NO'
			break
	for j in range(len(reds)):
		if s_reds[len(reds) - j - 1] > n - j:
			res = 'NO'
			break
	print(res or 'YES')


n = int(input())
for i in range(n):
	m = int(input())
	z = list(map(int, input().split()))
	(b, r) = ([], [])
	x = input()
	for j in range(m):
		if x[j] == 'B':
			b.append(z[j])
		else:
			r.append(z[j])
	b = sorted(b)
	v = True
	r = sorted(r, reverse=True)
	for k in range(len(b)):
		if b[k] < k + 1:
			v = False
	for k in range(len(r)):
		if r[k] > m - k:
			v = False
	if v:
		print('YES')
	else:
		print('NO')


import sys
import io, os
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	s = str(input().rstrip())
	B = []
	R = []
	for (i, c) in enumerate(s):
		if c == 'B':
			B.append(A[i])
		else:
			R.append(A[i])
	flag = True
	B.sort()
	for (i, b) in enumerate(B):
		if b < i + 1:
			flag = False
			break
	R.sort(reverse=True)
	for (i, r) in enumerate(R):
		if r > n - i:
			flag = False
			break
	if flag:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	s = input()
	b = []
	for (i, j) in zip(a, s):
		b.append([j, i])
	b.sort()
	f = 1
	for i in range(n):
		if b[i][0] == 'R' and b[i][1] > i + 1:
			f = 0
			break
		elif b[i][0] == 'B' and b[i][1] < i + 1:
			f = 0
			break
	if f:
		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')
T = int(input())
for _ in range(T):
	n = int(input())
	A = list(map(int, input().split(' ')))
	C = input()
	(R, B) = ([], [])
	for i in range(n):
		(R if C[i] == 'R' else B).append(A[i])
	R.sort()
	B.sort()
	flag = True
	(i, r, b) = (1, 0, 0)
	while r < len(R) or b < len(B):
		if b < len(B) and i <= B[b]:
			i += 1
			b += 1
		elif r < len(R) and i >= R[r]:
			i += 1
			r += 1
		else:
			flag = False
			break
	print('YES' if flag else 'NO')


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	s = str(input())
	d = [0 for i in range(n + 3)]
	ok = True
	l = []
	r = []
	for i in range(n):
		if s[i] == 'B':
			if a[i] <= 0:
				ok = False
			l.append(a[i])
		else:
			if a[i] > n:
				ok = False
			r.append(a[i])
	l.sort()
	r.sort()
	l_it = 0
	r_it = 0
	for i in range(1, n + 1):
		p = False
		while l_it != len(l):
			if l[l_it] < i:
				l_it += 1
			else:
				l_it += 1
				p = True
				break
		if p:
			continue
		while r_it != len(r):
			if r[r_it] > i:
				r_it += 1
			else:
				r_it += 1
				p = True
				break
		if p == False:
			ok = False
	if ok == False:
		print('NO')
	else:
		print('YES')


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

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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

def main():
	pass

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

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

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

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

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

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

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

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

def nCr(n, r):
	f = math.factorial
	return f(n) // f(r) // f(n - r)
mod = int(1000000000.0) + 7
import math
import statistics
from bisect import bisect_right
for __ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	s = input()
	blue = []
	red = []
	for i in range(n):
		if s[i] == 'B':
			blue.append(a[i])
		else:
			red.append(a[i])
	blue.sort()
	red.sort(reverse=True)
	ans = 'YES'
	for i in range(len(blue)):
		if blue[i] < i + 1:
			ans = 'NO'
	for i in range(len(red)):
		if red[i] > n - i:
			ans = 'NO'
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	colors = input()
	red = []
	blue = []
	ans = 'YES'
	for i in range(len(colors)):
		if colors[i] == 'B':
			blue.append(a[i])
		else:
			red.append(a[i])
	blue.sort()
	red.sort(reverse=True)
	num = 1
	for i in range(len(blue)):
		if blue[i] < num:
			ans = 'NO'
		num += 1
	num = n
	for i in range(len(red)):
		if red[i] > num:
			ans = 'NO'
		num -= 1
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	color = input()
	blue = []
	red = []
	for i in range(n):
		if color[i] == 'B':
			blue.append(a[i])
		else:
			red.append(a[i])
	blue.sort()
	red.sort()
	got = True
	for i in range(len(blue)):
		if blue[i] < i + 1:
			got = False
			break
	if not got:
		print('NO')
		continue
	k = len(blue)
	for i in range(len(red)):
		if red[i] > i + 1 + k:
			got = False
			break
	print('YES' if got else 'NO')


def solve():
	n = int(input())
	a = [int(x) for x in input().split()]
	colors = list(input())
	r = []
	b = []
	for i in range(n):
		if colors[i] == 'B':
			b.append(a[i])
		else:
			r.append(a[i])
	d = len(b)
	i = d - 1
	j = 0
	r.sort()
	b.sort()
	for number in range(d, 0, -1):
		if b[i] >= number:
			i -= 1
		else:
			return 'NO'
	for number in range(d + 1, n + 1):
		if r[j] <= number:
			j += 1
		else:
			return 'NO'
	return 'YES'
t = int(input())
for _ in range(t):
	print(solve())


from collections import Counter, deque, defaultdict
from math import *
mod = 1000000007

def isNotPossible(num, n):
	return num > n

def isNotPossible2(num, n):
	return num < n

def solve():
	n = int(input())
	l = list(map(int, input().split()))
	s = input()
	red = []
	blue = []
	for i in range(n):
		if s[i] == 'R':
			red.append(l[i])
		else:
			blue.append(l[i])
	red.sort()
	blue.sort()
	n1 = len(blue)
	n2 = len(red)
	for i in range(n):
		if i < n1:
			if isNotPossible(i + 1, blue[i]):
				print('NO')
				return
		elif isNotPossible2(i + 1, red[i - n1]):
			print('NO')
			return
	print('YES')
testcase = int(input())
for num in range(testcase):
	solve()


answers = []
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	s = input()
	b = []
	r = []
	for i in range(n):
		if s[i] == 'B':
			b.append(arr[i])
		else:
			r.append(arr[i])
	b.sort()
	r.sort()
	bi = 0
	rj = 0
	ans = 'NO'
	for k in range(1, n + 1):
		if bi < len(b) and b[bi] >= k:
			bi += 1
		elif rj < len(r) and r[rj] <= k:
			rj += 1
		else:
			break
	else:
		ans = 'YES'
	answers.append(ans)
print(*answers, sep='\n')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	color = list(input())
	blue = []
	red = []
	for (i, item) in enumerate(a):
		if color[i] == 'B':
			blue.append(item)
		else:
			red.append(item)
	blue = sorted(blue)
	red = sorted(red)
	possible = True
	i = 1
	for item in blue:
		if item >= i:
			i += 1
		else:
			possible = False
	for item in red:
		if item <= i:
			i += 1
		else:
			possible = False
	if possible:
		print('YES')
	else:
		print('NO')


def check(arr):
	c = [1] * len(arr)
	for i in arr:
		if 0 <= i - 1 < len(arr) and c[i - 1] == 1:
			c[i - 1] -= 1
		else:
			return False
	return True

def checkB(arr):
	arr.sort()
	for (ind, i) in enumerate(arr):
		if i < ind + 1:
			return False
	return True

def checkR(arr, pad):
	arr.sort()
	for (ind, i) in enumerate(arr):
		if i > ind + 1 + pad:
			return False
	return True

def solve(n, p, c):
	b = []
	r = []
	bc = rc = 0
	if check(p):
		return 'YES'
	else:
		for i in range(n):
			if c[i] == 'B':
				b.append(p[i])
				bc += 1
			else:
				r.append(p[i])
				rc += 1
		if bc == n:
			if checkB(p):
				return 'YES'
		elif rc == n:
			if checkR(p, 0):
				return 'YES'
		elif checkB(b) and checkR(r, bc):
			return 'YES'
	return 'NO'
t = int(input())
for test in range(t):
	n = int(input())
	p = list(map(int, input().split()))
	c = input()
	print(solve(n, p, c))


from collections import defaultdict
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	color = input()
	dp = []
	for i in range(n):
		if color[i] == 'B':
			dp.append([0, arr[i]])
		else:
			dp.append([1, arr[i]])
	dp.sort()
	cnt = 0
	flag = 1
	for i in dp:
		cnt += 1
		if i[1] == cnt:
			continue
		if i[1] != cnt:
			if i[0] == 0 and i[1] > cnt:
				continue
			elif i[0] == 1 and i[1] < cnt:
				continue
			else:
				print('NO')
				flag = 0
				break
	if flag:
		print('YES')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	s = input()
	B = []
	R = []
	B_count = 0
	R_count = 0
	for i in range(n):
		if s[i] == 'B':
			B.append(a[i])
			B_count += 1
		else:
			R.append(a[i])
			R_count += 1
	if all((i >= j for (i, j) in zip(sorted(B), list(range(1, B_count + 1))))) and all((i <= j for (i, j) in zip(sorted(R), list(range(n - R_count + 1, n + 1))))):
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	s = input()
	barr = []
	rarr = []
	for i in range(n):
		if s[i] == 'B':
			barr.append(a[i])
		else:
			rarr.append(a[i])
	i = 0
	j = 0
	leb = len(barr)
	ler = len(rarr)
	barr.sort()
	rarr.sort()
	now = 1
	y = 0
	while now <= n:
		if i != leb and barr[i] >= now:
			i += 1
		elif j != ler and rarr[j] <= now:
			j += 1
		else:
			y = 1
			break
		now += 1
	if y == 0:
		print('YES')
	else:
		print('NO')


import sys, math

def solve():
	n = int(input())
	l = list(map(int, input().split()))
	s = list(input())
	dec = []
	inc = []
	for i in range(len(l)):
		if s[i] == 'B':
			dec.append(l[i])
		else:
			inc.append(l[i])
	dec.sort()
	inc.sort()
	if len(dec) > 0 and dec[0] < 1:
		print('NO')
		return
	elif len(inc) > 0 and inc[len(inc) - 1] > n:
		print('NO')
		return
	ans = True
	start = 1
	for i in dec:
		if i < start:
			ans = False
		start += 1
	start = n
	inc.reverse()
	for i in inc:
		if i > start:
			ans = False
		start -= 1
	if ans:
		print('YES')
	else:
		print('NO')
t = int(input())
while t != 0:
	solve()
	t -= 1


for _ in range(int(input())):
	l = int(input())
	a = list(map(int, input().split()))
	s = input()
	b = [a[i] for i in range(l) if s[i] == 'B']
	r = [a[i] for i in range(l) if s[i] == 'R']
	b.sort()
	r.sort()
	n = len(r)
	m = len(b)
	c = 0
	k = 1
	for i in range(m):
		if b[i] < 1:
			c = 1
		if b[i] < k:
			c = 1
		k += 1
	for j in range(n):
		if r[j] > l:
			c = 1
		if r[j] > k:
			c = 1
		k += 1
	if c == 0:
		print('YES')
	else:
		print('NO')


import math as m
i = input()
inp = []
for a in range(0, int(i)):
	input()
	inp.append([[int(x) for x in input().split()], input()])

def logic(Barr, Rarr):
	l1 = len(Barr)
	for i in range(l1):
		if Barr[i] < i + 1:
			return 'NO'
	l2 = len(Rarr)
	for i in range(l2):
		if Rarr[i] > l1 + i + 1:
			return 'NO'
	return 'YES'
for [arr, coloring] in inp:
	Barr = []
	Rarr = []
	for i in range(len(arr)):
		if coloring[i] == 'B':
			Barr.append(arr[i])
		else:
			Rarr.append(arr[i])
	Barr.sort()
	Rarr.sort()
	print(logic(Barr, Rarr))


tt = int(input())
for _ in range(tt):
	n = int(input())
	a = list(map(int, input().split()))
	s = input()
	bed = []
	cec = []
	for i in range(n):
		if s[i] == 'R':
			bed.append(a[i])
		else:
			cec.append(a[i])
	bed.sort()
	cec.sort()
	bed = bed[::-1]
	r = n + 1
	l = 0
	for i in range(len(bed)):
		if bed[i] < r:
			r -= 1
	for i in range(len(cec)):
		if cec[i] > l:
			l += 1
	if l + 1 == r:
		print('YES')
	else:
		print('NO')


for step in range(int(input())):
	n = int(input())
	marbles = list(map(int, input().split()))
	colors = input()
	redMarbles = []
	blueMarbles = []
	for i in range(n):
		if colors[i] == 'B':
			blueMarbles.append(marbles[i])
		else:
			redMarbles.append(marbles[i])
	redMarbles.sort(reverse=True)
	blueMarbles.sort()
	ans = True
	for i in range(len(redMarbles)):
		if redMarbles[i] > n - i:
			ans = False
	for i in range(len(blueMarbles)):
		if blueMarbles[i] <= i:
			ans = False
	print('YES' if ans else 'NO')


t = int(input())
for i in range(0, t):
	n = int(input())
	l = [int(i) for i in input().split()]
	p = sorted(l)
	s = str(input())
	flag = True
	for i in range(0, n):
		if p[i] != i + 1:
			flag = False
			break
	if flag == True:
		print('YES')
	else:
		l_1 = []
		l_2 = []
		for i in range(0, len(l)):
			if s[i] == 'B':
				l_1.append(l[i])
			else:
				l_2.append(l[i])
		l_1.sort()
		l_2.sort(reverse=True)
		flag = True
		for i in range(0, len(l_1)):
			if l_1[i] < i + 1:
				flag = False
				print('NO')
				break
		if flag == True:
			ok = 0
			for i in range(0, len(l_2)):
				if n - l_2[i] < i:
					ok = 1
					print('NO')
					break
			if ok == 0:
				print('YES')


def fun(n, arr, s):
	b = []
	r = []
	ans = True
	for i in range(n):
		if s[i] == 'R':
			r.append(arr[i])
			if arr[i] > n:
				ans = False
				break
		else:
			b.append(arr[i])
			if arr[i] < 1:
				ans = False
				break
	if not ans:
		return 'NO'
	b = sorted(b)
	l1 = len(b)
	r = sorted(r)
	l2 = len(r)
	bb = 0
	rr = 0
	for i in range(1, n + 1):
		if bb < l1:
			x = b[bb]
			bb += 1
			if x < i:
				ans = False
				break
		elif rr < l2:
			x = r[rr]
			rr += 1
			if x > i:
				ans = False
				break
	return 'YES' if ans else 'NO'
t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	s = input()
	ans = fun(n, arr, s)
	print(ans)


import sys
input = lambda : sys.stdin.readline().strip()
t = int(input())
while t:
	t -= 1
	n = int(input())
	a = list(map(int, input().split()))
	s = list(input())
	c = []
	for i in range(n):
		c.append((s[i], a[i]))
	c.sort()
	ok = True
	for i in range(n):
		if c[i][0] == 'B':
			if c[i][1] < i + 1:
				ok = False
				break
		elif c[i][1] > i + 1:
			ok = False
			break
	if ok:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	c = input()
	r = []
	b = []
	for i in range(n):
		if c[i] == 'B':
			b.append(a[i])
		else:
			r.append(a[i])
	r.sort()
	b.sort()
	ans = 'YES'
	idx = 0
	j = 0
	for i in range(1, n + 1):
		if idx < len(b) and b[idx] >= i:
			idx += 1
		elif j < len(r) and r[j] <= i:
			j += 1
		else:
			ans = 'NO'
			break
	print(ans)


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

def solve():
	N = int(input())
	A = list(map(int, input().split()))
	B = []
	R = []
	for (i, c) in enumerate(input()):
		if c == 'B':
			B.append(A[i])
		else:
			R.append(A[i])
	B.sort()
	R.sort(reverse=True)
	for (i, b) in enumerate(B):
		if b < i + 1:
			print('NO')
			return
	for (i, r) in enumerate(R):
		if r > N - i:
			print('NO')
			return
	print('YES')
for _ in range(int(input())):
	solve()


from sys import stdin, stdout, setrecursionlimit
from io import BytesIO, IOBase
setrecursionlimit(10000)

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		import os
		self.os = os
		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
		self.BUFSIZE = 8192

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

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

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

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(stdin, stdout) = (IOWrapper(stdin), IOWrapper(stdout))
input = lambda : stdin.readline().rstrip('\r\n')
inp = lambda : int(input())
st = lambda : input().strip()
jn = lambda x, l: x.join(map(str, l))
int_arr = lambda : list(map(int, input().strip().split()))
str_arr = lambda : list(map(str, input().split()))
get_str = lambda : map(str, input().strip().split())
get_int = lambda : map(int, input().strip().split())
get_float = lambda : map(float, input().strip().split())
mod = 1000000007
for _ in range(inp()):
	n = inp()
	arr = int_arr()
	s = st()
	(b, r) = ([], [])
	for i in range(n):
		if s[i] == 'B':
			b.append(arr[i])
		else:
			r.append(arr[i])
	val = 1
	b.sort()
	r.sort()
	yes = True
	for i in range(len(b)):
		if b[i] < val:
			yes = False
			break
		val += 1
	for i in range(len(r)):
		if r[i] > val:
			yes = False
			break
		val += 1
	print('YES' if yes else 'NO')


for _ in range(int(input())):
	n = int(input())
	li = list(map(int, input().split()))
	s = input()
	r = s.count('R')
	b = n - r
	f = 0
	x = -10 ** 9
	m = 10 ** 9
	ri = [0] * n
	bi = [0] * n
	for i in range(n):
		if s[i] == 'R':
			if li[i] > n:
				f = 1
				break
			if li[i] < 1:
				li[0] += 1
			else:
				ri[li[i] - 1] += 1
		if s[i] == 'B':
			if li[i] < 1:
				f = 1
				break
			if li[i] > n:
				bi[n - 1] += 1
			else:
				bi[li[i] - 1] += 1
	for i in range(1, n):
		ri[n - i - 1] = ri[n - i - 1] + ri[n - i]
		bi[i] = bi[i] + bi[i - 1]
	for i in range(n):
		if ri[n - i - 1] > i + 1:
			f = 1
			break
	for i in range(n):
		if bi[i] > i + 1:
			f = 1
			break
	if f == 1:
		print('No')
	else:
		print('Yes')


for _ in range(int(input())):
	n = int(input())
	a = [[0, 0] for x in range(n)]
	k = 0
	for i in input().split():
		a[k][0] = int(i)
		k += 1
	k = 0
	for j in input():
		a[k][1] = j
		k += 1
	a.sort(key=lambda x: (x[1] == 'R', x[0]))
	f = True
	d = True
	for y in range(n):
		if a[y][1] == 'R' and a[y][0] > y + 1:
			f = False
			break
		if a[y][1] == 'B' and a[y][0] < y + 1:
			f = False
			break
	if f:
		print('YES')
	else:
		print('NO')


import math
from heapq import heappush, heappop, heapify
import random
import string
from collections import deque
from bisect import bisect, bisect_left, bisect_right, insort
import sys
input = sys.stdin.readline
S = lambda : input().rstrip()
I = lambda : int(S())
M = lambda : map(int, S().split())
L = lambda : list(M())
H = 1000000000 + 7
for _ in range(I()):
	n = I()
	l = L()
	s = S()
	a = list(zip(s, l))
	a.sort()
	f = 0
	for i in range(n):
		if a[i][0] == 'B' and a[i][1] < i + 1:
			f = 1
			break
		if a[i][0] == 'R' and a[i][1] > i + 1:
			f = 1
			break
	if f:
		print('NO')
	else:
		print('YES')


n = int(input())
for _ in range(n):
	x = int(input())
	nums = list(map(int, input().split()))
	colors = input()
	ans = sorted(list(zip(colors, nums)))
	f = True
	for i in range(x):
		if ans[i][0] == 'B':
			if ans[i][1] < i + 1:
				f = False
				break
		if ans[i][0] == 'R':
			if ans[i][1] > i + 1:
				f = False
				break
	if f:
		print('YES')
	else:
		print('NO')


def solve(n, a, b, r):
	b.sort()
	r.sort()
	i = 0
	for i in range(len(b)):
		if b[i] < i + 1:
			return 'NO'
	curr = len(b) + 1
	for i in range(len(r)):
		if r[i] > curr:
			return 'NO'
		curr += 1
	return 'YES'
for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	s = input()
	b = []
	r = []
	for i in range(n):
		if s[i] == 'B':
			b.append(a[i])
		else:
			r.append(a[i])
	print(solve(n, a, b, r))


def fun():
	t = int(input())
	for _ in range(t):
		n = int(input())
		arr = list(map(int, input().split()))
		colors = input()
		(blue, red) = ([], [])
		for i in range(n):
			if colors[i] == 'B':
				blue.append(arr[i])
			else:
				red.append(arr[i])
		blue.sort()
		red.sort()
		flag = True
		for i in range(len(blue)):
			if blue[i] < i + 1:
				flag = False
				break
		k = len(blue)
		for j in range(len(red)):
			if red[j] > k + 1:
				flag = False
				break
			k += 1
		if flag:
			print('YES')
		else:
			print('NO')
fun()


for _ in range(int(input())):
	size = int(input())
	arr = list(map(int, input().split()))
	s = str(input())
	b_arr = []
	r_arr = []
	for ind in range(size):
		if s[ind] == 'B':
			b_arr.append(arr[ind])
		else:
			r_arr.append(arr[ind])
	b_arr = sorted(b_arr)
	r_arr = sorted(r_arr)
	cur_num = 1
	bad = 0
	for ind in range(len(b_arr)):
		if cur_num <= b_arr[ind]:
			cur_num += 1
		else:
			bad = 1
	for ind in range(len(r_arr)):
		if cur_num >= r_arr[ind]:
			cur_num += 1
		else:
			bad = 1
	if bad:
		print('NO')
	else:
		print('YES')


def redBluePermutation(n, array, colors):
	blue = []
	red = []
	for x in range(n):
		if colors[x] == 'B':
			blue.append(array[x])
		else:
			red.append(array[x])
	blue.sort()
	red.sort()
	m = len(blue)
	n = len(red)
	for x in range(m):
		if blue[x] >= x + 1:
			continue
		else:
			return 'NO'
	for x in range(n):
		if red[x] <= m + x + 1:
			continue
		else:
			return 'NO'
	return 'YES'
t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	s = list(input())
	print(redBluePermutation(n, l, s))


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	colors = input()
	Bnums = [a[j] for j in range(len(a)) if colors[j] == 'B']
	Rnums = [a[j] for j in range(len(a)) if colors[j] == 'R']
	Bnums.sort()
	Rnums.sort()
	flag = True
	for j in range(len(Bnums)):
		if Bnums[j] < j + 1:
			flag = False
			break
	for j in range(len(Rnums)):
		if Rnums[j] > j + len(Bnums) + 1:
			flag = False
			break
	print('YES' if flag else 'NO')


import sys

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

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

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

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

def get_list_strings():
	return list(map(str, sys.stdin.readline().strip().split()))

def solve(n, arr, s):
	r = []
	b = []
	for (i, ele) in enumerate(s):
		if ele == 'R':
			if arr[i] > n:
				print('NO')
				return
			if arr[i] <= 0:
				arr[i] = 1
			r.append(arr[i])
		else:
			if arr[i] <= 0:
				print('NO')
				return
			if arr[i] > n:
				arr[i] = n
			b.append(arr[i])
	r.sort()
	b.sort()
	c = 1
	i = 0
	j = 0
	l1 = len(r)
	l2 = len(b)
	while i < l1 and j < l2:
		if c <= b[j]:
			j += 1
			c += 1
		elif r[i] <= c:
			i += 1
			c += 1
		else:
			print('NO')
			return
	while j < l2:
		if c <= b[j]:
			j += 1
			c += 1
		else:
			print('NO')
			return
	while i < l1:
		if r[i] <= c:
			i += 1
			c += 1
		else:
			print('NO')
			return
	print('YES')
T = get_int()
while T:
	n = get_int()
	arr = get_list()
	s = get_string()
	solve(n, arr, s)
	T -= 1


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	s = input()
	(blue, red) = ([], [])
	for i in range(n):
		if s[i] == 'B':
			blue.append(arr[i])
		else:
			red.append(arr[i])
	blue.sort()
	red.sort()
	ans = 'YES'
	(i, j) = (1, 0)
	while j < len(blue):
		if blue[j] < i:
			ans = 'NO'
			break
		i += 1
		j += 1
	j = 0
	while j < len(red):
		if red[j] > i:
			ans = 'NO'
			break
		i += 1
		j += 1
	print(ans)


t = int(input())
for _ in range(0, t):
	n = int(input())
	arr = list(map(int, input().split()))
	string1 = input()
	red = []
	blue = []
	for i in range(0, n):
		if string1[i] == 'B':
			blue.append(arr[i])
		else:
			red.append(arr[i])
	blue.sort()
	red.sort()
	l1 = len(blue)
	l2 = len(red)
	flag = 0
	for i in range(0, l1):
		if blue[i] >= i + 1:
			continue
		else:
			flag = 1
			break
	for j in range(0, l2):
		if red[j] <= l1 + j + 1:
			continue
		else:
			flag = 1
			break
	if flag == 1:
		print('NO')
	else:
		print('YES')


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split(' ')))
	colors = input()
	segments = []
	for i in range(n):
		if colors[i] == 'R':
			if a[i] > n:
				continue
			segments.append((max(1, a[i]), n))
		else:
			if a[i] < 1:
				continue
			segments.append((1, a[i]))
	segments = sorted(segments, key=lambda x: (x[0], x[1] - x[0]))
	p = 0
	f = True
	for i in range(1, n + 1):
		if p >= len(segments):
			f = False
			break
		if i >= segments[p][0] and i <= segments[p][1]:
			p += 1
		else:
			f = False
			break
	print('YES' if f else 'NO')


t = int(input())
inf = -10 ** 17
ans = []
for _ in range(t):
	n = int(input())
	nums = [int(_) for _ in input().split()]
	color = input()
	red = []
	blue = []
	for i in range(n):
		if color[i] == 'R':
			red.append(nums[i])
		else:
			blue.append(nums[i])
	red.sort()
	blue.sort()
	(r, b) = (0, 0)
	for i in range(1, n + 1):
		if b < len(blue) and blue[b] >= i:
			b += 1
		elif r < len(red) and red[r] <= i:
			r += 1
		else:
			ans.append('NO')
			break
	else:
		ans.append('YES')
print('\n'.join(ans))


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	colors = input()
	blues = []
	reds = []
	for i in range(len(a)):
		if colors[i] == 'R':
			reds.append(a[i])
		else:
			blues.append(a[i])
	ind = 1
	blues.sort()
	reds.sort()
	flag = False
	for el in blues:
		if el < ind:
			flag = True
		ind += 1
	for el in reds:
		if el > ind:
			flag = True
		ind += 1
	if flag:
		print('NO')
	else:
		print('YES')


for i in range(int(input())):
	a = int(input())
	b = list(map(int, input().split()))
	c = list(input())
	q = []
	qr = []
	s = 0
	for i in range(a):
		if c[i] == 'B':
			q.append(b[i])
		if c[i] == 'R':
			qr.append(b[i])
	q.sort()
	qr.sort()
	x = len(q)
	y = len(qr)
	for i in range(y):
		q.append(qr[i])
	for i in range(x):
		if q[i] < i + 1:
			s += 1
	for i in range(x, x + y):
		if q[i] > i + 1:
			s += 1
	if s != 0:
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = input()
	red = []
	blue = []
	for i in range(n):
		if b[i] == 'R':
			red.append(a[i])
		else:
			blue.append(a[i])
	red.sort()
	blue.sort()
	c = 1
	f = False
	for i in range(len(blue)):
		if blue[i] < c:
			f = True
			break
		c += 1
	if f:
		print('NO')
		continue
	c = len(blue) + 1
	f = False
	for i in range(len(red)):
		if red[i] > c:
			f = True
			break
		c += 1
	if f:
		print('NO')
		continue
	print('YES')


_ = int(input())
for __ in range(_):
	n = int(input())
	a = list(map(int, input().split()))
	s = input()
	arr_r = []
	arr_b = []
	hit_1 = False
	hit_2 = False
	for x in range(n):
		if s[x] == 'R':
			arr_r.append(a[x])
		else:
			arr_b.append(a[x])
	arr_r = sorted(arr_r)
	arr_b = sorted(arr_b)
	l_arr_b = len(arr_b)
	l_arr_r = len(arr_r)
	for x in range(len(arr_b)):
		if arr_b[x] < x + 1:
			hit_1 = True
			break
	if not hit_1:
		for x in range(len(arr_r)):
			if arr_r[x] > x + l_arr_b + 1:
				hit_1 = True
				break
	for x in range(len(arr_r)):
		if arr_r[x] > x + 1:
			hit_2 = True
			break
	if not hit_2:
		for x in range(len(arr_b)):
			if arr_b[x] < x + l_arr_r + 1:
				hit_2 = True
				break
	if not hit_1 or not hit_2:
		print('YES')
	else:
		print('NO')


t = int(input())
for f in range(t):
	n = int(input())
	num = list(map(int, input().split()))
	color = input()
	B = list()
	R = list()
	for i in range(n):
		if color[i] == 'B':
			B.append(num[i])
		else:
			R.append(num[i])
	B.sort()
	R.sort()
	possible = True
	for i in range(1, len(B) + 1):
		if B[i - 1] >= i:
			possible = True
		else:
			possible = False
			break
	if possible:
		for i in range(1, len(R) + 1):
			if R[i - 1] <= i + len(B):
				possible = True
			else:
				possible = False
				break
	if possible:
		print('YES')
	else:
		print('NO')
t = t - 1


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')

def comp(item1, item2):
	if item1[0] < item2[1]:
		return -1
	else:
		return 1

def solve():
	n = int(input())
	a = list(map(int, input().strip().split()))[:n]
	c = input()
	copy = []
	for i in range(n):
		copy.append([a[i], c[i]])
	copy.sort(key=lambda x: x[0])
	left = []
	min_i = 1
	for i in range(n):
		if copy[i][1] == 'B':
			if min_i <= copy[i][0]:
				min_i += 1
			else:
				print('NO')
				return
		elif copy[i][1] == 'R':
			left.append(copy[i][0])
	if len(left) != 0:
		left.sort()
		left.reverse()
	for i in range(min_i, n + 1):
		if len(left) == 0 or left[-1] > i:
			print('NO')
			return
		else:
			left.pop()
	print('YES')
T = 1
T = int(input())
for _ in range(T):
	solve()


import sys
import bisect
import math
inp = sys.stdin.readline
input = lambda : inp().strip()

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	s = input()
	R = [a[i] for i in range(n) if s[i] == 'R']
	B = [a[i] for i in range(n) if s[i] == 'B']
	R.sort()
	B.sort()
	b = 0
	for i in B:
		if i >= b + 1:
			b += 1
		else:
			return 'NO'
	for i in R:
		if i <= b + 1:
			b += 1
		else:
			return 'NO'
	return 'YES'
t = int(input())
for _ in range(t):
	print(solve())


def solve(length, a, cols):
	reds = []
	blues = []
	for i in range(length):
		if cols[i] == 'R':
			reds.append(a[i])
		else:
			blues.append(a[i])
	reds = sorted(reds, reverse=True)
	blues = sorted(blues)
	for i in range(len(reds)):
		if length - reds[i] < i:
			return 'NO'
	for i in range(len(blues)):
		if blues[i] < i + 1:
			return 'NO'
	return 'YES'
t = int(input())
for _ in range(t):
	length = int(input())
	a = list(map(int, input().split()))
	cols = input()
	res = solve(length, a, cols)
	print(res)


from collections import deque
from typing import Counter
import sys
input = sys.stdin.readline
for _ in range(int(input().strip())):
	n = int(input().strip())
	arr = list(map(int, input().strip().split()))
	color = list(input().strip())
	val_col = deque()
	for i in range(n):
		val_col.append([arr[i], color[i]])
	val_col = sorted(val_col, key=lambda x: (x[1], x[0]))
	res = 'YES'
	for i in range(n):
		if val_col[i][1] == 'B' and val_col[i][0] < i + 1:
			res = 'NO'
		elif val_col[i][1] == 'R' and val_col[i][0] > i + 1:
			res = 'NO'
	print(res)


import math
from collections import Counter
import copy
t = int(input())
for _ in range(t):
	n = int(input())
	arr = [int(i) for i in input().split()]
	s = input()
	temp = []
	flag = 0
	for i in range(n):
		if s[i] == 'B':
			if arr[i] < 0:
				flag = 1
				break
			temp.append((1, min(n, arr[i])))
		else:
			if arr[i] > n:
				flag = 1
				break
			temp.append((max(1, arr[i]), n))
	if flag:
		print('NO')
	else:
		start = 0
		temp.sort()
		for i in range(n):
			(l, r) = temp[i]
			if l <= start + 1 <= r:
				start += 1
			else:
				flag = 1
				break
		if flag:
			print('NO')
		else:
			print('YES')


import sys

def solve(arr, n, red, blue):
	cr = len(red)
	cb = len(blue)
	for (num, i) in enumerate(blue):
		if i < num + 1:
			return False
	for (num, i) in enumerate(red):
		if i > cb + num + 1:
			return False
	return True
t = int(input())
for tt in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	s = input()
	red = []
	blue = []
	for (num, i) in enumerate(s):
		if i == 'R':
			red.append(arr[num])
		else:
			blue.append(arr[num])
	red.sort()
	blue.sort()
	ans = solve(arr, n, red, blue)
	if ans:
		print('YES')
	else:
		print('NO')


from sys import stdin, stdout
from collections import Counter
input = stdin.readline
for _ in range(int(input())):
	n = int(input())
	li = list(map(int, input().split()))
	p = input()
	flag = 0
	x = -pow(10, 9)
	m = pow(10, 9)
	ri = [0] * n
	bi = [0] * n
	for i in range(n):
		if p[i] == 'R':
			if li[i] > n:
				flag = 1
				break
		if p[i] == 'B':
			if li[i] < 1:
				flag = 1
				break
	if flag == 1:
		print('No')
	else:
		for i in range(n):
			if p[i] == 'R':
				if li[i] < 1:
					li[0] += 1
				else:
					ri[li[i] - 1] += 1
			if p[i] == 'B':
				if li[i] > n:
					bi[n - 1] += 1
				else:
					bi[li[i] - 1] += 1
		for i in range(1, n):
			ri[n - i - 1] = ri[n - i - 1] + ri[n - i]
		for i in range(1, n):
			bi[i] = bi[i] + bi[i - 1]
		for i in range(n):
			if ri[n - i - 1] > i + 1:
				flag = 1
				break
			if bi[i] > i + 1:
				flag = 1
				break
		if flag == 1:
			print('NO')
		else:
			print('YES')


def op():
	n = int(input())
	a = [int(i) for i in input().split()]
	colors = list(input())
	blue = []
	red = []
	for i in range(n):
		if colors[i] == 'B':
			blue.append(a[i])
		else:
			red.append(a[i])
	blue.sort()
	red.sort()
	for i in range(len(blue)):
		if blue[i] <= i:
			return 'No'
	m = n
	n = len(red)
	for i in range(n):
		if red[n - i - 1] > m - i:
			return 'No'
	return 'Yes'
o = []
for i in range(int(input())):
	o.append(op())
for i in o:
	print(i)


from heapq import heapify, heappush, heappop, heappushpop
from collections import defaultdict as dd, deque as dq, Counter as C
from math import factorial as f, ceil, gcd, sqrt, log
from bisect import bisect_left as bl, bisect_right as br
from itertools import combinations as c, permutations as p
from math import factorial as f, ceil, gcd, sqrt, log
from sys import stdin
input = stdin.readline
mp = lambda : map(int, input().split())
it = lambda : int(input())
ls = lambda : list(input().strip().split())
mt = lambda r: [ls() for _ in range(r)]
lcm = lambda a, b: a * b // gcd(a, b)
for _ in range(it()):
	a = it()
	b = list(mp())
	l = input().strip()
	inc = []
	dec = []
	for i in range(a):
		if l[i] == 'B':
			dec.append(b[i])
		else:
			inc.append(b[i])
	visited = [0] * (a + 1)
	dec.sort(reverse=True)
	ans = 'YES'
	i = 1
	while dec:
		cur = dec.pop()
		m = min(i, cur)
		if m > 0 and m <= a and (visited[m] == 0):
			visited[m] = 1
			i += 1
	inc.sort(reverse=True)
	while inc:
		cur = inc.pop()
		m = max(i, cur)
		if m > 0 and m <= a and (visited[m] == 0):
			visited[m] = 1
			i += 1
	for i in range(1, a + 1):
		if visited[i] == 0:
			ans = 'NO'
			break
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	num = list(map(int, input().split()))
	colors = input()
	red = []
	blue = []
	for j in range(n):
		if colors[j] == 'R':
			red.append(num[j])
		else:
			blue.append(num[j])
	red.sort()
	blue.sort()
	idxR = idxB = 0
	idxN = 1
	failed = False
	while idxR < len(red) or idxB < len(blue):
		if idxB < len(blue) and blue[idxB] < idxN:
			if idxR < len(red) and red[idxR] > idxN:
				failed = True
				break
			elif idxR == len(red):
				failed = True
				break
			else:
				idxR += 1
		elif idxB == len(blue):
			if red[idxR] > idxN:
				failed = True
				break
			else:
				idxR += 1
		else:
			idxB += 1
		idxN += 1
	if failed:
		print('NO')
	else:
		print('YES')


def solution():
	n = int(input())
	a = [(c, int(x)) for (x, c) in zip(input().split(), input())]
	print('YES') if all((x[0] == 'B' and x[1] >= i or (x[0] == 'R' and x[1] <= i) for (i, x) in enumerate(sorted(a), start=1))) else print('NO')
for _ in range(int(input())):
	solution()


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	s = input()
	f = 0
	fb = [0] * n
	fr = [0] * n
	for j in range(n):
		if s[j] == 'B':
			if a[j] >= 1:
				if a[j] <= n:
					fb[a[j] - 1] += 1
			else:
				f = 1
				break
		elif a[j] <= n:
			if a[j] >= 1:
				fr[a[j] - 1] += 1
		else:
			f = 1
			break
	for j in range(1, n):
		fb[j] += fb[j - 1]
	for j in range(n - 2, 0, -1):
		fr[j] += fr[j + 1]
	for j in range(n):
		if fb[j] > j + 1:
			f = 1
			break
		if fr[j] > n - j:
			f = 1
			break
	if f == 1:
		print('NO')
	else:
		print('YES')


def cf_753D(numbers: list, colors: list):
	blues = []
	reds = []
	for (num, color) in zip(numbers, colors):
		if color == 'B':
			blues.append(num)
		else:
			reds.append(num)
	blues.sort(reverse=True)
	reds.sort(reverse=True)
	temp = len(blues)
	for i in range(1, len(blues) + 1):
		num = blues.pop()
		if num < i:
			return False
	for i in range(temp + 1, len(numbers) + 1):
		num = reds.pop()
		if num > i:
			return False
	return True
for _ in range(int(input())):
	input()
	print('YES' if cf_753D(list(map(int, input().split())), list(input())) else 'NO')


import sys
input = sys.stdin.readline

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

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

def mps(A):
	return [tuple(map(int, input().split())) for _ in range(A)]
import math
import bisect
import heapq
from copy import deepcopy as dc
from itertools import accumulate
from collections import Counter, defaultdict, deque

def ceil(U, V):
	return (U + V - 1) // V

def modf1(N, MOD):
	return (N - 1) % MOD + 1
inf = int(1e+20)
mod = int(1000000000.0 + 7)
t = int(input())
for _ in range(t):
	n = int(input())
	a = lmp()
	b = []
	r = []
	br = input()[:-1]
	for i in range(n):
		if br[i] == 'B':
			b.append(a[i])
		else:
			r.append(a[i])
	b.sort()
	r.sort()
	l = len(b)
	f = True
	for i in range(1, l + 1):
		if b[i - 1] < i:
			f = False
	for i in range(l + 1, n + 1):
		if r[i - 1 - l] > i:
			f = False
	if f:
		print('YES')
	else:
		print('NO')


import math

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

def Ii():
	return int(input())

def infi():
	return float('Inf')

def mino():
	return -1

def solve(b, r, n):
	bp = 0
	rp = 0
	mi = 1
	while bp < len(b):
		if b[bp] < mi:
			print('NO')
			return
		if b[bp] >= mi:
			bp += 1
			mi += 1
	while rp < len(r):
		if r[rp] > mi:
			print('NO')
			return
		if r[rp] <= mi:
			rp += 1
			mi += 1
	print('YES')
	return
for ____ in range(Ii()):
	n = Ii()
	arr = list(II())
	s = input()
	b = []
	r = []
	for i in range(n):
		if s[i] == 'B':
			b.append(arr[i])
		else:
			r.append(arr[i])
	b.sort()
	r.sort()
	solve(b, r, n)


for _ in range(int(input())):
	n = int(input())
	nums = list(map(int, input().split()))
	(red, blue) = ([], [])
	for (k, c) in enumerate(input()):
		if c == 'B':
			blue.append(nums[k])
		else:
			red.append(nums[k])
	len_b = len(blue)
	red.sort()
	blue.sort()
	ans = 'YES'
	for (k, i) in enumerate(blue):
		if i < k + 1:
			ans = 'NO'
			break
	if ans == 'YES':
		for (k, i) in enumerate(red):
			if i > len_b + k + 1:
				ans = 'NO'
				break
	print(ans)


import sys

def input():
	return sys.stdin.readline().rstrip()
t = int(input())
for _ in range(t):
	n = int(input())
	lst = list(map(int, input().split()))
	col = input()
	(blu, red) = ([], [])
	for i in range(n):
		if col[i] == 'B':
			blu.append(lst[i])
		else:
			red.append(lst[i])
	blu.sort()
	red.sort(reverse=True)
	if blu and blu[0] < 1:
		print('NO')
		continue
	if red and red[0] > n:
		print('NO')
		continue
	(tmp, cur) = (0, 1)
	flag = False
	if blu:
		for num in blu:
			if 1 <= num <= n:
				tmp += 1
				if tmp > num:
					flag = True
					break
	if flag:
		print('NO')
		continue
	(tmp, cur) = (0, 1)
	if red:
		for num in red:
			if 1 <= num <= n:
				tmp += 1
				if tmp > n - num + 1:
					flag = True
					break
	if flag:
		print('NO')
		continue
	print('YES')


def solve():
	n = int(input())
	A = list(map(int, input().split()))
	s = input()
	B = []
	for i in range(n):
		(a, b) = (1, n)
		if s[i] == 'R':
			if A[i] > n:
				return 'NO'
			a = max(1, A[i])
		else:
			if A[i] < 1:
				return 'NO'
			b = min(n, A[i])
		B.append([a, b])
	B.sort()
	can = True
	for i in range(n):
		if B[i][0] <= i + 1 <= B[i][1]:
			(B[i][0], B[i][1]) = (B[i][1], B[i][0])
			continue
		else:
			can = False
		(B[i][0], B[i][1]) = (B[i][1], B[i][0])
	if can:
		return 'YES'
	B.reverse()
	can = True
	for i in range(n):
		if B[i][1] <= n - i <= B[i][0]:
			continue
		else:
			can = False
	if can:
		return 'YES'
	return 'NO'
for _ in range(int(input())):
	print(solve())


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	s = input()
	f = True
	lt = []
	gt = []
	for i in range(n):
		if s[i] == 'B':
			lt.append(a[i])
		else:
			gt.append(a[i])
	lt.sort()
	gt.sort()
	l = 0
	h = 0
	for i in range(1, n + 1):
		if l < len(lt) and i <= lt[l]:
			l += 1
		elif h < len(gt) and i >= gt[h]:
			h += 1
		else:
			f = False
			break
	print('Yes' if f else 'No')


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	inp = input()
	b = []
	r = []
	for i in range(n):
		if inp[i] == 'B':
			b.append(arr[i])
		else:
			r.append(arr[i])
	b.sort()
	r.sort()
	h = 0
	l = 0
	check = False
	for i in range(1, n + 1):
		if l < len(b) and i <= b[l]:
			l += 1
		elif h < len(r) and i >= r[h]:
			h += 1
		else:
			check = True
			break
	if check:
		print('No')
	else:
		print('Yes')


number_tests = int(input())
for test in range(number_tests):
	list_size = int(input())
	list_numbers = input().split()
	list_numbers = list(map(int, list_numbers))
	list_letters = input()
	result = 'YES'
	list_blue = []
	list_red = []
	for value in range(list_size):
		if list_letters[value] == 'B':
			list_blue.append(list_numbers[value])
		else:
			list_red.append(list_numbers[value])
	list_blue.sort()
	list_red.sort()
	for value in range(len(list_blue)):
		if list_blue[value] < value + 1:
			result = 'NO'
			break
	if result == 'YES':
		for value in range(len(list_blue), list_size):
			if list_red[value - len(list_blue)] > value + 1:
				result = 'NO'
				break
	print(result)


kl = int(input())
for kkl in range(kl):
	pr = 1
	n = int(input())
	ls = [int(i) for i in input().split()]
	s = input()
	r = []
	b = []
	for i in range(n):
		if s[i] == 'R':
			r += [ls[i]]
		else:
			b += [ls[i]]
	b.sort()
	if pr:
		for i in range(len(b)):
			if b[i] <= i and pr:
				print('NO')
				pr = 0
	if pr:
		r.sort()
		for i in range(len(r) - 1, -1, -1):
			if r[i] > n - (len(r) - i - 1) and pr:
				print('NO')
				pr = 0
	if pr:
		print('YES')


import sys
input = sys.stdin.readline
t = int(input())
while t > 0:
	n = int(input())
	a = list(map(int, input().split()))
	c = input().strip()
	(b, r) = ([], [])
	for i in range(n):
		if c[i] == 'R':
			r.append(a[i])
		else:
			b.append(a[i])
	b.sort()
	r.sort()
	x = 1
	f = True
	for i in b:
		if x > i:
			f = False
		x += 1
	for i in r:
		if x < i:
			f = False
		x += 1
	print('YES' if f else 'NO')
	t -= 1


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

def main(t):
	n = int(input())
	arr = list(map(int, input().split()))
	s = input()
	dec = []
	inc = []
	for i in range(n):
		if s[i] == ord('B'):
			dec.append(arr[i])
		else:
			inc.append(arr[i])
	inc.sort()
	dec.sort()
	i = 0
	d = 0
	needed = 1
	preneeded = needed
	while True:
		preneeded = needed
		while i < len(dec) and dec[i] >= needed:
			needed += 1
			i += 1
		if d < len(inc) and inc[d] <= needed:
			needed += 1
			d += 1
		if needed == preneeded:
			break
	if needed == n + 1:
		print('YES')
	else:
		print('NO')
T = int(input())
t = 1
while t <= T:
	main(t)
	t += 1


from __future__ import division, print_function
import math
import sys
import os
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')

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

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

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

def insr():
	s = input().strip()
	return list(s[:len(s)])

def invr():
	return map(int, input().split())
import itertools
from sys import maxsize, stdout, stdin, stderr
mod = int(1000000000.0 + 7)
import sys

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

def grid(r, c):
	return [lint() for i in range(r)]
from collections import defaultdict, Counter, deque
import math
import heapq
from heapq import heappop, heappush
import bisect
from math import factorial, inf
from itertools import groupby
from itertools import permutations as comb
mod = 1000000007
MOD = 998244353

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

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

def check_prime(n):
	for i in range(2, int(n ** (1 / 2)) + 1):
		if not n % i:
			return False
	return True

def primefactors(n):
	num = 0
	while n % 2 == 0:
		num += 1
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			num += 1
			n = n // i
	if n > 2:
		num += 1
	return num

def ask(a, b, c):
	print(c, a, b, flush=True)
	n = I()
	return n

def linear_sieve(n):
	is_composite = [False] * n
	prime = []
	for i in range(2, n):
		if not is_composite[i]:
			prime.append(i)
		for j in prime:
			is_composite[i * j] = True
			if i % prime == 0:
				break
	return prime

def dfs(i, p, d):
	(a, tmp) = (0, 0)
	for j in d[i]:
		if j != p:
			a += 1
			tmp += dfs(j, i)
	if a == 0:
		return 0
	return tmp / a + 1

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 binpow(a, b, c):
	res = 1
	a = a % c
	while b > 0:
		if b & 1:
			res = res * a % c
		b = b >> 1
		a = a * a % c
	return res
d = []
primes = []
prim = [0] * (10 ** 5 + 1)

def sieve(n):
	for i in range(n):
		d.append(i)
	for i in range(2, n):
		if d[i] == i:
			prim[i] = 1
			primes.append(i)
		j = 0
		while j < len(primes) and primes[j] <= d[i] and (primes[j] * i < n):
			d[i * primes[j]] = primes[j]
			j += 1

def primeFactors(n):
	factors = []
	while n != 1:
		factors.append(d[n])
		n //= d[n]
	return factors
t = 1
t = I()
for _ in range(t):
	n = I()
	s = lint()
	l = S()
	(r, b) = ([], [])
	flag = True
	for i in range(n):
		if l[i] == 'B':
			b.append(s[i])
			if s[i] <= 0:
				flag = False
				break
		else:
			r.append(s[i])
			if s[i] > n:
				flag = False
				break
	b.sort()
	r.sort(reverse=True)
	k = 1
	for i in range(len(b)):
		if b[i] < k:
			flag = False
		k += 1
	k = n
	r.sort(reverse=True)
	for j in range(len(r)):
		if r[j] > k:
			flag = False
		k -= 1
	if flag:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	string = str(input())
	n = len(string)
	blue = []
	red = []
	flag = True
	for i in range(n):
		if string[i] == 'B':
			blue.append(arr[i])
		else:
			red.append(arr[i])
	blue.sort()
	red.sort(reverse=True)
	for i in range(len(blue)):
		if blue[i] < i + 1:
			flag = False
	for i in range(len(red)):
		if red[i] > n - i:
			flag = False
	if flag:
		print('YES')
	else:
		print('NO')


def fun(arr, brr, n):
	temp = []
	for i in range(n):
		if arr[i] < 1 and brr[i] == 'B' or (arr[i] > n and brr[i] == 'R'):
			return False
		if brr[i] == 'B':
			temp.append((1, min(n, arr[i])))
		else:
			temp.append((max(1, arr[i]), n))
	temp.sort(key=lambda x: (x[0], x[1]))
	k = 1
	for x in temp:
		if k < x[0] or k > x[1]:
			return False
		k += 1
	return True
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	brr = input()
	if fun(arr, brr, n):
		print('Yes')
	else:
		print('No')


from sys import stdin

def read_input():
	n = int(stdin.readline().rstrip())
	a = list(map(int, stdin.readline().split()))
	c = stdin.readline().rstrip()
	return (n, a, c)

def solve(n, a, c):
	rods = []
	for i in range(n):
		if c[i] == 'B':
			if a[i] >= 1:
				left = 1
				right = min(n, a[i])
				rods.append((left, right))
		elif a[i] <= n:
			left = max(1, a[i])
			right = n
			rods.append((left, right))
	if len(rods) < n:
		return 'NO'
	rods.sort()
	for (i, rod) in enumerate(rods, 1):
		if not rod[0] <= i <= rod[1]:
			return 'NO'
	return 'YES'

def main():
	t = int(stdin.readline())
	for _ in range(t):
		input = read_input()
		answer = solve(*input)
		print(answer)
main()


from sys import stdin as f
t = int(next(f))
out = []

def solve(n, a, c):
	a = [[a[i], c[i]] for i in range(n)]
	red = [ai[0] for ai in a if ai[1] == 'R']
	blue = [ai[0] for ai in a if ai[1] == 'B']
	if any((r > n for r in red)) or any((b < 1 for b in blue)):
		return False
	for i in range(n):
		if a[i][1] == 'R':
			a[i][0] = max(1, a[i][0])
		else:
			a[i][0] = min(a[i][0], n)
	a.sort(key=lambda x: (x[1], x[0]))
	ans = True
	for i in range(n):
		if a[i][0] < i + 1 and a[i][1] == 'B':
			ans = False
			break
		if a[i][0] > i + 1 and a[i][1] == 'R':
			ans = False
			break
	return ans
	return 'YES' if ans else 'NO'
for _ in range(t):
	n = int(next(f))
	a = list(map(int, next(f).strip().split()))
	c = next(f).strip()
	ans = solve(n, a, c)
	out.append('yes' if ans else 'no')
print(*out, sep='\n')


import sys

def rall():
	return sys.stdin.readlines()

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

def rl_types(types):
	str_list = [x for x in sys.stdin.readline().strip().split(' ')]
	return [types[i](str_list[i]) for i in range(len(str_list))]

def pr(something=''):
	sys.stdout.write(str(something) + '\n')

def pra(array):
	sys.stdout.write(' '.join([str(x) for x in array]) + '\n')

def solve(array):
	return array
NT = int(rl())
for ti in range(NT):
	n = int(rl())
	array = list(map(int, rl().split(' ')))
	colors = rl()
	blues = sorted([array[i] for i in range(n) if colors[i] == 'B'])
	reds = sorted([array[i] for i in range(n) if colors[i] == 'R'], reverse=True)
	(reds_okay, blues_okay) = (True, True)
	for i in range(len(blues)):
		if blues[i] >= 1 + i:
			continue
		else:
			blues_okay = False
			break
	for i in range(len(reds)):
		if reds[i] <= n - i:
			continue
		else:
			reds_okay = False
	pr('YES' if blues_okay and reds_okay else 'NO')


num_lines = int(input())
for _ in range(num_lines):
	num_item = int(input())
	list_num = input().split(' ')
	list_num = list(map(int, list_num))
	list_color = input()
	list_red = []
	list_blue = []
	for i in range(num_item):
		if list_color[i] == 'B':
			list_blue.append(list_num[i])
		else:
			list_red.append(list_num[i])
	list_red.sort()
	list_blue.sort()
	list_num.sort()
	cur = 1
	for b in list_blue:
		if b >= cur:
			cur += 1
		else:
			break
	for r in list_red:
		if r <= cur:
			cur += 1
		else:
			break
	if cur == num_item + 1:
		print('YES')
	else:
		print('NO')


t = int(input())
for tc in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	s = input()
	r = []
	b = []
	for i in range(n):
		if s[i] == 'R':
			r.append(a[i])
		else:
			b.append(a[i])
	b.sort()
	r.sort()
	flag = 0
	for i in range(len(b)):
		if b[i] <= i:
			flag = 1
	for i in range(len(r) - 1, -1, -1):
		if r[i] > n:
			flag = 1
		n -= 1
	if flag:
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	input()
	a = list(map(int, input().split()))
	b = []
	r = []
	for (i, x) in enumerate(input()):
		if x == 'B':
			b.append(a[i])
		else:
			r.append(a[i])
	b.sort()
	r.sort()
	n = len(b)
	print('YES' if all((x >= i + 1 for (i, x) in enumerate(b))) and all((x <= n + i + 1 for (i, x) in enumerate(r))) else 'NO')


import bisect
import math
from collections import deque
import heapq
import functools
from collections import defaultdict
mod = 998244353
N = 200005
getnums = lambda : map(int, input().split())
getnum = lambda : int(input())

def mul(a, b):
	return a * b % mod

def add(a, b):
	return a + b if a + b < mod else a + b - mod

def sub(a, b):
	return a - b if a - b >= 0 else a - b + mod

def powr(a, b):
	ans = 1
	while b > 0:
		if b & 1:
			ans = mul(ans, a)
		a = mul(a, a)
		b //= 2
	return ans

def inv(n):
	return powr(n, mod - 2)

def factlist():
	fact = [1]
	for i in range(1, N):
		fact.append(mul(fact[i - 1], i))
	return fact

def invfactlist(fact):
	invfact = [0] * N
	invfact[0] = 1
	invfact[N - 1] = inv(fact[N - 1])
	for i in range(N - 2, 0, -1):
		invfact[i] = mul(invfact[i + 1], i + 1)
	return invfact

def rot(S):
	return list(zip(*S[::-1]))

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

def generate():
	ans = [0]
	while ans[-1] < 1000000000:
		ans.append(1 + ans[-1] * 2)
	return ans

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

def LcmOfArray(arr, idx):
	if idx == len(arr) - 1:
		return arr[idx]
	a = arr[idx]
	b = LcmOfArray(arr, idx + 1)
	return int(a * b / __gcd(a, b))
con = dict()

class Node:

	def __init__(self, val):
		self.val = val
		self.child = None
		self.parent = None

	def addrear(self, y):
		self.child = y
		y.parent = self

	def deleterear(self, y):
		self.child = None
		y.parent = None

	def findparent(self):
		parent = self.parent
		node = self
		while parent:
			node = parent
			parent = parent.parent
		return node

	def getelem(self):
		lst = [self.val]
		ch = self.child
		while ch:
			lst.append(ch.val)
			ch = ch.child
		return lst

def main():
	t = getnum()
	while t:
		t -= 1
		n = getnum()
		lst = list(getnums())
		s = input()
		rlst = []
		blst = []
		for i in range(n):
			if s[i] == 'R':
				rlst.append(lst[i])
			else:
				blst.append(lst[i])
		fl = True
		blst.sort()
		for i in range(len(blst)):
			if blst[i] < i + 1:
				fl = False
		rlst.sort()
		for i in range(len(rlst)):
			if rlst[i] > i + 1 + len(blst):
				fl = False
		print('YES') if fl else print('NO')
main()


def exists(a, b, n):
	R = []
	B = []
	for i in range(n):
		if b[i] == 'R':
			R.append(a[i])
		else:
			B.append(a[i])
	respuesta = 'YES'
	R = sorted(R)
	B = sorted(B)
	lenB = len(B)
	lenR = len(R)
	for i in range(lenB):
		if B[i] < i + 1:
			return 'NO'
	for i in range(lenR):
		if R[i] > lenB + i + 1:
			return 'NO'
	return respuesta

def split(s):
	ans = []
	for letter in s:
		ans.append(letter)
	return ans
t = int(input())
for i in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = split(input())
	print(exists(a, b, n))


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	s = input()
	arr_b = sorted([arr[i] for i in range(n) if s[i] == 'B'])
	arr_r = sorted([arr[i] for i in range(n) if s[i] == 'R'], reverse=True)
	res = True
	for i in range(len(arr_b)):
		if arr_b[i] < i + 1:
			res = False
			break
	if not res:
		print('NO')
		continue
	for i in range(len(arr_r)):
		if arr_r[i] > n - i:
			res = False
			break
	if res:
		print('YES')
	else:
		print('NO')


def solve(n, ls, s):
	blues = []
	reds = []
	i = 0
	while i < n:
		if s[i] == 'R':
			reds.append(ls[i])
		else:
			blues.append(ls[i])
		i += 1
	blues.sort(reverse=True)
	reds.sort(reverse=True)
	i = n
	ri = 0
	bi = 0
	while i >= 1:
		if ri < len(reds) and reds[ri] <= i:
			i -= 1
			ri += 1
			continue
		if bi < len(blues) and blues[bi] >= i:
			i -= 1
			bi += 1
			continue
		return 'NO'
	return 'YES'
t = int(input().strip())
inputs = []
for _ in range(t):
	n = int(input().strip())
	a = list(map(int, input().strip().split()))
	s = input().strip()
	inputs.append((n, a, s))
for inp in inputs:
	print(solve(*inp))


ram = int(input())
for jjd in range(ram):
	n = int(input())
	l = list(map(int, input().split()))
	s = input()
	r = []
	b = []
	for i in range(n):
		if s[i] == 'B':
			b.append(l[i])
		else:
			r.append(l[i])
	b.sort()
	r.sort()
	r = r[::-1]
	a = 0
	for i in range(len(b)):
		if b[i] < i + 1:
			print('NO')
			a = 1
			break
	if a == 0:
		for i in range(len(l) - 1, len(b) - 1, -1):
			if r[len(l) - i - 1] > i + 1:
				print('NO')
				a = 1
				break
	if a == 0:
		print('YES')


import math
t = int(input())
for _ in range(t):
	n = int(input())
	lst = list(map(int, input().split()))
	s = input()
	ss = []
	b = []
	for i in range(n):
		ss.append(s[i])
	res_lst = list(zip(ss, lst))
	res_lst.sort()
	i = 1
	for i in range(1, n + 1):
		if res_lst[i - 1][1] < i and res_lst[i - 1][0] == 'B':
			print('NO')
			break
		elif res_lst[i - 1][1] > i and res_lst[i - 1][0] == 'R':
			print('NO')
			break
	else:
		print('YES')


import sys
input = lambda : sys.stdin.readline().rstrip()
for _ in range(int(input())):
	N = int(input())
	A = list(map(int, input().split()))
	B = input()
	(D1, D2) = ([], [])
	for i in range(N):
		if B[i] == 'B':
			D1.append(A[i])
		else:
			D2.append(A[i])
	ans = True
	D1.sort()
	for i in range(1, len(D1) + 1):
		if D1[i - 1] < i:
			ans = False
			break
	if ans:
		D2.sort()
		for i in range(N, len(D1), -1):
			if D2[i - len(D1) - 1] > i:
				ans = False
				break
	if ans:
		print('YES')
	else:
		print('NO')


t = int(input())
for s in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	s = str(input())
	r = []
	b = []
	for j in range(n):
		if s[j] == 'R':
			r.append(a[j])
		else:
			b.append(a[j])
	r.sort(reverse=True)
	b.sort(reverse=True)
	k = len(r)
	for i in range(n):
		if i + 1 < n - k + 1:
			if b[-1] < i + 1:
				print('NO')
				k = -1
				break
			else:
				b.pop()
		elif r[-1] > i + 1:
			print('NO')
			k = -1
			break
		else:
			r.pop()
	if k != -1:
		print('YES')


t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	arrc = input()
	l1 = list()
	l2 = list()
	for j in range(n):
		if arrc[j] == 'B':
			l1.append(arr[j])
		else:
			l2.append(arr[j])
	l1.sort()
	l2.sort()
	fuck = True
	for j in range(len(l1)):
		if l1[j] < j + 1:
			fuck = False
			break
	for j in range(len(l2)):
		if l2[j] > j + 1 + len(l1):
			fuck = False
			break
	if fuck:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	n = int(input())
	mass = list(map(int, input().split()))
	cl = input()
	(b, r) = ([], [])
	for i in range(n):
		if cl[i] == 'R':
			r.append(mass[i])
		else:
			b.append(mass[i])
	b.sort()
	r.sort()
	(a1, a2) = (0, 0)
	flag = 0
	for i in range(1, n + 1):
		if a1 < len(b) and b[a1] >= i:
			a1 += 1
		elif a2 < len(r) and r[a2] <= i:
			a2 += 1
		else:
			flag = 1
			break
	if flag == 0:
		print('YES')
	else:
		print('NO')


import os
import sys
from io import BytesIO, IOBase
from math import cos, pi, ceil, pi, tan, floor, gcd, sqrt, log2, factorial, log10
from collections import Counter
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase
from statistics import mean, median, mode
from bisect import *
alpha = ascii_lowercase
beta = ascii_uppercase

def nextPowerOf2(n):
	p = 1
	if n and (not n & n - 1):
		return n
	while p < n:
		p <<= 1
	return p

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

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

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

def Sieve(n):
	prime = [True for i in range(n + 1)]
	prime[0] = False
	prime[1] = False
	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

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 create_matrix(n, m):
	mat = [[] for i in range(n)]
	for i in range(n):
		for j in range(m):
			mat[i].append(0)
	return mat

def main():
	for ttt in range(int(input())):
		n = int(input())
		arr = list(map(int, input().split()))
		s = input()
		res = []
		ans = []
		for i in range(n):
			if s[i] == 'B':
				res.append([arr[i], 'B'])
			else:
				ans.append([arr[i], 'R'])
		ans.sort()
		res.sort()
		ss = res + ans
		for i in range(n):
			if ss[i][1] == 'B' and ss[i][0] >= i + 1:
				ss[i][0] = i + 1
			elif ss[i][1] == 'R' and ss[i][0] <= i + 1:
				ss[i][0] = i + 1
		for i in range(n):
			if ss[i][0] != i + 1:
				print('NO')
				break
		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()


def main():
	T = int(input())
	for t in range(T):
		run()

def run():
	n = int(input())
	nums = list(map(int, input().split(' ')))
	colors = input()
	red = sorted(list((num for (i, num) in enumerate(nums) if colors[i] == 'R')))
	blue = sorted(list((num for (i, num) in enumerate(nums) if colors[i] == 'B')))
	for i in range(n, 0, -1):
		if red and red[-1] > i:
			print('NO')
			break
		if red and red[-1] <= i:
			red.pop(-1)
		elif blue and blue[-1] >= i:
			blue.pop(-1)
		else:
			print('NO')
			break
	if not red and (not blue):
		print('YES')
main()


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	s = input()

	def fun():
		r = []
		b = []
		for i in range(n):
			if s[i] == 'B':
				b.append(l[i])
			else:
				r.append(l[i])
		b.sort()
		r.sort()
		m = len(b)
		for i in range(1, m + 1):
			if b[i - 1] < i:
				return False
		for i in range(len(r)):
			if r[i] > m + 1 + i:
				return False
		return True
	if fun():
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	c = input()
	(i, j) = (1, n)
	a = [[arr[k], c[k]] for k in range(n)]
	a.sort()
	for k in range(n):
		if a[k][0] >= i and a[k][1] == 'B':
			i += 1
	for k in range(n - 1, -1, -1):
		if a[k][0] <= j and a[k][1] == 'R':
			j -= 1
	if i > j:
		print('Yes')
	else:
		print('No')


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	s = input()
	flag = True
	b = []
	r = []
	for i in range(n):
		if s[i] == 'B':
			b.append(l[i])
		else:
			r.append(l[i])
	b.sort()
	r.sort()
	lenb = len(b)
	for i in range(1, lenb + 1):
		if b[i - 1] < i:
			flag = False
	for i in range(lenb + 1, n + 1):
		if r[i - lenb - 1] > i:
			flag = False
	if flag == True:
		print('YES')
	else:
		print('NO')


import sys
import math
import collections
import heapq
dy = [1, 0, -1, 0]
dx = [0, 1, 0, -1]
r = lambda : sys.stdin.readline().rstrip()
MIS = lambda : map(int, r().split())
for _ in range(int(r())):
	N = int(r())
	L = list(MIS())
	C = list(r())
	BB = 0
	cant = 0
	RR = 0
	B = []
	R = []
	for i in range(N):
		if C[i] == 'B':
			B.append(L[i])
		else:
			R.append(L[i])
	B.sort()
	R.sort(reverse=1)
	bt = 1
	rt = N
	ans = 0
	for i in range(len(B)):
		if B[i] >= bt:
			ans += 1
			bt += 1
	for i in range(len(R)):
		if R[i] <= rt:
			ans += 1
			rt -= 1
	if ans == N:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	s = list(input())
	inc = [0 for i in range(n + 1)]
	flag = 1
	for i in range(n):
		if a[i] <= 0 and s[i] == 'B':
			flag = 0
			break
		if a[i] > n and s[i] == 'R':
			flag = 0
			break
	for i in range(n):
		if s[i] == 'R' and a[i] >= 1 and (a[i] <= n):
			inc[a[i]] += 1
	c = 0
	j = 1
	for i in range(n, 0, -1):
		c += inc[i]
		if c > j:
			flag = 0
			break
		j += 1
	dec = [0 for i in range(n + 1)]
	for i in range(n):
		if s[i] == 'B' and a[i] >= 1 and (a[i] <= n):
			dec[a[i]] += 1
	c = 0
	for i in range(1, n + 1):
		c += dec[i]
		if c > i:
			flag = 0
			break
	if flag == 0:
		print('NO')
		continue
	print('YES')


t = int(input())
for _ in range(t):
	n = int(input())
	values = list(map(int, input().split()))
	color = input()
	blue = []
	red = []
	for (v, c) in zip(values, color):
		if c == 'B':
			blue.append(v)
		else:
			red.append(v)
	blue.sort()
	red.sort()
	found1 = True
	found2 = True
	for i in range(len(blue)):
		if blue[i] < i + 1:
			found1 = False
			break
	i = len(blue) + 1
	for j in range(len(red)):
		if red[j] > i:
			found2 = False
			break
		i += 1
	if found1 and found2:
		print('YES')
	else:
		print('NO')


def blue_red(n, num, color):
	redlist = [0 for i in range(n)]
	bluelist = [0 for i in range(n)]
	if n == 1:
		if color == 'R':
			return int(num[0]) <= 1
		if color == 'B':
			return int(num[0]) >= 1
	for i in range(n):
		k = int(num[i])
		if color[i] == 'B':
			if k < 1:
				return False
			if k >= n:
				bluelist[-1] += 1
			if k >= 1 and k < n:
				bluelist[k - 1] += 1
		else:
			if k > n:
				return False
			if k <= 1:
				redlist[-1] += 1
			if k <= n and k > 1:
				redlist[n - k] += 1
	current_blue = 0
	for i in range(len(bluelist)):
		current_blue += bluelist[i]
		if current_blue > i + 1:
			return False
	current_red = 0
	for i in range(len(redlist)):
		current_red += redlist[i]
		if current_red > i + 1:
			return False
	return True
total = int(input())
for i in range(total):
	n = int(input())
	num = input().split()
	color = input()
	x = blue_red(n, num, color)
	if x:
		print('YES')
	else:
		print('NO')


from collections import *
for y in range(int(input())):
	n = int(input())
	lst = list(map(int, input().split()))
	s = input()
	t = 1
	lst1 = []
	lst2 = []
	ans = 'YES'
	for i in range(n):
		if s[i] == 'B':
			lst1.append(lst[i])
		else:
			lst2.append(lst[i])
	lst1.sort()
	lst2.sort()
	for i in lst1:
		if i >= t:
			t += 1
		else:
			ans = 'NO'
			t += 1
	for i in lst2:
		if i <= t:
			t += 1
		else:
			ans = 'NO'
			t += 1
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	A = [int(i) for i in input().split()]
	color = input()
	(R, B) = ([], [])
	for (i, a) in enumerate(A):
		if color[i] == 'R':
			R.append(a)
		else:
			B.append(a)
	R.sort()
	B.sort()
	for i in range(len(B)):
		if i + 1 > B[i]:
			print('NO')
			break
	else:
		for i in range(len(R)):
			if i + len(B) + 1 < R[i]:
				print('NO')
				break
		else:
			print('YES')


def f():
	n = int(input())
	a = list(map(int, input().split()))
	col = input()
	b = list()
	r = list()
	for i in range(n):
		if col[i] == 'B':
			b.append(a[i])
		else:
			r.append(a[i])
	b.sort()
	cntb = len(b)
	for i in range(cntb):
		if b[i] <= i:
			print('NO')
			return
	r.sort(reverse=True)
	cntr = len(r)
	for i in range(cntr):
		if r[i] > n - i:
			print('NO')
			return
	print('YES')
t = int(input())
for i in range(t):
	f()


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	s = str(input())
	b = []
	r = []
	f = 0
	for i in range(n):
		if s[i] == 'B':
			b.append(l[i])
		else:
			r.append(l[i])
	s = [x for x in range(1, n + 1)]
	bl = s[:len(b)]
	rl = s[len(b):]
	b.sort()
	r.sort()
	for i in range(len(b)):
		if b[i] >= bl[i]:
			continue
		else:
			f = 1
			break
	for i in range(len(r)):
		if r[i] <= rl[i]:
			continue
		else:
			f = 1
			break
	if f == 1:
		print('NO')
	else:
		print('YES')


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	colors = input()
	vse = []
	for j in range(len(a)):
		vse.append([a[j], colors[j]])
	vse.sort()
	cursorB = 0
	cursorR = 0
	fin = 'YES'
	for j in range(n):
		if vse[j][1] == 'B':
			if cursorB >= vse[j][0]:
				fin = 'NO'
				break
			cursorB += 1
		if vse[n - 1 - j][1] == 'R':
			if n - cursorR < vse[n - 1 - j][0]:
				fin = 'NO'
				break
			cursorR += 1
	print(fin)


n = int(input())
for dgfjd in range(n):
	lenn = int(input())
	lst = list(map(int, input().split()))
	s = list(input())
	blue = []
	red = []
	for i in range(lenn):
		if s[i] == 'B':
			blue.append(lst[i])
		else:
			red.append(lst[i])
	blue = sorted(blue)
	red = sorted(red)
	q = False
	b = 0
	r = 0
	q = True
	for i in range(1, lenn + 1):
		if b < len(blue) and blue[b] >= i:
			b += 1
		elif r < len(red) and red[r] <= i:
			r += 1
		else:
			q = False
			print('NO')
			break
	if q:
		print('YES')


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	s = input()
	b = [[a[j], s[j]] for j in range(n)]
	b.sort()
	l = 1
	r = n
	flag = True
	for j in range(n):
		if b[j][1] == 'B':
			if l > b[j][0]:
				flag = False
				break
			else:
				l += 1
		if b[n - j - 1][1] == 'R':
			if r < b[n - j - 1][0]:
				flag = False
				break
			else:
				r -= 1
	if flag:
		print('YES')
	else:
		print('NO')


def maxmin(A, D, C):
	stat = False
	E = {'B': [], 'R': []}
	for i in range(A):
		if C[i] == 'B':
			E['B'].append(D[i])
		else:
			E['R'].append(D[i])
	E['B'].sort()
	E['R'].sort()
	cur = 1
	for j in E['B']:
		if j >= cur:
			cur += 1
		else:
			stat = True
			break
	for k in E['R']:
		if k <= cur:
			cur += 1
		else:
			stat = True
			break
	if not stat:
		return 'YES'
	else:
		return 'NO'
T = int(input())
for _ in range(T):
	N = int(input())
	X = list(map(int, input().split()))
	y = str(input())
	Y = list(y.strip())
	print(maxmin(N, X, Y))


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	s = input()
	red = []
	blue = []
	xy = 0
	for i in range(n):
		if s[i] == 'R':
			red.append(a[i])
		else:
			blue.append(a[i])
	red.sort()
	blue.sort()
	ans = 1
	for i in range(len(blue)):
		if ans <= blue[i]:
			ans += 1
		else:
			print('NO')
			xy = 1
			break
	if xy == 0:
		for i in range(len(red)):
			if ans >= red[i]:
				ans += 1
			else:
				print('NO')
				xy = 1
				break
	if xy == 0:
		print('YES')


import sys
import os.path
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
	sys.stderr = open('error.txt', 'w')
depth = 1000000
mod = 1000000007
lim = mod * mod
sys.setrecursionlimit(depth)
linp = lambda : list(minp())
minp = lambda : map(int, input().split())
from math import inf, ceil, sqrt, log2, gcd
from collections import defaultdict, deque
dxy = [(1, 0), (-1, 0), (0, 1), (0, -1)]
for _ in range(int(input())):
	n = int(input())
	(a, s) = (linp(), input())
	(blue, red) = ([], [])
	for i in range(n):
		if s[i] == 'B':
			blue.append(a[i])
		else:
			red.append(a[i])
	red.sort(reverse=True)
	v = [False for _ in range(n + 1)]
	j = n
	for e in red:
		while v[j] != False and j >= e:
			j -= 1
		if j >= e:
			v[j] = True
		j -= 1
	i = 1
	blue.sort()
	for e in blue:
		while v[i] != False and i <= e:
			i += 1
		if i <= e:
			v[i] = True
		i += 1
	v = v[1:]
	if all(v):
		print('YES')
	else:
		print('NO')


import math

def solve():
	n = int(input())
	l = list(map(int, input().split()))
	s = input()
	red = []
	blue = []
	for i in range(n):
		if s[i] == 'R':
			red.append(l[i])
		else:
			blue.append(l[i])
	red.sort()
	blue.sort()
	rn = len(red)
	bn = len(blue)
	f = 1
	for i in range(1, n + 1):
		if i <= bn:
			if blue[i - 1] < i:
				f = 0
				break
		elif red[i - bn - 1] > i:
			f = 0
			break
	if f:
		print('YES')
	else:
		print('NO')
for testis in range(int(input())):
	solve()


for _ in range(int(input())):
	n = int(input())
	l = input().split()
	s = input()
	(b, r) = ([], [])
	for i in range(n):
		x = int(l[i])
		if s[i] == 'R':
			r.append(x)
		else:
			b.append(x)
	if any((i > j for (i, j) in enumerate(sorted(b), 1))) or any((j > i for (i, j) in enumerate(sorted(r), n + 1 - len(r)))):
		print('NO')
	else:
		print('YES')


def solve():
	n = int(input())
	arr = [int(x) for x in input().split()]
	colors = list(input())
	b = [arr[i] for i in range(n) if colors[i] == 'B']
	b.sort()
	r = [arr[i] for i in range(n) if colors[i] == 'R']
	r.sort(reverse=True)
	r = [n - i >= r[i] for i in range(len(r))]
	b = [i + 1 <= b[i] for i in range(len(b))]
	if all(b + r):
		return 'YES'
	return 'NO'
for _ in range(int(input())):
	print(solve())


for _ in range(int(input())):
	n = int(input())
	x = list(map(int, input().split()))
	s = input()
	for i in range(n):
		x[i] = [x[i], s[i]]
	x = sorted(x, key=lambda x: (x[1] == 'R', x[0]))
	ans = 'YES'
	for i in range(n):
		if x[i][1] == 'B' and x[i][0] < i + 1:
			ans = 'NO'
		if x[i][1] == 'R' and x[i][0] > i + 1:
			ans = 'NO'
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	list1 = list(map(int, input().strip().split()))
	list2 = list(input())
	b = []
	r = []
	for i in range(n):
		if list2[i] == 'B':
			b.append(list1[i])
		else:
			r.append(list1[i])
	b.sort()
	flag = 1
	for i in range(len(b)):
		if b[i] < i + 1:
			flag = 0
			break
	if flag:
		r.sort()
		r.reverse()
		for i in range(len(r)):
			if r[i] > n - i:
				flag = 0
				break
	if flag:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	m = input()
	b = []
	r = []
	for j in range(len(a)):
		if m[j] == 'B':
			b.append(a[j])
		else:
			r.append(a[j])
	ok = True
	r.sort(reverse=True)
	b.sort()
	for j in range(len(r)):
		if r[j] > n - j:
			ok = False
	for j in range(len(b)):
		if b[j] < j + 1:
			ok = False
	if ok == True:
		print('YES')
	else:
		print('NO')


for t in range(int(input())):
	n = int(input())
	lis = list(map(int, input().split()))
	s = input()
	red = []
	blue = []
	for i in range(n):
		if s[i] == 'R':
			red.append(lis[i])
		else:
			blue.append(lis[i])
	red.sort()
	blue.sort()
	r_pointer = b_pointer = 0
	val = 1
	flag = 0
	while (r_pointer < len(red) or b_pointer < len(blue)) and val <= n:
		if b_pointer < len(blue) and blue[b_pointer] >= val:
			b_pointer += 1
		elif r_pointer < len(red) and red[r_pointer] <= val:
			r_pointer += 1
		else:
			flag = 1
			break
		val += 1
	if flag == 1 or val < n:
		print('NO')
	else:
		print('YES')


t = int(input())
for test in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	colors = input()
	blue = []
	red = []
	for i in range(n):
		if colors[i] == 'R':
			red.append(arr[i])
		else:
			blue.append(arr[i])
	blue.sort()
	red.sort()
	need = 1
	possible = True
	for i in blue:
		if i >= need:
			need += 1
		else:
			possible = False
			break
	for i in red:
		if i <= need:
			need += 1
		else:
			possible = False
			break
	if possible:
		print('YES')
	else:
		print('NO')


import sys
import time
import os
from io import BytesIO, IOBase
import math
from random import randint
M = 10 ** 9 + 7
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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

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

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

def get_ints():
	return list(map(int, inputf().split()))

def get_string():
	return list(map(str, inputf().split()))
global maximum

def _lis(arr, n):
	global maximum
	if n == 1:
		return 1
	maxEndingHere = 1
	for i in range(1, n):
		res = _lis(arr, i)
		if arr[i - 1] < arr[n - 1] and res + 1 > maxEndingHere:
			maxEndingHere = res + 1
	maximum = max(maximum, maxEndingHere)
	return maxEndingHere

def LIS(arr):
	global maximum
	n = len(arr)
	maximum = 1
	_lis(arr, n)
	return maximum

def binary_search(data, elem):
	low = 0
	high = len(data) - 1
	while low <= high:
		middle = (low + high) // 2
		if data[middle] == elem:
			return middle
		elif data[middle] > elem:
			high = middle - 1
		else:
			low = middle + 1
	return middle

def upper_bound(my_list, key):
	large = len(my_list) - 1
	small = 0
	while small <= large:
		mid = (small + large) // 2
		if my_list[mid] < key:
			small = mid + 1
		elif my_list[mid] > key:
			large = mid - 1
		else:
			return mid
	if my_list[mid] > key:
		return mid
	else:
		return mid + 1

def lower_bound(my_list, key):
	large = len(my_list) - 1
	small = 0
	while small <= large:
		mid = (small + large) // 2
		if my_list[mid] < key:
			small = mid + 1
		elif my_list[mid] > key:
			large = mid - 1
		else:
			return mid
	if my_list[mid] < key:
		return mid
	else:
		return mid - 1
a = []

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
	for p in range(2, n + 1):
		if prime[p]:
			a.append(p)

def roman_number(x):
	if x > 15999:
		return
	value = [5000, 4000, 1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1]
	symbol = ['F', 'MF', 'M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', 'I']
	roman = ''
	i = 0
	while x > 0:
		div = x // value[i]
		x = x % value[i]
		while div:
			roman += symbol[i]
			div -= 1
		i += 1
	return roman

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

def prefixSum(test_list):
	res = [sum(test_list[:i + 1]) for i in range(len(test_list))]
	return res

def lcm(x, y):
	if x > y:
		greater = x
	else:
		greater = y
	while True:
		if greater % x == 0 and greater % y == 0:
			lcm = greater
			break
		greater += 1
	return lcm
testcase = int(inputf())
for test in range(testcase):
	n = int(inputf())
	a = get_ints()
	color = inputf()
	blue = []
	red = []
	for i in range(0, n):
		if color[i] == 'R':
			red.append(a[i])
		else:
			blue.append(a[i])
	blue.sort()
	red.sort(reverse=True)
	left = 1
	right = n
	stop = False
	for num in blue:
		if num >= left:
			left += 1
		else:
			print('NO')
			stop = True
			break
	if stop == False:
		for num in red:
			if num <= right:
				right -= 1
			else:
				print('NO')
				break
		else:
			print('YES')


from itertools import product, combinations
from math import sqrt, gcd, ceil
INF = int(1000000000.0 + 1)
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	s = input()
	r = []
	b = []
	for i in range(n):
		if s[i] == 'R':
			r.append(a[i])
		else:
			b.append(a[i])
	nr = len(r)
	nb = len(b)
	r.sort()
	b.sort()
	ans = True
	for i in range(nr):
		if r[nr - i - 1] > n - i:
			ans = False
	for i in range(nb):
		if b[i] < i + 1:
			ans = False
	if ans:
		print('YES')
	else:
		print('NO')


from __future__ import division, print_function
import math
import sys
import os
from io import BytesIO, IOBase
from collections import deque, Counter, OrderedDict, defaultdict
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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

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

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

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

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

def insr():
	s = input().strip()
	return list(s[:len(s)])

def invr():
	return map(int, input().split())
for _ in range(inp()):
	n = inp()
	l = inlt()
	s = insr()
	flag = 1
	for i in range(n):
		if s[i] == 'R' and l[i] > n:
			flag = 0
			break
		elif s[i] == 'B' and l[i] < 1:
			flag = 0
			break
	dr = defaultdict(lambda : 0)
	db = defaultdict(lambda : 0)
	for i in range(n):
		if s[i] == 'R':
			dr[l[i]] += 1
		elif s[i] == 'B':
			db[l[i]] += 1
	if flag:
		cntr = 0
		cntb = 0
		for i in range(n, 0, -1):
			cntr += dr[i]
			if cntr > n - i + 1:
				flag = 0
				break
		for i in range(1, n + 1):
			cntb += db[i]
			if cntb > i:
				flag = 0
				break
		if flag:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


def blue_red_permutation(n, a, s):
	reds = []
	blues = []
	for i in range(n):
		if s[i] == 'B':
			blues += [a[i]]
		else:
			reds += [a[i]]
	blues.sort()
	for i in range(1, len(blues) + 1):
		if blues[i - 1] < i:
			print('NO')
			return
	reds.sort(reverse=True)
	for i in range(len(reds)):
		if reds[i] > n - i:
			print('NO')
			return
	print('YES')
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	s = input()
	blue_red_permutation(n, a, s)