An integer array $a_1, a_2, \ldots, a_n$ is being transformed into an array of lowercase English letters using the following prodecure:

While there is at least one number in the array:

Choose any number $x$ from the array $a$, and any letter of the English alphabet $y$.

Replace all occurrences of number $x$ with the letter $y$.

For example, if we initially had an array $a = [2, 3, 2, 4, 1]$, then we could transform it the following way:

Choose the number $2$ and the letter c. After that $a = [c, 3, c, 4, 1]$.

Choose the number $3$ and the letter a. After that $a = [c, a, c, 4, 1]$.

Choose the number $4$ and the letter t. After that $a = [c, a, c, t, 1]$.

Choose the number $1$ and the letter a. After that $a = [c, a, c, t, a]$.

After the transformation all letters are united into a string, in our example we get the string "cacta".

Having the array $a$ and the string $s$ determine if the string $s$ could be got from the array $a$ after the described transformation?


-----Input-----

The first line contains a single integer $t$ $(1 \leq t \leq 10^3$) — the number of test cases.

Then the description of the test cases follows.

The first line of each test case contains a single integer $n$ ($1 \leq n \leq 50$) — the length of the array $a$ and the string $s$.

The second line of each test case contains exactly $n$ integers: $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 50$) — the elements of the array $a$.

The third line of each test case contains a string $s$ of length $n$, consisting of lowercase English letters.


-----Output-----

For each test case, output "YES", if we can get the string $s$ from the array $a$, and "NO" otherwise. You can output each letter in any case.


-----Examples-----

Input
7
5
2 3 2 4 1
cacta
1
50
a
2
11 22
ab
4
1 2 2 1
aaab
5
1 2 3 2 1
aaaaa
6
1 10 2 9 3 8
azzfdb
7
1 2 3 4 1 1 2
abababb
Output
YES
YES
YES
NO
YES
YES
NO


-----Note-----

The first test case corresponds to the sample described in the statement.

In the second test case we can choose the number $50$ and the letter a.

In the third test case we can choose the number $11$ and the letter a, after that $a = [a, 22]$. Then we choose the number $22$ and the letter b and get $a = [a, b]$.

In the fifth test case we can change all numbers one by one to the letter a.

Difficulty: EASY
Tags: Implementation

Greedy algorithms
Skill types: Greedy algorithms

Starter code:

Solutions:
def proccess(length, llist, stringo):
	diction = {}
	for i in range(length):
		if llist[i] in diction and stringo[i] == diction[llist[i]]:
			continue
		elif llist[i] not in diction:
			diction[llist[i]] = stringo[i]
		else:
			print('NO')
			return
	print('YES')
test_cases = int(input())
for _ in range(test_cases):
	length = input()
	llist = input().split()
	stringo = input()
	proccess(int(length), llist, stringo)


def foo(n, ls, s):
	d = {}
	for i in range(n):
		if ls[i] in d:
			if d[ls[i]] != s[i]:
				return False
		else:
			d[ls[i]] = s[i]
	return True
t = int(input())
for _ in range(t):
	n = int(input())
	ls = [int(i) for i in input().split()]
	s = input()
	if foo(n, ls, s):
		print('YES')
	else:
		print('NO')


import sys
t = int(sys.stdin.readline())
for test in range(t):
	n = int(sys.stdin.readline())
	a = list(map(int, sys.stdin.readline().split()))
	s = list(sys.stdin.readline().strip())
	dic = {}
	ans = True
	for i in range(n):
		if a[i] not in dic:
			dic[a[i]] = s[i]
		elif dic[a[i]] != s[i]:
			ans = False
			break
	if ans:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	k = int(input())
	li = list(map(int, input().split()))
	s = list(input())
	fr = dict()
	chec = 1
	for i in range(len(li)):
		if li[i] not in fr:
			fr[li[i]] = s[i]
		else:
			temp = fr[li[i]]
			if temp != s[i]:
				chec = 0
				break
	if not chec:
		print('NO')
	else:
		print('YES')


from sys import stdin, stdout
t = int(stdin.readline().strip())
for _ in range(t):
	n = int(stdin.readline().strip())
	arr = list(map(int, stdin.readline().split()))
	s = stdin.readline().strip()
	mapping = {}
	match = True
	for i in range(n):
		if arr[i] in mapping:
			if s[i] != mapping[arr[i]]:
				match = False
				break
		else:
			mapping[arr[i]] = s[i]
	print('YES' if match else 'NO')


import math
import collections
import bisect
import heapq
from collections import deque
from math import sqrt, ceil, floor

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

def inp_str_arr():
	return list(input().strip().split(' '))

def inp_str():
	return input()

def solve():
	(n,) = inp_arr()
	a = inp_arr()
	s = inp_str()
	mp = {}
	n = len(a)
	for i in range(n):
		if a[i] not in mp:
			mp[a[i]] = s[i]
		elif mp[a[i]] != s[i]:
			print('NO')
			return
	print('YES')
	return
(tt,) = inp_arr()
for t in range(tt):
	solve()


import math
t = int(input())
while t > 0:
	n = int(input())
	arr = list(map(int, input().split()))
	s = input()
	map1 = {}
	false = False
	for i in range(n):
		char = s[i]
		val = arr[i]
		if val not in map1:
			map1[val] = char
		elif map1[val] == char:
			continue
		else:
			false = True
			break
	if false:
		print('NO')
	else:
		print('YES')
	t -= 1


tc = int(input())
for _ in range(tc):
	n = int(input())
	a = [int(x) for x in input().split()]
	s = input()
	ans = True
	m = {}
	for i in range(n):
		if a[i] in m:
			if m[a[i]] != s[i]:
				ans = False
				break
		else:
			m[a[i]] = s[i]
	print('YES' if ans else 'NO')


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	s = input()
	d = {}
	c = 0
	for i in range(n):
		if l[i] in d:
			if d[l[i]] != s[i]:
				c = c + 1
		else:
			d[l[i]] = s[i]
	if c == 0:
		print('YES')
	else:
		print('NO')


def tr(l, s):
	d = dict()
	for i in range(len(l)):
		if d.get(l[i], s[i]) != s[i]:
			return False
		d[l[i]] = s[i]
	return True
t = int(input())
for _ in range(t):
	f = dict()
	n = int(input())
	l = list(map(int, input().split()))
	s = input()
	print('YES' if tr(l, s) else 'NO')


for _ in range(int(input())):
	n = int(input())
	y = {}
	x = input().split()
	a = input()
	for i in range(n):
		if x[i] in y:
			if y[x[i]] != a[i]:
				print('NO')
				break
		else:
			y[x[i]] = a[i]
	else:
		print('YES')


for _ in range(int(input())):
	a = int(input())
	b = [int(i) for i in input().split()]
	c = input()
	d = {}
	check = True
	for i in range(a):
		if b[i] in d.keys():
			if d[b[i]] != c[i]:
				check = False
				break
		else:
			d[b[i]] = c[i]
	if check:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	n = int(input())
	arr = [int(x) for x in input().split()]
	s = input()
	dct = {}
	ans = True
	for i in range(n):
		if arr[i] in dct and dct[arr[i]] != s[i]:
			ans = False
			break
		dct[arr[i]] = s[i]
	if ans:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	s = input()
	d = {}
	done = False
	for i in range(n):
		if arr[i] in d:
			if d[arr[i]] != s[i]:
				print('NO')
				done = True
				break
		else:
			d[arr[i]] = s[i]
	if not done:
		print('YES')


import math
t = int(input())
for test in range(t):
	arrLength = int(input())
	arr = list(map(int, input().split()))
	myStr = input()
	myDict = {}
	answ = True
	for ind in range(len(arr)):
		if arr[ind] not in myDict:
			myDict[arr[ind]] = myStr[ind]
		elif myDict[arr[ind]] != myStr[ind]:
			answ = False
	if answ:
		print('YES')
	else:
		print('NO')


import sys
from collections import Counter, defaultdict, OrderedDict, deque
from itertools import permutations, combinations
from functools import lru_cache
input = lambda : sys.stdin.readline().rstrip()
ii = lambda : int(input())
mi = lambda : map(int, input().split())
li = lambda : list(mi())
inf = 2 ** 63 - 1
mod = 10 ** 9 + 7

def solve():
	n = ii()
	l = li()
	s = input()
	d = {}
	for (i, j) in zip(l, s):
		if i in d:
			if d[i] != j:
				return 'NO'
		else:
			d[i] = j
	return 'YES'
for _ in range(ii()):
	print(solve())


def ans(arr, s):
	d = {}
	for i in range(len(arr)):
		if arr[i] in d:
			if d[arr[i]] != s[i]:
				return False
		d[arr[i]] = s[i]
	return True
for T in range(int(input())):
	n = int(input())
	arr = [int(i) for i in input().split()]
	s = input()
	print('YES' if ans(arr, s) else 'NO')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	s = input()
	t = dict()
	for i in range(n):
		if a[i] not in t:
			t[a[i]] = s[i]
			continue
		elif a[i] in t and t[a[i]] == s[i]:
			continue
		print('NO')
		break
	else:
		print('YES')


t = int(input())
for _ in range(t):
	n = int(input())
	mas = list(map(int, input().split()))
	check = list(input())
	d = dict()
	alarm = False
	for i in range(n):
		if mas[i] not in d:
			d[mas[i]] = check[i]
		elif d[mas[i]] == check[i]:
			continue
		else:
			alarm = True
			break
	if alarm:
		print('NO')
	else:
		print('YES')


def ss(n, l, s):
	d = {}
	for i in range(n):
		if l[i] in d:
			if d[l[i]] == s[i]:
				continue
			else:
				return False
		else:
			d[l[i]] = s[i]
	return True
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	s = str(input())
	if ss(n, l, s):
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.readline

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

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

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

def invr():
	return map(int, input().split())
for _ in range(inp()):
	flag = 'YES'
	hashmap = {}
	_ = inp()
	nums = inlt()
	strs = insr()
	for i in range(len(nums)):
		if nums[i] not in hashmap:
			hashmap[nums[i]] = strs[i]
		if hashmap[nums[i]] != strs[i]:
			flag = 'NO'
			break
	print(flag)


from collections import deque
InputList = lambda Dtype: [Dtype(x) for x in input().split()]
from functools import lru_cache
from math import sqrt, atan, pi

def solve():
	N = int(input())
	nums = InputList(int)
	s = input()
	map_n_to_c = {}
	for (n, c) in zip(nums, s):
		if n not in map_n_to_c:
			map_n_to_c[n] = c
		elif map_n_to_c[n] != c:
			return 'NO'
	return 'YES'
ReturnMode = True
t = 0
if not t:
	t = int(input())
for _ in range(t):
	ans = solve()
	if ReturnMode:
		print(ans) if type(ans) != list else print(*ans)


def solution():
	n = int(input())
	arr = list(map(int, input().split()))
	s = input()
	d = [''] * 51
	for i in range(n):
		if d[arr[i]] == s[i] or d[arr[i]] == '':
			d[arr[i]] = s[i]
		else:
			print('NO')
			return
	print('YES')
for _ in range(int(input())):
	solution()


t = int(input())

def solve(nums, string):
	dic = {}
	for (index, num) in enumerate(nums):
		if num in dic:
			if dic[num] != string[index]:
				return 'NO'
		else:
			dic[num] = string[index]
	return 'YES'
for i in range(t):
	n = int(input())
	nums = list(map(int, input().split()))
	string = list(input())
	print(solve(nums, string))


n = int(input())
for i in range(n):
	m = int(input())
	a = list(input().split())
	b = list(input())
	d = {}
	flag = 0
	for j in range(m):
		if a[j] not in d.keys():
			d[a[j]] = b[j]
		elif b[j] != d[a[j]]:
			flag = 1
			break
	if flag == 1:
		print('NO')
	else:
		print('YES')


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	s = input()
	d = {}
	for i in range(n):
		if a[i] in d:
			if d[a[i]] == s[i]:
				continue
			else:
				print('NO')
				break
		else:
			d[a[i]] = s[i]
	else:
		print('YES')


test = int(input())
for _ in range(test):
	n = int(input())
	arr = list(map(int, input().split()))
	s = str(input())
	words = {}
	status = True
	for (i, num) in enumerate(arr):
		if num not in words:
			words[num] = s[i]
		elif words[num] != s[i]:
			status = False
			break
	if status:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(input())
	p = ['.'] * 52
	x = 'YES'
	for j in range(n):
		i = a[j]
		if p[i] == '.':
			p[i] = b[j]
		elif p[i] != b[j]:
			x = 'NO'
			break
	print(x)


t = int(input())
for j in range(t):
	letters = {}
	n = int(input())
	nums = list(map(int, input().split()))
	string = input()
	ok = True
	for i in range(n):
		if nums[i] in letters:
			if letters[nums[i]] != string[i]:
				print('NO')
				ok = False
				break
		else:
			letters[nums[i]] = string[i]
	if ok:
		print('YES')


t = int(input())
for tc in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	s = input()
	d = {}
	for i in range(n):
		if l[i] in d:
			d[l[i]].extend(s[i])
		else:
			d[l[i]] = [s[i]]
	c = 0
	for i in d:
		if len(list(set(d[i]))) != 1:
			print('NO')
			c = 1
			break
	if c == 0:
		print('YES')


N = int(input())
for _ in range(N):
	m = int(input())
	arr = list(map(int, input().split()))
	res_str = input()
	dict = {}
	if len(arr) != len(res_str):
		print('NO')
		continue
	Flag = True
	for i in range(m):
		if not arr[i] in dict.keys():
			dict[arr[i]] = res_str[i]
		elif res_str[i] != dict[arr[i]]:
			Flag = False
	if Flag:
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.readline

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

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

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

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

def mainak(n):
	ts = 0
	for (idx, i) in enumerate(n):
		if i > n[ts]:
			ts = idx
	return ts + 1

def iso(d):
	a = [d[0]]
	i = 1
	while i < len(d):
		if a[i - 1] - d[i] == a[i - 1] + d[i]:
			a.append(a[i - 1] + d[i])
		elif a[i - 1] - d[i] > 0 and a[i - 1] + d[i] > 0:
			print(-1)
			return
		else:
			a.append(a[i - 1] + d[i])
		i += 1
	print(' '.join([str(x) for x in a]))

def solve(n, a, s):
	h = {}
	i = 0
	while i < len(s):
		if a[i] not in h:
			h[a[i]] = s[i]
		elif h[a[i]] != s[i]:
			print('NO')
			return
		i += 1
	print('YES')
t = inp()
for _ in range(t):
	n = int(input().strip())
	a = [int(x) for x in input().split()]
	s = input().strip()
	solve(n, a, s)


def ans(x, n, s):
	d = {}
	for i in range(n):
		if x[i] not in d:
			d[x[i]] = [s[i]]
		else:
			d[x[i]].append(s[i])
	for (i, j) in d.items():
		if len(set(j)) > 1:
			return 'NO'
	return 'YES'
for _ in range(int(input())):
	n = int(input())
	x = list(map(int, input().split()))
	s = input().strip()
	print(ans(x, n, s))


t = int(input())
z = 0
while z < t:
	n = int(input())
	l = list(map(int, input().split()))
	s = input()
	d = {}
	flag = 1
	for i in range(n):
		if l[i] not in d:
			d[l[i]] = s[i]
		elif d[l[i]] == s[i]:
			pass
		else:
			flag = 0
			break
	if flag == 0:
		print('NO')
	else:
		print('YES')
	z += 1


import sys
import collections
from math import ceil, gcd, sqrt, log
import bisect
INF = float('inf')
mod = 1000000007

def solve():
	n = int(input())
	A = list(map(int, input().split()))
	s = input()
	net = dict()
	for i in range(n):
		if A[i] not in net:
			net[A[i]] = s[i]
		elif net[A[i]] != s[i]:
			print('NO')
			return
	print('YES')
t = int(input())
while t != 0:
	solve()
	t -= 1


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	s = input()
	d1 = {}
	for i in range(n):
		if l[i] not in d1:
			d1[l[i]] = s[i]
		else:
			v = l[i]
			if d1[v] != s[i]:
				print('NO')
				break
	else:
		print('YES')


count_of_test_cases = int(input())
for _ in range(count_of_test_cases):
	number_count = int(input())
	numbers = list(map(int, input().split()))
	s = input()
	my_dict = dict()
	for i in range(len(numbers)):
		if numbers[i] in my_dict.keys():
			if s[i] != my_dict[numbers[i]]:
				print('NO')
				break
		else:
			my_dict[numbers[i]] = s[i]
	else:
		print('YES')


t = int(input())
while t:
	n = int(input())
	arr = list(map(int, input().split()))
	s = input()
	f = 1
	d = {}
	for i in range(n):
		if arr[i] not in d:
			d[arr[i]] = s[i]
		elif d[arr[i]] != s[i]:
			print('NO')
			f = 0
			break
	if f == 1:
		print('YES')
	t = t - 1


def num_replace(arr, s):
	d = {}
	for i in range(len(arr)):
		if arr[i] not in d:
			d[arr[i]] = s[i]
		elif d[arr[i]] != s[i]:
			return 'NO'
	return 'YES'
t = int(input())
i1 = 1
while i1 <= t:
	n = int(input())
	arr = list(map(int, input().rstrip().split()))
	s = input()
	print(num_replace(arr, s))
	i1 += 1


t = int(input())
for a0 in range(t):
	n = int(input())
	a = [i for i in str(input()).strip().split()]
	s = str(input())
	checker = dict(zip(a, [i for i in s]))
	works = True
	for (num, letter) in zip(a, s):
		if checker[num] != letter:
			works = False
			print('NO')
			break
	if works:
		print('YES')


out = []
for _ in range(int(input())):
	n = int(input())
	d = dict()
	a = input().split()
	s = input()
	r = 'YES'
	for i in range(n):
		if a[i] in d:
			if d[a[i]] != s[i]:
				r = 'NO'
				break
		else:
			d[a[i]] = s[i]
	out.append(r)
for i in out:
	print(i)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	string = input()
	flag = True
	hashMap = {}
	for i in range(n):
		if arr[i] in hashMap:
			if hashMap[arr[i]] == string[i]:
				flag = True
			else:
				flag = False
				break
		else:
			hashMap[arr[i]] = string[i]
	if flag:
		print('YES')
	else:
		print('NO')


t = int(input(''))
for i in range(t):
	ke = 'YES'
	a = int(input(''))
	b = input('').split(' ')
	s = input('')
	mapping = {}
	for (j, v) in enumerate(b):
		mapping[v] = s[j]
	for (j, v) in enumerate(b):
		if mapping[v] != s[j]:
			ke = 'NO'
			break
	print(ke)


def Replacement(arr, s):
	dt = {}
	for (x, y) in zip(arr, s):
		if x in dt and dt[x] != y:
			return 'NO'
		else:
			dt[x] = y
	return 'YES'
OUTPUT = []
for _ in range(int(input())):
	N = int(input())
	arr = input().split()
	s = input()
	OUTPUT.append(Replacement(arr, s))
for _ in OUTPUT:
	print(_)


t = int(input())
for i in range(0, t):
	n = int(input())
	arr = list(map(int, input().split()))
	s = input()
	dic = {}
	flag = 0
	for i in range(0, len(arr)):
		if arr[i] not in dic:
			dic[arr[i]] = s[i]
		elif s[i] != dic[arr[i]]:
			flag = 1
			break
	if flag == 0:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(n, arr, s, d, answer, ind) = (int(input()), map(int, input().split()), input(), {}, True, 0)
	for i in arr:
		if i in d and d[i] != s[ind]:
			answer = False
			break
		else:
			d[i] = s[ind]
		ind += 1
	if answer:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	n = int(input())
	m = {}
	number = list(map(int, input().split()))
	char = [*input()]
	notapp = 0
	for (c, j) in zip(char, number):
		if m.get(j) == None:
			m[j] = c
		elif m[j] != c:
			notapp = 1
			break
	if notapp == 1:
		print('NO')
	else:
		print('YES')


from bisect import *
from math import gcd, inf
from collections import defaultdict, deque

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

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

def w():
	return input()
t = nn()
for _ in range(t):
	n = nn()
	arr = li()
	w = input()
	flag = False
	dic = {}
	for (idx, i) in enumerate(arr):
		if i not in dic:
			dic[i] = w[idx]
		elif dic[i] != w[idx]:
			flag = True
			break
	print('NO') if flag else print('YES')


for _ in range(int(input())):
	n = int(input())
	nums = list(map(int, input().split()))
	word = input()
	dict = {}
	flag = 1
	for (i, num) in enumerate(nums):
		if num in dict and word[i] != dict[num]:
			print('NO')
			flag = 0
			break
		if num not in dict:
			dict[num] = word[i]
	if flag:
		print('YES')


n = int(input())
for i in range(n):
	d = {}
	m = int(input())
	l = input().split(' ')
	s = input()
	flag = 0
	for j in range(m):
		if l[j] not in d:
			d[l[j]] = s[j]
			continue
		if d[l[j]] != s[j]:
			flag = 1
			break
	if flag:
		print('NO')
	else:
		print('YES')


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	s = input()
	d = {}
	flag = 0
	for i in range(n):
		if a[i] in d:
			if d[a[i]] != s[i]:
				flag = 1
				print('NO')
				break
		d[a[i]] = s[i]
	if flag == 0:
		print('YES')


n = int(input())
for i in range(n):
	len_mas = int(input())
	mas = list(map(int, input().split()))
	s = input()
	dict = {}
	flag = False
	for j in range(len_mas):
		if mas[j] in dict.keys():
			if dict[mas[j]] != s[j]:
				flag = True
				break
		else:
			dict[mas[j]] = s[j]
	if flag:
		print('NO')
	else:
		print('YES')


t = int(input())

def test(n, a, s):
	d = dict()
	for (i, c) in enumerate(a):
		if c in d:
			if d[c] == s[i]:
				continue
			else:
				print('NO')
				return
		d[c] = s[i]
	print('YES')
while t:
	t -= 1
	(n,) = tuple(map(int, input().split()))
	a = list(map(int, input().split()))
	s = input()
	test(n, a, s)


tt = int(input())
while tt:
	tt -= 1
	n = int(input())
	a = list(map(int, input().split()))
	s = input()
	mp = {}
	f = True
	for i in range(n):
		if not a[i] in mp:
			mp[a[i]] = s[i]
		elif mp[a[i]] != s[i]:
			f = False
			break
	if f:
		print('YES')
	else:
		print('NO')


def helper(arr, strs):
	h = {}
	for i in range(len(strs)):
		if h.get(arr[i]) == None:
			h[arr[i]] = strs[i]
		elif h.get(arr[i]) != None and h[arr[i]] != strs[i]:
			return False
	return True
for i in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	strs = input()
	if helper(arr, strs):
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	s = input()
	d = {}
	flag = True
	for i in range(n):
		if arr[i] not in d:
			d[arr[i]] = s[i]
		elif s[i] != d[arr[i]]:
			print('NO')
			flag = False
			break
	if flag:
		print('YES')


for _ in range(int(input())):
	v = int(input())
	m = input().split()
	n = input()
	d = {}
	ans = 'YES'
	for (i, x) in enumerate(m):
		if x not in d:
			d[x] = n[i]
		elif n[i] != d[x]:
			ans = 'NO'
			break
	print(ans)


cases = int(input())
for case in range(1, cases + 1):
	n = int(input())
	nums = [int(i) for i in input().split()]
	string = input()
	d = {}
	flag = True
	for i in range(n):
		let = string[i]
		num = nums[i]
		if num in d:
			if d[num] != let:
				flag = False
				break
		else:
			d[num] = let
	print(('NO', 'YES')[flag])


def solve():
	_ = int(input())
	arr = list(map(int, input().split(' ')))
	s = input()
	d = {}
	for (idx, key) in enumerate(arr):
		val = d.get(key, None)
		if val is None:
			d[key] = s[idx]
		elif d[key] != s[idx]:
			return False
	return True

def main():
	t = int(input())
	for _ in range(t):
		ans = solve()
		if ans:
			print('YES')
		else:
			print('NO')
main()


for _ in range(int(input())):
	n = int(input())
	x = list(map(int, input().split()))
	s = list(input())
	d = {}
	flag = 0
	for j in range(len(x)):
		if x[j] not in d:
			d[x[j]] = s[j]
		elif d[x[j]] != s[j]:
			flag = 1
			break
	if flag:
		print('NO')
	else:
		print('YES')


from collections import defaultdict
n = int(input())
ans = []
for _ in range(n):
	m = int(input())
	nums = list(map(int, input().split()))
	s = str(input())
	dic = defaultdict(str)
	for (i, num) in enumerate(nums):
		if dic[num] and dic[num] != s[i]:
			ans.append('NO')
			break
		else:
			dic[num] = s[i]
	else:
		ans.append('YES')
for i in ans:
	print(i)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	w = input()
	d = {}
	out = True
	for x in range(n):
		curr_let = w[x]
		if arr[x] not in d:
			d[arr[x]] = curr_let
		elif d[arr[x]] != curr_let:
			out = False
			break
	if out:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	s = input()
	sl = {}
	for i in range(n):
		if a[i] not in sl:
			sl[a[i]] = s[i]
		elif sl[a[i]] != s[i]:
			print('NO')
			break
	else:
		print('YES')


import sys, math
t = int(sys.stdin.readline())
for i in range(t):
	freq = [0] * 51
	n = int(sys.stdin.readline())
	list1 = list(map(int, sys.stdin.readline().split()))
	string = list(sys.stdin.readline())
	a = 0
	for i in range(n):
		if freq[list1[i]] == 0:
			freq[list1[i]] = string[i]
		elif freq[list1[i]] != string[i]:
			print('NO')
			a = 1
			break
	if a == 0:
		print('YES')


for i in range(int(input())):
	n = int(input())
	(num, ltrs) = (input().split(), input())
	(dict1, ltrs2) = ({}, '')
	for i in range(n):
		dict1[num[i]] = ltrs[i]
	for elem in num:
		ltrs2 += dict1[elem]
	if ltrs == ltrs2:
		print('YES')
	else:
		print('NO')


def solve(n, l, s):
	d = {}
	for i in range(n):
		if l[i] in d:
			if d[l[i]] != s[i]:
				return 'NO'
		else:
			d[l[i]] = s[i]
	return 'YES'
for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	s = input()
	print(solve(n, l, s))


for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	s = input()
	seen = ['!' for i in range(51)]
	for i in range(n):
		done = False
		if seen[a[i]] == '!':
			seen[a[i]] = s[i]
		elif seen[a[i]] != s[i]:
			print('NO')
			done = True
			break
	if not done:
		print('YES')


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	s = input()
	d = dict()
	Breaker = False
	for (ind, i) in enumerate(l):
		if i not in d:
			d[i] = s[ind]
		elif d[i] != s[ind]:
			Breaker = True
			break
	if Breaker:
		print('NO')
	else:
		print('YES')


tcs = int(input())
for tc in range(tcs):
	n = int(input())
	nums = list(map(int, input().split()))
	s = input()
	hsh = {}
	good = True
	for (i, e) in enumerate(nums):
		if nums[i] in hsh and hsh[nums[i]] != s[i]:
			good = False
			break
		elif nums[i] not in hsh:
			hsh[nums[i]] = s[i]
	print('YES') if good else print('NO')


test = int(input())
while test > 0:
	test -= 1
	n = int(input())
	a1 = input().split(' ')
	s2 = input()
	a2 = []
	for i in s2:
		a2.append(i)
	d = {}
	ans = ''
	for i in range(0, n):
		if a1[i] not in d.keys():
			d[a1[i]] = a2[i]
		elif d[a1[i]] != a2[i]:
			ans = 'NO'
			break
	if ans == 'NO':
		print('NO')
		continue
	else:
		print('YES')


t = int(input())
for i in range(t):
	n = int(input())
	nums = list(map(int, input().split(' ')))
	string = list(input())
	d = {}
	success = True
	for (s, n) in zip(string, nums):
		if d.get(n) is None:
			d[n] = s
		elif d[n] != s:
			print('NO')
			success = False
			break
	if success:
		print('YES')


def execute(numbers_list: list, s: str):
	if len(numbers_list) != len(s):
		return 'NO'
	dic = {}
	for i in range(len(numbers_list)):
		if numbers_list[i] in dic.keys():
			if dic[numbers_list[i]] != s[i]:
				print('NO')
				return
		dic[numbers_list[i]] = s[i]
	print('YES')

def main1():
	out_str = ''
	inp_size = int(input())
	for i in range(inp_size):
		inp_list = []
		for j in range(int(input())):
			inp_list.append(input())
		inp_str = input()
		out_str += execute(inp_list, inp_str)
	print(out_str)

def main2():
	inp_size = int(input())
	for i in range(inp_size):
		inp_list_size = input()
		inp_list = input().split(' ')
		inp_str = input()
		execute(inp_list, inp_str)
main2()


for _ in range(int(input())):
	(n, l, c, d, ans) = (int(input()), list(map(int, input().split())), input(), {}, 'YES')
	for i in range(n):
		if l[i] in d.keys():
			if d[l[i]] != c[i]:
				ans = 'NO'
				break
		else:
			d[l[i]] = c[i]
	print(ans)


problems = int(input())
for _ in range(problems):
	_amount = int(input())
	nums = list(map(int, input().split(' ')))
	word = input()
	d = {}
	is_true = True
	for i in range(len(nums)):
		if not is_true:
			break
		num = nums[i]
		if num in d:
			if d[num] != word[i]:
				is_true = False
		else:
			d[num] = word[i]
	if is_true:
		print('YES')
	else:
		print('NO')


def solve(array, string, length_a):
	dictionary = {}
	for i in range(length_a):
		if array[i] in dictionary:
			if string[i] == dictionary.get(array[i]):
				continue
			else:
				return 'NO'
		else:
			dictionary[array[i]] = string[i]
	return 'YES'
num_testcases = int(input())
for number in range(num_testcases):
	length_a = int(input())
	array = list(input().split(' '))
	string = input()
	print(solve(array, string, length_a))


i = input()
for n in range(int(i)):
	strlen = input()
	nmbs = input().split(' ')
	word = input()
	dict = {}
	a = True
	for m in range(len(nmbs)):
		if nmbs[m] in dict.keys():
			if dict[nmbs[m]] != word[m]:
				print('NO')
				a = False
				break
		else:
			dict.update({nmbs[m]: word[m]})
	if a == True:
		print('YES')


from collections import defaultdict
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	s = input()
	map_ = {}
	flag = 1
	for i in range(n):
		if a[i] in map_:
			if s[i] != s[map_[a[i]]]:
				flag = 0
				break
		else:
			map_[a[i]] = i
	print('YES' if flag else 'NO')


import sys
input = sys.stdin.readline
from collections import defaultdict
for _ in range(int(input())):
	d = defaultdict(list)
	n = int(input())
	w = list(map(int, input().split()))
	s = input()[:-1]
	for (i, j) in enumerate(w):
		d[j].append(i)
	for i in d:
		e = [s[x] for x in d[i]]
		if len(set(e)) > 1:
			print('NO')
			break
	else:
		print('YES')


t = int(input())
for tc in range(t):
	n = int(input())
	a = input().split()
	s = input()
	dick = dict()
	z = 1
	for i in range(n):
		if a[i] not in dick:
			dick[a[i]] = s[i]
		elif dick[a[i]] != s[i]:
			z = 0
			print('NO')
			break
	if z:
		print('YES')


t = int(input())
outputs = []
for i in range(t):
	n = int(input())
	array = input().split()
	array = [int(x) for x in array]
	s = input()
	output = [n, array, s]
	outputs.append(output)

def task(output):
	result = 'NO'
	dictNums = {}
	n = output[0]
	array = output[1]
	s = output[2]
	for i in range(n):
		if array[i] not in dictNums:
			dictNums[array[i]] = s[i]
		elif s[i] == dictNums[array[i]]:
			continue
		else:
			return 'NO'
	result = 'YES'
	return result
for output in outputs:
	print(task(output))


def single_case():
	n = int(input())
	t = list(map(int, input().split()))
	s = input()
	used_mapping = dict()
	for (let, num) in zip(s, t):
		if num in used_mapping:
			if used_mapping[num] != let:
				print('NO')
				return
		else:
			used_mapping[num] = let
	print('YES')
	return
z = int(input())
for _ in range(z):
	single_case()


def f(n, l, s):
	d = {}
	for i in range(n):
		if l[i] not in d:
			d[l[i]] = s[i]
		elif d[l[i]] != s[i]:
			return 'NO'
	return 'YES'
n = int(input())
for _ in range(n):
	print(f(int(input()), input().split(), input()))


n_inputs = int(input())
result = []
for test in range(n_inputs):
	length = int(input())
	int_list = input().split(' ')
	char_list = input()
	d = dict()
	err = False
	for i in range(length):
		cur = d.get(int_list[i])
		if cur != None and cur != char_list[i]:
			err = True
			break
		d[int_list[i]] = char_list[i]
	if err:
		result.append('NO')
	else:
		result.append('YES')
for res in result:
	print(res)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split(' ')))
	s = input()
	d = {}
	ans = ''
	for j in range(n):
		if a[j] not in d:
			d[a[j]] = s[j]
		elif d[a[j]] != s[j]:
			ans = 'NO'
			break
		if j == n - 1:
			ans = 'YES'
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	s = input()
	dic = {}
	ans = 'YES'
	for (i, val) in enumerate(a):
		if val not in dic:
			dic[val] = s[i]
			continue
		if dic[val] != s[i]:
			ans = 'NO'
			break
	print(ans)


def solution(arr, ltr, n):
	dic = {}
	for i in range(n):
		if arr[i] in dic:
			if dic[arr[i]] != ltr[i]:
				return 'NO'
		else:
			dic[arr[i]] = ltr[i]
	return 'YES'
t = int(input())
result = []
for i in range(t):
	n = int(input())
	arr = [x for x in input().split(' ')]
	ltr = input()
	result.append(solution(arr, ltr, n))
for res in result:
	print(res)


t = int(input())
for i in range(t):
	n = int(input())
	L = list(map(int, input().split()))
	ch = input()
	C = list(ch)
	D = {}
	a = 0
	for i in range(n):
		if L[i] not in D.keys():
			D[L[i]] = C[i]
	for i in range(n):
		if D[L[i]] != C[i]:
			a = 1
	if a == 1:
		print('NO')
	else:
		print('YES')


d = {}
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	s = list(input())
	avail = True
	d.clear()
	i = 0
	while i < n and avail:
		try:
			if d[a[i]] != s[i]:
				avail = False
			else:
				i += 1
		except:
			d[a[i]] = s[i]
			i += 1
	if avail:
		print('YES')
	else:
		print('NO')


def solve(n, ls, s):
	ans = {}
	for i in range(n):
		if ls[i] in ans:
			if s[i] != ans[ls[i]]:
				return 'NO'
		else:
			ans[ls[i]] = s[i]
	return 'YES'
t = int(input())
while t > 0:
	n = int(input())
	ls = list(map(int, input().split()))
	s = input()
	print(solve(n, ls, s))
	t -= 1


for test in range(int(input())):
	n = int(input())
	lks = list(map(int, input().split()))
	singh = input()
	temp = dict()
	ans = 'YES'
	for i in range(n):
		if lks[i] not in temp:
			temp[lks[i]] = singh[i]
		elif temp[lks[i]] != singh[i]:
			ans = 'NO'
			break
	print(ans)


import sys

def solve_problem(numbers: list, characters: list) -> str:
	mapp = dict()
	for n in numbers:
		ch = characters.pop(0)
		if n not in mapp:
			mapp[n] = ch
		elif mapp[n] != ch:
			return 'NO'
	return 'YES'
count = int(sys.stdin.readline())
resp = []
for _ in range(count):
	sys.stdin.readline()
	n = list(sys.stdin.readline().split())
	c = list(sys.stdin.readline())[:-1]
	resp.append((n, c))
for r in resp:
	print(solve_problem(r[0], r[1]))


t = int(input())
for i in range(t):
	n = int(input())
	a = input()
	a = a.split()
	s = input()
	a_set = set(a)
	ch = [a[x] + s[x] for x in range(n)]
	ch_set = set(ch)
	if len(a_set) == len(ch_set):
		print('YES')
	else:
		print('NO')


tests = int(input())
for _ in range(tests):
	m = int(input())
	n = list(map(int, input().split()))
	s = input()
	dc = {}
	for i in range(m):
		if not dc.get(n[i]):
			dc[n[i]] = s[i]
		elif dc[n[i]] != s[i]:
			print('NO')
			break
	else:
		print('YES')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	s = input()
	d = {}
	for i in range(n):
		if a[i] not in d:
			d[a[i]] = s[i]
		elif d[a[i]] == s[i]:
			continue
		else:
			print('NO')
			break
	else:
		print('YES')


def rep(arr, st):
	d = {}
	for i in range(len(arr)):
		if arr[i] not in d:
			d[arr[i]] = st[i]
		elif d[arr[i]] != st[i]:
			return 'NO'
	return 'YES'
t = int(input())
ans = []
for m in range(t):
	l = int(input())
	arr = list(map(int, input().split(' ')))
	st = input()
	ans.append(rep(arr, st))
for k in ans:
	print(k)


for i in range(int(input())):
	n = int(input())
	l = list(map(str, input().split()))
	s = input()
	k = {}
	for x in range(n):
		if l[x] not in k.keys():
			k[l[x]] = set(s[x])
		else:
			k[l[x]].add(s[x])
	flag = 0
	for x in k.values():
		if len(x) > 1:
			flag = 1
			break
	if flag == 1:
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	n = int(input())
	d = dict()
	a = list(map(int, input().split()))
	b = input()
	ans = 'YES'
	for i in range(n):
		if a[i] not in d:
			d[a[i]] = b[i]
		elif d[a[i]] != b[i]:
			ans = 'NO'
			break
	print(ans)