Ayush, Ashish and Vivek are busy preparing a new problem for the next Codeforces round and need help checking if their test cases are valid.

Each test case consists of an integer $n$ and two arrays $a$ and $b$, of size $n$. If after some (possibly zero) operations described below, array $a$ can be transformed into array $b$, the input is said to be valid. Otherwise, it is invalid.

An operation on array $a$ is:   select an integer $k$ $(1 \le k \le \lfloor\frac{n}{2}\rfloor)$  swap the prefix of length $k$ with the suffix of length $k$ 

For example, if array $a$ initially is $\{1, 2, 3, 4, 5, 6\}$, after performing an operation with $k = 2$, it is transformed into $\{5, 6, 3, 4, 1, 2\}$.

Given the set of test cases, help them determine if each one is valid or invalid.


-----Input-----

The first line contains one integer $t$ $(1 \le t \le 500)$ — the number of test cases. The description of each test case is as follows.

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

The second line of each test case contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le 10^9)$ — elements of array $a$.

The third line of each test case contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le 10^9)$ — elements of array $b$.


-----Output-----

For each test case, print "Yes" if the given input is valid. Otherwise print "No".

You may print the answer in any case.


-----Example-----
Input
5
2
1 2
2 1
3
1 2 3
1 2 3
3
1 2 4
1 3 4
4
1 2 3 2
3 1 2 2
3
1 2 3
1 3 2

Output
yes
yes
No
yes
No



-----Note-----

For the first test case, we can swap prefix $a[1:1]$ with suffix $a[2:2]$ to get $a=[2, 1]$.

For the second test case, $a$ is already equal to $b$.

For the third test case, it is impossible since we cannot obtain $3$ in $a$.

For the fourth test case, we can first swap prefix $a[1:1]$ with suffix $a[4:4]$ to obtain $a=[2, 2, 3, 1]$. Now we can swap prefix $a[1:2]$ with suffix $a[3:4]$ to obtain $a=[3, 1, 2, 2]$.

For the fifth test case, it is impossible to convert $a$ to $b$.

Difficulty: HARD

Solutions:
import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	x = sorted(zip(a, reversed(a)))
	y = sorted(zip(b, reversed(b)))
	if x == y:
		print('Yes')
	else:
		print('No')


from collections import defaultdict
import math
from functools import reduce
from heapq import heapify, heappush, heappop
import sys
from sys import stdin, stdout
from random import seed
from random import randint
mod = 10 ** 9 + 7

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

def add_mod(a, b):
	return (a % mod + b % mod) % mod

def sub_mod(a, b):
	return (a % mod - b % mod + mod) % mod

def modInverse(b):
	return pow(b, mod - 2, mod)

def div_mod(a, b):
	a = a % mod
	inv = modInverse(b)
	return inv * a % mod

class Graph:

	def __init__(self, vertices):
		self.V = vertices + 1
		self.graph = defaultdict(set)
		self.Time = 0
		self.P = 0
		self.Q = 0

	def addEdge(self, u, v):
		self.graph[u].add(v)
		self.graph[v].add(u)

	def bridgeUtil(self, u):
		self.count[u] += 1
		self.disc[u] = self.Time
		self.low[u] = self.Time
		self.Time += 1
		for v in self.graph[u]:
			if self.count[v] == 0:
				self.parent[v] = u
				self.bridgeUtil(v)
				self.count[u] += self.count[v]
				self.low[u] = min(self.low[u], self.low[v])
				if self.low[v] > self.disc[u]:
					self.Q += 1
					if self.count[v] % 2 == 0:
						self.P += 1
			elif v != self.parent[u]:
				self.low[u] = min(self.low[u], self.disc[v])

	def bridge(self):
		self.disc = [float('Inf')] * self.V
		self.low = [float('Inf')] * self.V
		self.parent = [-1] * self.V
		self.count = [0] * self.V
		for i in range(1, self.V):
			if self.count[i] == 0:
				self.bridgeUtil(i)
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	(c, d) = (reversed(a), reversed(b))
	(e, f) = (zip(a, c), zip(b, d))
	(e, f) = (sorted(e), sorted(f))
	if (n % 2 == 0 or a[n // 2] == b[n // 2]) and e == f:
		print('Yes')
	else:
		print('No')


import sys
from array import array
from typing import List, Tuple, TypeVar, Generic, Sequence, Union

def input():
	return sys.stdin.buffer.readline().decode('utf-8')

def main():
	t = int(input())
	ans = ['No'] * t
	for ti in range(t):
		n = int(input())
		a = list(map(int, input().split()))
		b = list(map(int, input().split()))
		if n & 1 and a[n >> 1] != b[n >> 1]:
			continue
		if sorted(((a[i], a[n - i - 1]) if a[i] < a[n - i - 1] else (a[n - i - 1], a[i]) for i in range(n >> 1))) == sorted(((b[i], b[n - i - 1]) if b[i] < b[n - i - 1] else (b[n - i - 1], b[i]) for i in range(n >> 1))):
			ans[ti] = 'Yes'
	print(*ans, sep='\n')
main()


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

def cnt(A):
	C = Counter()
	for i in range(len(A) // 2):
		(a, b) = (A[i], A[-i - 1])
		C[min(a, b), max(a, b)] += 1
	return C
for _ in range(int(input())):
	n = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	if n % 2 == 1 and A[n // 2] != B[n // 2]:
		print('No')
		continue
	print('Yes' if cnt(A) == cnt(B) else 'No')


from sys import stdin, stdout

def swaps_again(n, a, b):
	if n % 2 == 1 and a[n // 2] != b[n // 2]:
		return 'No'
	dica = {}
	for i in range(0, n // 2):
		al = a[i]
		ar = a[n - 1 - i]
		if al not in dica:
			dica[al] = {}
		if ar not in dica:
			dica[ar] = {}
		if ar not in dica[al]:
			dica[al][ar] = 0
		if al not in dica[ar]:
			dica[ar][al] = 0
		dica[al][ar] += 1
		dica[ar][al] += 1
	for i in range(0, n // 2):
		bl = b[i]
		br = b[n - 1 - i]
		if bl not in dica or br not in dica[bl] or dica[bl][br] == 0:
			return 'No'
		dica[bl][br] -= 1
		dica[br][bl] -= 1
	return 'Yes'
t = int(stdin.readline())
for i in range(t):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	b = list(map(int, stdin.readline().split()))
	stdout.write(swaps_again(n, a, b) + '\n')


import sys, math
import io, os

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

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

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

def out(var):
	sys.stdout.write(str(var) + '\n')
mod = int(1000000000.0) + 7
for t in range(int(data())):
	n = int(data())
	a = mdata()
	b = mdata()
	s = a + a
	ind = 0
	if n % 2 != 0:
		if a[n // 2] != b[n // 2]:
			out('No')
			continue
	flag = True
	cnt = 0
	l = [0] * (n // 2)
	for i in range(n // 2):
		for j in range(n // 2):
			if l[j] == 0:
				if a[i] == b[j] and a[n - i - 1] == b[n - j - 1] or (a[i] == b[n - j - 1] and a[n - i - 1] == b[j]):
					cnt += 1
					l[j] = 1
					break
	if cnt == n // 2:
		out('Yes')
	else:
		out('No')


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

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if n % 2 == 1 and a[n // 2] != b[n // 2]:
		print('No')
		return
	d = defaultdict(int)
	for i in range(n // 2):
		d[min(a[i], a[n - 1 - i]), max(a[i], a[n - 1 - i])] += 1
	ok = True
	for i in range(n // 2):
		v = (min(b[i], b[n - 1 - i]), max(b[i], b[n - 1 - i]))
		if d[v] <= 0:
			ok = False
			break
		d[v] -= 1
	if ok:
		print('Yes')
	else:
		print('No')
t = int(input())
while t:
	t -= 1
	solve()


from collections import defaultdict
import sys, math
f = None
try:
	f = open('q1.input', 'r')
except IOError:
	f = sys.stdin
if 'xrange' in dir(__builtins__):
	range = xrange
sys.setrecursionlimit(10 ** 2)

def print_case_iterable(case_num, iterable):
	print('Case #{}: {}'.format(case_num, ' '.join(map(str, iterable))))

def print_case_number(case_num, iterable):
	print('Case #{}: {}'.format(case_num, iterable))

def print_iterable(A):
	print(' '.join(A))

def read_int():
	return int(f.readline().strip())

def read_int_array():
	return [int(x) for x in f.readline().strip().split(' ')]

def rns():
	a = [x for x in f.readline().split(' ')]
	return (int(a[0]), a[1].strip())

def read_string():
	return list(f.readline().strip())

def ri():
	return int(f.readline().strip())

def ria():
	return [int(x) for x in f.readline().strip().split(' ')]

def rns():
	a = [x for x in f.readline().split(' ')]
	return (int(a[0]), a[1].strip())

def rs():
	return list(f.readline().strip())

def bi(x):
	return bin(x)[2:]
from collections import deque
import math
NUMBER = 10 ** 9 + 7

def factorial(n):
	M = NUMBER
	f = 1
	for i in range(1, n + 1):
		f = f * i % M
	return f

def mult(a, b):
	return a * b % NUMBER

def minus(a, b):
	return (a - b) % NUMBER

def plus(a, b):
	return (a + b) % NUMBER

def egcd(a, b):
	if a == 0:
		return (b, 0, 1)
	else:
		(g, y, x) = egcd(b % a, a)
		return (g, x - b // a * y, y)

def modinv(a):
	m = NUMBER
	(g, x, y) = egcd(a, m)
	if g != 1:
		raise Exception('modular inverse does not exist')
	else:
		return x % m

def choose(n, k):
	if n < k:
		assert false
	return mult(factorial(n), modinv(mult(factorial(k), factorial(n - k))))
from collections import deque, defaultdict
import heapq

def solution(a, b, n):
	da = defaultdict(int)
	db = defaultdict(int)
	for i in range(n // 2):
		da[frozenset([a[i], a[n - 1 - i]])] += 1
		db[frozenset([b[i], b[n - 1 - i]])] += 1
	if n % 2:
		if a[n // 2] != b[n // 2]:
			return 'No'
	for x in da:
		if db[x] != da[x]:
			return 'No'
	return 'Yes'

def main():
	T = ri()
	for i in range(T):
		n = ri()
		a = ria()
		b = ria()
		x = solution(a, b, n)
		if 'xrange' not in dir(__builtins__):
			print(x)
		else:
			(print >> output, str(x))
	if 'xrange' in dir(__builtins__):
		print(output.getvalue())
		output.close()
if 'xrange' in dir(__builtins__):
	import cStringIO
	output = cStringIO.StringIO()
main()


import collections
T = int(input())
while T > 0:
	n = int(input())
	arr1 = list(map(int, input().split()))
	arr2 = list(map(int, input().split()))
	if n % 2 == 1 and arr1[n // 2] != arr2[n // 2]:
		print('No')
		T -= 1
		continue
	have = collections.defaultdict(int)
	for i in range(n // 2):
		pair = (arr1[i], arr1[n - i - 1])
		have[pair] += 1
	form = True
	for i in range(n // 2):
		pair1 = (arr2[i], arr2[n - i - 1])
		pair2 = (arr2[n - i - 1], arr2[i])
		if pair1 in have:
			have[pair1] -= 1
			if have[pair1] == 0:
				have.pop(pair1)
		elif pair2 in have:
			have[pair2] -= 1
			if have[pair2] == 0:
				have.pop(pair2)
		else:
			form = False
			break
	if form is True:
		print('Yes')
	else:
		print('No')
	T -= 1


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	works = True
	if n % 2:
		if a[n // 2] != b[n // 2]:
			works = False
	pairsA = []
	for i in range(n // 2):
		f = a[i]
		s = a[n - i - 1]
		if f > s:
			(f, s) = (s, f)
		pairsA.append((f, s))
	pairsB = []
	for i in range(n // 2):
		f = b[i]
		s = b[n - i - 1]
		if f > s:
			(f, s) = (s, f)
		pairsB.append((f, s))
	pairsA.sort()
	pairsB.sort()
	if works and pairsA == pairsB:
		print('Yes')
	else:
		print('No')


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


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

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

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

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

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

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

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))
t = 1
t = iinput()
for i in range(t):
	n = iinput()
	a = rlinput()
	b = rlinput()
	if sorted(a) != sorted(b):
		print('No')
		continue
	if n % 2 and a[n // 2] != b[n // 2]:
		print('No')
		continue
	d = defaultdict(int)
	for i in range(n // 2):
		(val1, val2) = (a[i], a[n - i - 1])
		d[max(val1, val2), min(val1, val2)] += 1
	flg = True
	for i in range(n // 2):
		(val1, val2) = (b[i], b[n - i - 1])
		d[max(val1, val2), min(val1, val2)] -= 1
		if d[max(val1, val2), min(val1, val2)] < 0:
			flg = False
			break
	print(['No', 'Yes'][flg])


from collections import Counter
T = int(input().strip())
for t in range(T):
	n = int(input().strip())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if Counter(a) != Counter(b):
		print('No')
		continue
	mid = n // 2 + n % 2
	aa = Counter((tuple(sorted([a[i], a[n - i - 1]])) for i in range(mid)))
	bb = Counter((tuple(sorted([b[i], b[n - i - 1]])) for i in range(mid)))
	if aa != bb:
		print('No')
		continue
	print('Yes')


import sys
input = sys.stdin.readline
from collections import Counter as cc
I = lambda : list(map(int, input().split()))
(t,) = I()
for _ in range(t):
	(n,) = I()
	a = I()
	b = I()
	A = []
	B = []
	if n % 2 and a[n // 2] != b[n // 2]:
		print('No')
		continue
	for i in range(n // 2):
		A.append(tuple(sorted([a[i], a[n - i - 1]])))
		B.append(tuple(sorted([b[i], b[n - i - 1]])))
	if cc(A) == cc(B):
		print('Yes')
	else:
		print('No')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	s1 = []
	s2 = []
	if n % 2 == 1 and a[n // 2] != b[n // 2]:
		print('No')
		continue
	for i in range(n // 2):
		s1.append((min(a[i], a[n - i - 1]), max(a[i], a[n - i - 1])))
		s2.append((min(b[i], b[n - i - 1]), max(b[i], b[n - i - 1])))
	if sorted(s1) == sorted(s2):
		print('Yes')
	else:
		print('No')


import sys
import collections as cc
I = lambda : list(map(int, input().split()))
for tc in range(int(input())):
	(n,) = I()
	a = I()
	b = I()
	aa = []
	bb = []
	f = 1
	if n % 2:
		if a[n // 2] != b[n // 2]:
			f = 0
	if f:
		for i in range(n // 2):
			(x, y) = (a[i], a[n - i - 1])
			(xx, yy) = (b[i], b[n - i - 1])
			if x > y:
				(x, y) = (y, x)
			if xx > yy:
				(xx, yy) = (yy, xx)
			aa.append((x, y))
			bb.append((xx, yy))
		aa = cc.Counter(aa)
		bb = cc.Counter(bb)
		if aa == bb:
			print('Yes')
		else:
			print('No')
	else:
		print('No')


import sys
input = sys.stdin.readline
t = int(input())
for tests in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	C = []
	D = []
	if n % 2 == 1:
		if A[n // 2] != B[n // 2]:
			print('No')
			continue
	for i in range(n // 2):
		C.append(sorted([A[i], A[-i - 1]]))
		D.append(sorted([B[i], B[-i - 1]]))
	if sorted(C) == sorted(D):
		print('Yes')
	else:
		print('No')


from collections import defaultdict
from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	brr = list(map(int, input().split()))
	if n % 2 and arr[n // 2] != brr[n // 2]:
		print('No')
		continue
	dct = defaultdict(lambda : 0)
	for i in range(n // 2):
		t = (arr[i], arr[n - i - 1])
		dct[min(t), max(t)] += 1
	for i in range(n // 2):
		t = (brr[i], brr[n - i - 1])
		dct[min(t), max(t)] -= 1
	print('No' if any((v for (k, v) in dct.items())) else 'Yes')


import sys
input = sys.stdin.readline
import heapq
import copy
import math

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

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

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

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

class Node:

	def _init_(self, val):
		self.data = val
		self.left = None
		self.right = None

def pre_sum(arr):
	p = [0]
	for i in arr:
		p.append(p[-1] + i)
	p.pop(0)
	return p

def pre_back(arr):
	p = [0]
	for i in arr:
		p.append(p[-1] + i)
	p.pop(0)
	return p

def bin_search(arr, l, r, val):
	if arr[r] <= val:
		return r + 1
	if r - l < 2:
		if arr[l] > val:
			return l
		else:
			return r
	mid = int((l + r) / 2)
	if arr[mid] <= val:
		return bin_search(arr, mid, r, val)
	else:
		return bin_search(arr, l, mid, val)

def search_leftmost(arr, val):

	def helper(arr, l, r, val):
		print(l, r)
		if arr[l] == val:
			return l
		if r - l <= 1:
			if arr[r] == val:
				return r
			else:
				print('not found')
				return
		mid = int((r + l) / 2)
		if arr[mid] >= val:
			return helper(arr, l, mid, val)
		else:
			return helper(arr, mid, r, val)
	return helper(arr, 0, len(arr) - 1, val)

def search_rightmost(arr, val):

	def helper(arr, l, r, val):
		print(l, r)
		if arr[r] == val:
			return r
		if r - l <= 1:
			if arr[l] == val:
				return r
			else:
				print('not found')
				return
		mid = int((r + l) / 2)
		if arr[mid] > val:
			return helper(arr, l, mid, val)
		else:
			return helper(arr, mid, r, val)
	return helper(arr, 0, len(arr) - 1, val)

def pr_list(a):
	print(*a, sep=' ')

def main():
	tests = inp()
	mod = 1000000007
	limit = 10 ** 18
	for test in range(tests):
		n = inp()
		a = inlt()
		b = inlt()
		hashm = {}
		if n % 2 == 1:
			if a[n // 2] != b[n // 2]:
				print('No')
				continue
		for i in range(0, n // 2):
			if (a[i], a[n - i - 1]) not in hashm:
				hashm[a[i], a[n - i - 1]] = 1
			else:
				hashm[a[i], a[n - i - 1]] = hashm[a[i], a[n - i - 1]] + 1
		flag = 0
		for i in range(0, n // 2):
			if (b[i], b[n - i - 1]) in hashm:
				if hashm[b[i], b[n - i - 1]] == 1:
					del hashm[b[i], b[n - i - 1]]
				else:
					hashm[b[i], b[n - i - 1]] = hashm[b[i], b[n - i - 1]] - 1
			elif (b[n - i - 1], b[i]) in hashm:
				if hashm[b[n - i - 1], b[i]] == 1:
					del hashm[b[n - i - 1], b[i]]
				else:
					hashm[b[n - i - 1], b[i]] = hashm[b[n - i - 1], b[i]] - 1
			else:
				flag = 1
				break
		if flag == 0:
			print('Yes')
		else:
			print('No')
main()


import sys
from collections import deque
readline = sys.stdin.readline
ns = lambda : readline().rstrip()
ni = lambda : int(readline().rstrip())
nm = lambda : map(int, readline().split())
nl = lambda : list(map(int, readline().split()))

def solve():
	n = ni()
	a = nl()
	b = nl()
	for i in range(n // 2):
		if a[i] < a[n - 1 - i]:
			(a[i], a[n - 1 - i]) = (a[n - 1 - i], a[i])
		if b[i] < b[n - 1 - i]:
			(b[i], b[n - 1 - i]) = (b[n - 1 - i], b[i])
	if n & 1 and a[n // 2] != b[n // 2]:
		print('No')
		return
	f = [(a[i], a[n - 1 - i]) for i in range(n // 2)]
	g = [(b[i], b[n - 1 - i]) for i in range(n // 2)]
	f.sort()
	g.sort()
	print('Yes' if f == g else 'No')
	return
T = int(input())
for _ in range(T):
	solve()


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

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

def fi():
	return float(input())

def si():
	return input()

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

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

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

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
mod = 1000000007
import math
import bisect
from decimal import *
getcontext().prec = 50
abc = 'abcdefghijklmnopqrstuvwxyz'

def fn(n):
	c = 0
	while n % 2 == 0:
		c += 1
		n //= 2
	return c
pi = 3.141592653589793

def main():
	for _ in range(ii()):
		n = ii()
		a = li()
		b = li()
		l1 = []
		l2 = []
		for i in range(n):
			l1.append([min(a[i], a[-i - 1]), max(a[i], a[-i - 1])])
			l2.append([min(b[i], b[-i - 1]), max(b[i], b[-i - 1])])
		l1.sort()
		l2.sort()
		if l1 == l2:
			print('Yes')
		else:
			print('No')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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

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


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

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

def mapi(arg=0):
	return map(int if arg == 0 else str, input().split())
for _ in range(int(input())):
	n = int(input())
	a = list(mapi())
	b = list(mapi())
	if n & 1 and a[n // 2] != b[n // 2]:
		print('No')
		continue
	f = 1
	mp = defaultdict(int)
	for i in range(n // 2):
		mp[min(a[i], a[n - i - 1]), max(a[i], a[n - i - 1])] += 1
	for i in range(n // 2):
		mp[min(b[i], b[n - i - 1]), max(b[i], b[n - i - 1])] -= 1
		if mp[min(b[i], b[n - i - 1]), max(b[i], b[n - i - 1])] < 0:
			f = 0
			break
	if f:
		print('Yes')
	else:
		print('No')


from collections import deque

def Hopcroft_Karp(adj, L):
	N = len(adj)
	matching = [-1 for _ in range(N)]
	while True:
		extended = False
		sources = [v for v in range(N) if matching[v] == -1 and L[v]]
		bfs_pred = [-1 for _ in range(N)]
		bfs_source = [-1 for _ in range(N)]
		for v in sources:
			bfs_pred[v] = v
			bfs_source[v] = v
		queue = deque(sources)
		while len(queue) > 0:
			cur = queue.popleft()
			if matching[bfs_source[cur]] != -1:
				continue
			for nb in adj[cur]:
				if matching[nb] == -1:
					while nb != -1:
						(matching[nb], matching[cur], nb, cur) = (cur, nb, matching[cur], bfs_pred[cur])
					extended = True
					break
				else:
					new = matching[nb]
					if bfs_pred[new] == -1:
						bfs_pred[new] = cur
						bfs_source[new] = bfs_source[cur]
						queue.append(new)
		if not extended:
			break
	return (sum((1 for x in matching if x != -1)) // 2, matching)
t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	if n % 2:
		if a[n // 2] != b[n // 2]:
			print('No')
			continue
	a_pairs = []
	b_pairs = []
	for i in range(n // 2):
		if a[i] < a[n - i - 1]:
			a_pairs.append((a[i], a[n - i - 1]))
		else:
			a_pairs.append((a[n - i - 1], a[i]))
		if b[i] < b[n - i - 1]:
			b_pairs.append((b[i], b[n - i - 1]))
		else:
			b_pairs.append((b[n - i - 1], b[i]))
	adj = [[] for _ in range(len(a_pairs) + len(b_pairs))]
	for (i, ap) in enumerate(a_pairs):
		for (j, bp) in enumerate(b_pairs):
			if ap == bp:
				adj[i].append(len(a_pairs) + j)
				adj[len(a_pairs) + j].append(i)
	if Hopcroft_Karp(adj, [True] * len(a_pairs) + [False] * len(b_pairs))[0] == len(a_pairs):
		print('Yes')
	else:
		print('No')


from bisect import *
from collections import *
from math import gcd, ceil, sqrt, floor, inf
from heapq import *
from itertools import *
from operator import add, mul, sub, xor, truediv, floordiv
from functools import *
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 RL():
	return map(int, sys.stdin.readline().rstrip().split())

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

def N():
	return int(input())
from types import GeneratorType

def bootstrap(f, stack=[]):

	def wrappedfunc(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		else:
			to = f(*args, **kwargs)
			while True:
				if type(to) is GeneratorType:
					stack.append(to)
					to = next(to)
				else:
					stack.pop()
					if not stack:
						break
					to = stack[-1].send(to)
			return to
	return wrappedfunc
farr = [1]
ifa = []

def fact(x, mod=0):
	if mod:
		while x >= len(farr):
			farr.append(farr[-1] * len(farr) % mod)
	else:
		while x >= len(farr):
			farr.append(farr[-1] * len(farr))
	return farr[x]

def ifact(x, mod):
	global ifa
	ifa.append(pow(farr[-1], mod - 2, mod))
	for i in range(x, 0, -1):
		ifa.append(ifa[-1] * i % mod)
	ifa = ifa[::-1]

def per(i, j, mod=0):
	if i < j:
		return 0
	if not mod:
		return fact(i) // fact(i - j)
	return farr[i] * ifa[i - j] % mod

def com(i, j, mod=0):
	if i < j:
		return 0
	if not mod:
		return per(i, j) // fact(j)
	return per(i, j, mod) * ifa[j] % mod

def catalan(n):
	return com(2 * n, n) // (n + 1)

def linc(f, t, l, r):
	while l < r:
		mid = (l + r) // 2
		if t > f(mid):
			l = mid + 1
		else:
			r = mid
	return l

def rinc(f, t, l, r):
	while l < r:
		mid = (l + r + 1) // 2
		if t < f(mid):
			r = mid - 1
		else:
			l = mid
	return l

def ldec(f, t, l, r):
	while l < r:
		mid = (l + r) // 2
		if t < f(mid):
			l = mid + 1
		else:
			r = mid
	return l

def rdec(f, t, l, r):
	while l < r:
		mid = (l + r + 1) // 2
		if t > f(mid):
			r = mid - 1
		else:
			l = mid
	return l

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

def binfun(x):
	c = 0
	for w in arr:
		c += ceil(w / x)
	return c

def lowbit(n):
	return n & -n

def inverse(a, m):
	a %= m
	if a <= 1:
		return a
	return (1 - inverse(m, a) * m) // a % m

class BIT:

	def __init__(self, arr):
		self.arr = arr
		self.n = len(arr) - 1

	def update(self, x, v):
		while x <= self.n:
			self.arr[x] += v
			x += x & -x

	def query(self, x):
		ans = 0
		while x:
			ans += self.arr[x]
			x &= x - 1
		return ans

class DSU:

	def __init__(self, n):
		self.c = [-1] * n

	def same(self, x, y):
		return self.find(x) == self.find(y)

	def find(self, x):
		if self.c[x] < 0:
			return x
		self.c[x] = self.find(self.c[x])
		return self.c[x]

	def union(self, u, v):
		(u, v) = (self.find(u), self.find(v))
		if u == v:
			return False
		if self.c[u] < self.c[v]:
			(u, v) = (v, u)
		self.c[u] += self.c[v]
		self.c[v] = u
		return True

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

class UFS:

	def __init__(self, n):
		self.parent = [i for i in range(n)]
		self.ranks = [0] * n

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

	def union(self, u, v):
		(pu, pv) = (self.find(u), self.find(v))
		if pu == pv:
			return False
		if self.ranks[pu] >= self.ranks[pv]:
			self.parent[pv] = pu
			if self.ranks[pv] == self.ranks[pu]:
				self.ranks[pu] += 1
		else:
			self.parent[pu] = pv

def Prime(n):
	c = 0
	prime = []
	flag = [0] * (n + 1)
	for i in range(2, n + 1):
		if not flag[i]:
			prime.append(i)
			c += 1
		for j in range(c):
			if i * prime[j] > n:
				break
			flag[i * prime[j]] = prime[j]
			if i % prime[j] == 0:
				break
	return flag

def dij(s, graph):
	d = {}
	d[s] = 0
	heap = [(0, s)]
	seen = set()
	while heap:
		(dis, u) = heappop(heap)
		if u in seen:
			continue
		for v in graph[u]:
			if v not in d or d[v] > d[u] + graph[u][v]:
				d[v] = d[u] + graph[u][v]
				heappush(heap, (d[v], v))
	return d

def GP(it):
	return [[ch, len(list(g))] for (ch, g) in groupby(it)]

class DLN:

	def __init__(self, val):
		self.val = val
		self.pre = None
		self.next = None
t = N()
for i in range(t):
	n = N()
	a = RLL()
	b = RLL()
	i = 0
	j = n - 1
	ans = 'Yes'
	if n & 1:
		if a[n // 2] != b[n // 2]:
			ans = 'No'
			print(ans)
			continue
	c1 = Counter()
	c2 = Counter()
	while i < j:
		t = tuple(sorted([a[i], a[j]]))
		c1[t] += 1
		t = tuple(sorted([b[i], b[j]]))
		c2[t] += 1
		i += 1
		j -= 1
	if c1 != c2:
		ans = 'No'
	print(ans)


from os import path
import sys
from functools import cmp_to_key as ctk
from collections import deque, defaultdict as dd
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from itertools import permutations
from datetime import datetime
from math import ceil, sqrt, log, gcd

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

def si():
	return input()

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

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

def solve():
	for _ in range(ii()):
		n = ii()
		a = li()
		b = li()
		f = 1
		if n % 2 and a[n // 2] != b[n // 2]:
			f = 0
		m = {}
		for i in range(n // 2):
			x = [min(a[i], a[n - i - 1]), max(a[i], a[n - i - 1])]
			x = tuple(x)
			if x not in m:
				m[x] = 0
			m[x] += 1
		for i in range(n // 2):
			x = [min(b[i], b[n - i - 1]), max(b[i], b[n - i - 1])]
			x = tuple(x)
			if x not in m or m[x] == 0:
				f = 0
				break
			m[x] -= 1
		print('Yes' if f else 'No')
solve()


def solve():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if n % 2 == 1:
		if a[n // 2] != b[n // 2]:
			print('No')
			return
	(u, v) = (list(), list())

	def add(s, p, q):
		if p > q:
			(p, q) = (q, p)
		s.append((p, q))
	for i in range(n // 2):
		add(u, a[i], a[n - i - 1])
		add(v, b[i], b[n - i - 1])
	if sorted(u) == sorted(v):
		print('Yes')
	else:
		print('No')
t = int(input())
for _ in range(t):
	solve()


import collections
import time
import os
import sys
import bisect
import heapq
from typing import List

def solve(N, A, B):
	if N % 2 != 0:
		if A[N // 2] != B[N // 2]:
			return False
	wca = collections.defaultdict(int)
	for i in range(N // 2):
		(a, b) = (A[i], A[N - i - 1])
		wca[min(a, b), max(a, b)] += 1
	wcb = collections.defaultdict(int)
	for i in range(N // 2):
		(a, b) = (B[i], B[N - i - 1])
		wcb[min(a, b), max(a, b)] += 1
	return all([wca[k] == v for (k, v) in wcb.items()])
T = int(input())
ans = []
for ti in range(T):
	N = int(input())
	A = [int(x) for x in input().split()]
	B = [int(x) for x in input().split()]
	ans.append(solve(N, A, B))
print('\n'.join(['Yes' if v else 'No' for v in ans]))


import sys
input = sys.stdin.readline
import math
from collections import defaultdict
t = int(input())
for i in range(t):
	n = int(input())
	a = [int(i) for i in input().split() if i != '\n']
	b = [int(i) for i in input().split() if i != '\n']
	(dict1, dict2) = (defaultdict(int), defaultdict(int))
	(freq1, freq2) = (defaultdict(int), defaultdict(int))
	for j in range(math.ceil(n / 2)):
		dict1[min(a[j], a[-j - 1]), max(a[-j - 1], a[j])] += 1
		dict2[min(b[-j - 1], b[j]), max(b[j], b[-j - 1])] += 1
	for j in range(n):
		freq1[a[j]] += 1
		freq2[b[j]] += 1
	ok = True
	for j in dict1:
		for k in j:
			if freq1[k] != freq2[k]:
				ok = False
		if dict1[j] != dict2[j]:
			ok = False
			break
	if ok == True:
		print('Yes')
	else:
		print('No')


for i in range(int(input())):
	n = int(input())
	s1 = list(map(int, input().split()))
	s2 = list(map(int, input().split()))
	d1 = s1[::-1]
	d2 = s2[::-1]
	if sorted(zip(s1, d1)) == sorted(zip(s2, d2)):
		print('Yes')
	else:
		print('No')


from collections import Counter

def main():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	dic = Counter()
	m = n // 2
	if n & 1 and a[m] != b[m]:
		print('No')
		return
	for (x, y) in zip(a[:m], a[:-m - 1:-1]):
		dic[min(x, y), max(x, y)] += 1
	for (x, y) in zip(b[:m], b[:-m - 1:-1]):
		if dic[min(x, y), max(x, y)] <= 0:
			print('No')
			return
		dic[min(x, y), max(x, y)] -= 1
	print('Yes')
for _ in range(int(input())):
	main()


from collections import Counter
from collections import defaultdict
T = int(input())
for t in range(T):
	N = int(input())
	A = [int(_) for _ in input().split()]
	B = [int(_) for _ in input().split()]
	if Counter(A) != Counter(B):
		print('No')
		continue
	if N & 1:
		if A[N // 2] != B[N // 2]:
			print('No')
			continue
		A = A[:N // 2] + A[1 + N // 2:]
		B = B[:N // 2] + B[1 + N // 2:]
	N = len(A)
	cc = defaultdict(lambda : defaultdict(int))
	for i in range(N // 2):
		cc[A[i]][A[N - 1 - i]] += 1
		cc[A[N - 1 - i]][A[i]] += 1
	cc2 = defaultdict(lambda : defaultdict(int))
	for i in range(N // 2):
		cc2[B[i]][B[N - 1 - i]] += 1
		cc2[B[N - 1 - i]][B[i]] += 1
	if cc == cc2:
		print('Yes')
	else:
		print('No')


import os
from io import BytesIO, IOBase
import sys
from collections import defaultdict, deque, Counter
from math import sqrt, pi, ceil, log, inf, gcd, floor
from itertools import combinations, permutations
from bisect import *
from fractions import Fraction
from heapq import *
from random import randint

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if n & 1 and a[n // 2] != b[n // 2]:
		return 'No'
	c = Counter()
	d = Counter()
	for i in range(n // 2):
		c[min(a[i], a[-(i + 1)]), max(a[i], a[-(i + 1)])] += 1
		d[min(b[i], b[-(i + 1)]), max(b[i], b[-(i + 1)])] += 1
	if c == d:
		return 'Yes'
	return 'No'

def main():
	for t in range(int(input())):
		print(solve())
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()


t = int(input())
for case in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	aCompressed = []
	b = list(map(int, input().split()))
	bCompressed = []
	validity = True
	if n % 2 != 0:
		if a[int(n / 2)] != b[int(n / 2)]:
			validity = False
	for i in range(int(n / 2)):
		aCompressed.append(min(a[i], a[-i - 1]) * 1000000001 + max(a[i], a[-i - 1]))
		bCompressed.append(min(b[i], b[-i - 1]) * 1000000001 + max(b[i], b[-i - 1]))
	aCompressed.sort()
	bCompressed.sort()
	for i in range(int(n / 2)):
		if aCompressed[i] != bCompressed[i]:
			validity = False
			break
	if validity:
		print('Yes')
	else:
		print('No')


from collections import *
t = int(input())
for y in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ca = Counter(a)
	cb = Counter(b)
	if ca != cb:
		print('No')
		continue
	vis = [0 for i in range(n)]
	for i in range((n + 1) // 2):
		f = 1
		for j in range(n):
			if vis[j] == 1:
				continue
			if b[j] == a[i] and b[n - 1 - j] == a[n - 1 - i]:
				vis[j] = 1
				vis[n - 1 - j] = 1
				f = 0
				break
		if f == 1:
			print('No')
			break
	else:
		print('Yes')


for _ in range(int(input())):
	n = int(input())
	a = [int(X) for X in input().split()]
	b = [int(x) for x in input().split()]
	an = 1
	if n % 2:
		if a[n // 2] != b[n // 2]:
			an = 0
	x = []
	y = []
	for i in range(n // 2):
		x.append(a[i] + a[n - 1 - i])
		y.append(b[i] + b[n - 1 - i])
	x.sort()
	y.sort()
	for i in range(len(x)):
		if x[i] != y[i]:
			an = 0
			break
	print('Yes' if an else 'No')


import sys
import math
input = sys.stdin.readline
t = int(input())
for cs in range(t):
	n = int(input())
	a = [int(_) for _ in input().split()]
	b = [int(_) for _ in input().split()]
	pa = []
	pb = []
	for i in range(n):
		j = n - i - 1
		if i > j:
			break
		if i < j:
			(p, q) = (a[i], a[j])
		elif i == j:
			(p, q) = (a[i], -1)
		if p > q:
			(p, q) = (q, p)
		pa.append((p, q))
	for i in range(n):
		j = n - i - 1
		if i > j:
			break
		if i < j:
			(p, q) = (b[i], b[j])
		elif i == j:
			(p, q) = (b[i], -1)
		if p > q:
			(p, q) = (q, p)
		pb.append((p, q))
	pa.sort()
	pb.sort()
	ans = True
	for i in range(len(pa)):
		for j in range(2):
			if pa[i][j] != pb[i][j]:
				ans = False
	print('Yes' if ans else 'No')


t = int(input())
for i in range(t):
	n = int(input())
	lis1 = [int(x) for x in input().split()]
	lis2 = [int(x) for x in input().split()]
	if n % 2 == 1:
		if lis1[n // 2] != lis2[n // 2]:
			print('No')
			continue
	dict1 = dict()
	for i in range(n // 2):
		str1 = str(lis1[i]) + ',' + str(lis1[n - i - 1])
		str2 = str(lis1[n - i - 1]) + ',' + str(lis1[i])
		if str1 in dict1.keys() or str2 in dict1.keys():
			if str1 in dict1.keys():
				dict1[str1] += 1
			else:
				dict1[str2] += 1
		else:
			dict1[str1] = 1
	badge = 0
	for i in range(n // 2):
		str1 = str(lis2[i]) + ',' + str(lis2[n - i - 1])
		if str1 in dict1.keys():
			dict1[str1] -= 1
			if dict1[str1] == 0:
				del dict1[str1]
		else:
			str2 = str(lis2[n - i - 1]) + ',' + str(lis2[i])
			if str2 in dict1.keys():
				dict1[str2] -= 1
				if dict1[str2] == 0:
					del dict1[str2]
			else:
				badge = 1
				break
	if badge == 0:
		print('Yes')
	else:
		print('No')


import copy
wer = int(input())
for ewr in range(wer):
	a = int(input())
	n = list(map(int, input().split(' ')))
	m = list(map(int, input().split(' ')))
	if a == 1:
		if n[0] != m[0]:
			print('No')
			continue
		else:
			print('Yes')
			continue
	if a % 2 == 1:
		r = int(a / 2)
		if n[r] != m[r]:
			print('No')
			continue
	er = int(a / 2)
	flag = 0
	for i in range(er):
		p = n[i]
		q = n[a - 1 - i]
		tre = 0
		for w in range(er):
			if m[w] == p and m[a - 1 - w] == q:
				tre = 1
				m[w] = -100
				m[a - 1 - w] = -100
				break
			if m[w] == q and m[a - 1 - w] == p:
				tre = 1
				m[w] = -100
				m[a - 1 - w] = -100
				break
		if tre == 0:
			flag = 1
			break
	if flag == 1:
		print('No')
	else:
		print('Yes')


import sys
import bisect as b
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if a == b:
		print('Yes')
	elif sorted(a) != sorted(b):
		print('No')
	elif n % 2 != 0 and a[n // 2] != b[n // 2]:
		print('No')
	else:
		(l, l1) = ([], [])
		for i in range(0, n // 2):
			l.append((max(a[i], a[n - i - 1]), min(a[i], a[n - i - 1])))
			l1.append((max(b[i], b[n - i - 1]), min(b[i], b[n - i - 1])))
		l.sort()
		l1.sort()
		if l != l1:
			print('No')
		else:
			print('Yes')


t = int(input())
for o in range(t):
	n = int(input())
	a = list(map(int, input().strip().split()))
	b = list(map(int, input().strip().split()))
	aPairs = []
	bPairs = []
	oddBreaker = False
	if n % 2:
		if a[n // 2] != b[n // 2]:
			oddBreaker = True
	for i in range(n // 2):
		v = a[i]
		w = a[-1 - i]
		x = b[i]
		y = b[-1 - i]
		minA = min(v, w)
		maxA = max(v, w)
		minB = min(x, y)
		maxB = max(x, y)
		aPairs.append([minA, maxA])
		bPairs.append([minB, maxB])
	aPairs.sort()
	bPairs.sort()
	if aPairs != bPairs or oddBreaker:
		print('No')
	else:
		print('Yes')


t = int(input())
for i in range(t):
	l = int(input())
	if l <= 1:
		g = int(input())
		f = int(input())
		if g == f:
			print('Yes')
		else:
			print('No')
	else:
		a = []
		b = []
		a = list(map(int, input().split()))
		b = list(map(int, input().split()))
		m = [[min(a[0], a[-1]), max(a[0], a[-1])]]
		flag = 1
		for i in range(1, l // 2):
			m.append([min(a[i], a[l - i - 1]), max(a[i], a[l - i - 1])])
		for i in range(l // 2):
			test = [min(b[i], b[l - i - 1]), max(b[i], b[l - i - 1])]
			flag = 0
			for j in range(len(m)):
				if test == m[j]:
					flag = 1
					del m[j]
					break
			if flag == 0:
				break
		if flag:
			if l % 2:
				if a[l // 2] == b[l // 2]:
					print('Yes')
				else:
					print('No')
			else:
				print('Yes')
		else:
			print('No')


from collections import defaultdict
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	tf = True
	if n % 2 == 1:
		if a[n // 2] != b[n // 2]:
			tf = False
	if tf:
		d = defaultdict(int)
		for i in range(n // 2):
			(x, y) = (min(a[i], a[n - 1 - i]), max(a[i], a[n - 1 - i]))
			d[x, y] += 1
		for i in range(n // 2):
			(x, y) = (min(b[i], b[n - 1 - i]), max(b[i], b[n - 1 - i]))
			if d[x, y] > 0:
				d[x, y] -= 1
			else:
				tf = False
				break
		if tf:
			print('Yes')
		else:
			print('No')
	else:
		print('No')


import math
import random
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
import threading
from collections import defaultdict
threading.stack_size(10 ** 8)
mod = 10 ** 9 + 7
mod1 = 998244353
import os
import sys
from io import BytesIO, IOBase
sys.setrecursionlimit(300000)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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

class TreeNode:

	def __init__(self, k, v):
		self.key = k
		self.value = v
		self.left = None
		self.right = None
		self.parent = None
		self.height = 1
		self.num_left = 1
		self.num_total = 1

class AvlTree:

	def __init__(self):
		self._tree = None

	def add(self, k, v):
		if not self._tree:
			self._tree = TreeNode(k, v)
			return
		node = self._add(k, v)
		if node:
			self._rebalance(node)

	def _add(self, k, v):
		node = self._tree
		while node:
			if k < node.key:
				if node.left:
					node = node.left
				else:
					node.left = TreeNode(k, v)
					node.left.parent = node
					return node.left
			elif node.key < k:
				if node.right:
					node = node.right
				else:
					node.right = TreeNode(k, v)
					node.right.parent = node
					return node.right
			else:
				node.value = v
				return

	@staticmethod
	def get_height(x):
		return x.height if x else 0

	@staticmethod
	def get_num_total(x):
		return x.num_total if x else 0

	def _rebalance(self, node):
		n = node
		while n:
			lh = self.get_height(n.left)
			rh = self.get_height(n.right)
			n.height = max(lh, rh) + 1
			balance_factor = lh - rh
			n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
			n.num_left = 1 + self.get_num_total(n.left)
			if balance_factor > 1:
				if self.get_height(n.left.left) < self.get_height(n.left.right):
					self._rotate_left(n.left)
				self._rotate_right(n)
			elif balance_factor < -1:
				if self.get_height(n.right.right) < self.get_height(n.right.left):
					self._rotate_right(n.right)
				self._rotate_left(n)
			else:
				n = n.parent

	def _remove_one(self, node):
		replacement = node.left or node.right
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = replacement
			else:
				node.parent.right = replacement
			replacement.parent = node.parent
			node.parent = None
		else:
			self._tree = replacement
			replacement.parent = None
		node.left = None
		node.right = None
		node.parent = None
		self._rebalance(replacement)

	def _remove_leaf(self, node):
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = None
			else:
				node.parent.right = None
			self._rebalance(node.parent)
		else:
			self._tree = None
		node.parent = None
		node.left = None
		node.right = None

	def remove(self, k):
		node = self._get_node(k)
		if not node:
			return
		if AvlTree._is_leaf(node):
			self._remove_leaf(node)
			return
		if node.left and node.right:
			nxt = AvlTree._get_next(node)
			node.key = nxt.key
			node.value = nxt.value
			if self._is_leaf(nxt):
				self._remove_leaf(nxt)
			else:
				self._remove_one(nxt)
			self._rebalance(node)
		else:
			self._remove_one(node)

	def get(self, k):
		node = self._get_node(k)
		return node.value if node else -1

	def _get_node(self, k):
		if not self._tree:
			return None
		node = self._tree
		while node:
			if k < node.key:
				node = node.left
			elif node.key < k:
				node = node.right
			else:
				return node
		return None

	def get_at(self, pos):
		x = pos + 1
		node = self._tree
		while node:
			if x < node.num_left:
				node = node.left
			elif node.num_left < x:
				x -= node.num_left
				node = node.right
			else:
				return (node.key, node.value)
		raise IndexError('Out of ranges')

	@staticmethod
	def _is_left(node):
		return node.parent.left and node.parent.left == node

	@staticmethod
	def _is_leaf(node):
		return node.left is None and node.right is None

	def _rotate_right(self, node):
		if not node.parent:
			self._tree = node.left
			node.left.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.left
			node.left.parent = node.parent
		else:
			node.parent.right = node.left
			node.left.parent = node.parent
		bk = node.left.right
		node.left.right = node
		node.parent = node.left
		node.left = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	def _rotate_left(self, node):
		if not node.parent:
			self._tree = node.right
			node.right.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.right
			node.right.parent = node.parent
		else:
			node.parent.right = node.right
			node.right.parent = node.parent
		bk = node.right.left
		node.right.left = node
		node.parent = node.right
		node.right = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	@staticmethod
	def _get_next(node):
		if not node.right:
			return node.parent
		n = node.right
		while n.left:
			n = n.left
		return n

class SegmentTree1:

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

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

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

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

	def __len__(self):
		return self._len

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

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

class SegmentTree:

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

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

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

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

	def __len__(self):
		return self._len

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

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

class Factorial:

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

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

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

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

class Combination:

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

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

def powm(a, n, m):
	if a == 1 or n == 0:
		return 1
	if n % 2 == 0:
		s = powm(a, n // 2, m)
		return s * s % m
	else:
		return a * powm(a, n - 1, m) % m

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z

def product(l):
	por = 1
	for i in range(len(l)):
		por *= l[i]
	return por

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] < key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def binary(x, length):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y

def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] >= k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater
for ik in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	l1 = list(map(int, input().split()))
	d = defaultdict(int)
	if n % 2 == 1:
		if l[n // 2] != l1[n // 2]:
			print('No')
			continue
	for i in range(n // 2):
		if l[i] > l[n - 1 - i]:
			(l[i], l[n - 1 - i]) = (l[n - 1 - i], l[i])
		if l1[i] > l1[n - 1 - i]:
			(l1[i], l1[n - 1 - i]) = (l1[n - 1 - i], l1[i])
		d[l[i], l[n - 1 - i]] += 1
		d[l1[i], l1[n - 1 - i]] -= 1
	if len(d) == 0 or max(d.values()) == min(d.values()) == 0:
		print('Yes')
	else:
		print('No')


for _ in range(int(input())):
	n = int(input())
	a = [int(c) for c in input().split()]
	b = [int(c) for c in input().split()]
	ad = sorted(a)
	bd = sorted(b)
	if ad != bd:
		print('No')
		continue
	if n % 2 == 1:
		if a[n // 2] != b[n // 2]:
			print('No')
			continue
	dic = {}
	for i in range(n // 2):
		c = a[i]
		d = a[n - 1 - i]
		pair = (min(c, d), max(c, d))
		dic[pair] = dic.get(pair, 0) + 1
	for i in range(n // 2):
		c = b[i]
		d = b[n - 1 - i]
		pair = (min(c, d), max(c, d))
		if dic.get(pair, -1) <= 0:
			print('No')
			break
		else:
			dic[pair] -= 1
	else:
		print('Yes')


from sys import stdin, stdout
import sys
t = int(stdin.readline().strip())
for _ in range(t):
	n = int(stdin.readline().strip())
	a = list(map(int, stdin.readline().strip().split(' ')))
	b = list(map(int, stdin.readline().strip().split(' ')))
	d = {}
	for i in range(n // 2):
		t1 = b[i]
		t2 = b[n - 1 - i]
		if t1 > t2:
			(t1, t2) = (t2, t1)
		if t1 in d:
			d[t1].append(t2)
		else:
			d[t1] = [t2]
	ans = True
	if n % 2 == 1:
		if a[n // 2] != b[n // 2]:
			ans = False
	for i in range(n // 2):
		t1 = a[i]
		t2 = a[n - 1 - i]
		if t1 > t2:
			(t1, t2) = (t2, t1)
		if t1 in d:
			if t2 in d[t1]:
				d[t1].remove(t2)
			else:
				ans = False
				break
		else:
			ans = False
			break
	if ans:
		stdout.write('Yes\n')
	else:
		stdout.write('No\n')


from sys import stdin, stdout
from collections import defaultdict

def main():
	t = int(stdin.readline())
	for _ in range(t):
		n = int(stdin.readline())
		a = list(map(int, stdin.readline().split()))
		b = list(map(int, stdin.readline().split()))
		if n % 2 == 1 and a[int(n / 2)] != b[int(n / 2)]:
			stdout.write('No\n')
			continue
		dic_a = defaultdict(int)
		dic_b = defaultdict(int)
		for i in range(int(n / 2)):
			left = a[i]
			right = a[n - i - 1]
			(left, right) = (min(left, right), max(left, right))
			dic_a[left, right] += 1
			left = b[i]
			right = b[n - i - 1]
			(left, right) = (min(left, right), max(left, right))
			dic_b[left, right] += 1
		is_ok = True
		for (x, c) in dic_a.items():
			if x not in dic_b or dic_b[x] != c:
				is_ok = False
				break
		if is_ok:
			stdout.write('Yes\n')
		else:
			stdout.write('No\n')
main()


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

def solve(N, A, B):
	if N % 2 == 1:
		if A[N // 2] != B[N // 2]:
			return 'No'
	for i in range(N // 2):
		if A[i] > A[N - i - 1]:
			(A[i], A[N - i - 1]) = (A[N - i - 1], A[i])
		if B[i] > B[N - i - 1]:
			(B[i], B[N - i - 1]) = (B[N - i - 1], B[i])
	A = zip(A[:N // 2], A[-N // 2:][::-1])
	B = zip(B[:N // 2], B[-N // 2:][::-1])
	if sorted(A) == sorted(B):
		return 'Yes'
	return 'No'
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
T = int(input())
for t in range(T):
	(N,) = [int(x) for x in input().split()]
	A = [int(x) for x in input().split()]
	B = [int(x) for x in input().split()]
	ans = solve(N, A, B)
	print(ans)


import sys

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

def idata():
	return [int(x) for x in ii().split()]

def solve_of_problem():
	n = int(ii())
	data = idata()
	data1 = idata()
	if n == 1:
		if data1 == data:
			print('Yes')
		else:
			print('No')
		return
	if sorted(data) != sorted(data1):
		print('No')
		return
	if n % 2 == 1:
		if data[n // 2] != data1[n // 2]:
			print('No')
			return
		data = data[:n // 2] + data[n // 2 + 1:]
		data1 = data1[:n // 2] + data1[n // 2 + 1:]
		n -= 1
	d = dict()
	for i in range(n // 2):
		d[str(data[i]) + ' ' + str(data[n - i - 1])] = 0
		d[str(data[n - 1 - i]) + ' ' + str(data[i])] = 0
		d[str(data1[i]) + ' ' + str(data1[n - i - 1])] = 0
		d[str(data1[n - 1 - i]) + ' ' + str(data1[i])] = 0
	for i in range(n // 2):
		d[str(data[i]) + ' ' + str(data[n - i - 1])] += 1
		d[str(data[n - 1 - i]) + ' ' + str(data[i])] += 1
		d[str(data1[i]) + ' ' + str(data1[n - i - 1])] -= 1
		d[str(data1[n - 1 - i]) + ' ' + str(data1[i])] -= 1
	if min(d.values()) < 0:
		print('No')
		return
	print('Yes')
	return
for ______ in range(int(ii())):
	solve_of_problem()


import bisect
import sys
import math
input = sys.stdin.readline
from collections import defaultdict
from collections import Counter

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

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

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

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

def solve(case):
	n = inp()
	aa = inlt()
	bb = inlt()
	ac = Counter(aa)
	bc = Counter(bb)
	if ac != bc:
		return 'No'
	if n % 2 == 1 and ac[n // 2] != bc[n // 2]:
		return 'No'
	i = 0
	j = n - 1
	aaa = []
	bbb = []
	while i < j:
		aaa.append((min(aa[i], aa[j]), max(aa[i], aa[j])))
		bbb.append((min(bb[i], bb[j]), max(bb[i], bb[j])))
		i += 1
		j -= 1
	aaa.sort()
	bbb.sort()
	if all((aaa[i] == bbb[i] for i in range(0, len(aaa)))):
		return 'Yes'
	else:
		return 'No'
if len(sys.argv) > 1 and sys.argv[1].startswith('input'):
	f = open('./' + sys.argv[1], 'r')
	input = f.readline
T = inp()
for i in range(T):
	res = solve(i + 1)
	print(str(res))


def is_equal(a1, a2, n):
	if n % 2 == 1 and a1[n // 2] != a2[n // 2]:
		return False
	arr1 = create(a1)
	arr2 = create(a2)
	for (u, v) in zip(arr1, arr2):
		if u != v:
			return False
	return True

def create(a):
	arr = []
	n = len(a)
	for i in range(n // 2):
		if a[i] <= a[n - i - 1]:
			arr.append((a[i], a[n - i - 1]))
		else:
			arr.append((a[n - i - 1], a[i]))
	return sorted(arr)
for _ in range(int(input())):
	n = int(input())
	a1 = list(map(int, input().split()))
	a2 = list(map(int, input().split()))
	if is_equal(a1, a2, n) == True:
		print('Yes')
	else:
		print('No')


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

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

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

def main():

	def solve():
		n = int(inputi())
		aa = [int(a) for a in inputi().split()]
		bb = [int(a) for a in inputi().split()]
		if n % 2 == 1 and aa[n // 2] != bb[n // 2]:
			print('No')
			return
		apairs = {}
		bpairs = {}
		for i in range(n // 2):
			ap = frozenset((aa[i], aa[-i - 1]))
			apairs[ap] = apairs.get(ap, 0) + 1
			bp = frozenset((bb[i], bb[-i - 1]))
			bpairs[bp] = bpairs.get(bp, 0) + 1
		if apairs == bpairs:
			print('Yes')
		else:
			print('No')
	t = int(inputi())
	for _ in range(t):
		solve()
main()


for _ in range(int(input())):
	m = int(input())
	k = list(map(int, input().split()))
	l = list(map(int, input().split()))
	if sorted(zip(k, k[::-1])) == sorted(zip(l, l[::-1])):
		print('Yes')
	else:
		print('No')


for _ in range(int(input())):
	n = int(input())
	k = n // 2
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	dicA = {}
	dicB = {}
	for i in range(k):
		(p, q) = (a[i], a[-i - 1])
		if p > q:
			if (q, p) not in dicA:
				dicA[q, p] = 0
			dicA[q, p] += 1
		else:
			if (p, q) not in dicA:
				dicA[p, q] = 0
			dicA[p, q] += 1
	for i in range(k):
		(p, q) = (b[i], b[-i - 1])
		if p > q:
			if (q, p) not in dicB:
				dicB[q, p] = 0
			dicB[q, p] += 1
		else:
			if (p, q) not in dicB:
				dicB[p, q] = 0
			dicB[p, q] += 1
	if n % 2 == 1:
		if a[k] != b[k]:
			print('No')
		else:
			res = 'Yes'
			for (p, q) in dicA:
				if (p, q) not in dicB:
					res = 'No'
				elif dicA[p, q] != dicB[p, q]:
					res = 'No'
			print(res)
	else:
		res = 'Yes'
		for (p, q) in dicA:
			if (p, q) not in dicB:
				res = 'No'
			elif dicA[p, q] != dicB[p, q]:
				res = 'No'
		print(res)


for _ in range(int(input())):
	(n, a, b) = (int(input()), list(map(int, input().split())), list(map(int, input().split())))
	(a1, b1) = ([], [])
	for i in range((n + 1) // 2):
		a1.append([min(a[i], a[n - i - 1]), max(a[i], a[n - i - 1])])
		b1.append([min(b[i], b[n - i - 1]), max(b[i], b[n - i - 1])])
	a.sort()
	b.sort()
	if n % 2 and a[n // 2] != b[n // 2]:
		print('No')
		continue
	a1.sort()
	b1.sort()
	print('Yes' if a1 == b1 else 'No')


from collections import defaultdict

def solve(a, b):
	n = len(a)
	if n % 2 != 0:
		if a[n // 2] != b[n // 2]:
			return False
	counts = defaultdict(int)
	i = 0
	j = n - 1
	while i < j:
		counts[min(a[i], a[j]), max(a[i], a[j])] += 1
		i += 1
		j -= 1
	(i, j) = (0, n - 1)
	counts2 = defaultdict(int)
	while i < j:
		counts2[min(b[i], b[j]), max(b[i], b[j])] += 1
		i += 1
		j -= 1
	return counts == counts2
t = int(input())
for _ in range(t):
	input()
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if solve(a, b):
		print('Yes')
	else:
		print('No')


import sys

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

def N():
	return int(input())

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

def L():
	return list(NM())

def LN(n):
	return [N() for i in range(n)]

def LL(n):
	return [L() for i in range(n)]
t = N()
import collections

def f():
	n = N()
	a = L()
	if n % 2:
		m = a[n // 2]
	d = collections.defaultdict(int)
	for i in range(n // 2):
		(x, y) = (a[i], a[-1 - i])
		if y < x:
			(x, y) = (y, x)
		d[x, y] += 1
	a = L()
	if n % 2:
		if m != a[n // 2]:
			print('No')
			return
	for i in range(n // 2):
		(x, y) = (a[i], a[-1 - i])
		if y < x:
			(x, y) = (y, x)
		if d[x, y] == 0:
			print('No')
			return
		d[x, y] -= 1
	print('Yes')
	return
for i in range(t):
	f()


cases = int(input())
answers = [] * 0
for problems in range(cases):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	s1 = sorted(a)
	s2 = sorted(b)
	pairs = [] * 0
	for i in range(n // 2):
		pairs.append(sorted([a[i], a[-1 - i]]))
	if s1 != s2:
		answers.append('No')
	elif n % 2 == 1 and a[(n - 1) // 2] != b[(n - 1) // 2]:
		answers.append('No')
	else:
		bOk = True
		for i in range(n // 2):
			if sorted([b[i], b[-1 - i]]) in pairs:
				pairs.remove(sorted([b[i], b[-1 - i]]))
			else:
				bOk = False
		answers.append('Yes') if bOk else answers.append('No')
for answer in answers:
	print(answer)


test = int(input())
number = []
col_a = []
col_b = []
for i in range(test):
	number.append(int(input()))
	col_a.append(list(map(int, input().split())))
	col_b.append(list(map(int, input().split())))
for i in range(test):
	if number[i] % 2 == 1:
		if col_a[i][int((number[i] - 1) / 2)] != col_b[i][int((number[i] - 1) / 2)]:
			print('No')
		else:
			pair_a = []
			pair_b = []
			mark = [0 for k in range(int((number[i] - 1) / 2))]
			for j in range(int((number[i] - 1) / 2)):
				pair_a.append([col_a[i][j], col_a[i][number[i] - 1 - j]])
				pair_b.append([col_b[i][j], col_b[i][number[i] - 1 - j]])
			no = 0
			for j in range(len(pair_b)):
				markble = 0
				for k in range(len(pair_a)):
					if mark[k] == 0:
						if pair_a[k][0] == pair_b[j][0] and pair_a[k][1] == pair_b[j][1]:
							mark[k] = 1
							markble = 1
							break
						elif pair_a[k][0] == pair_b[j][1] and pair_a[k][1] == pair_b[j][0]:
							mark[k] = 1
							markble = 1
							break
				if markble == 0:
					no = 1
					break
			if no == 1:
				print('No')
			else:
				print('Yes')
	else:
		pair_a = []
		pair_b = []
		mark = [0 for k in range(int(number[i] / 2))]
		for j in range(int(number[i] / 2)):
			pair_a.append([col_a[i][j], col_a[i][number[i] - 1 - j]])
			pair_b.append([col_b[i][j], col_b[i][number[i] - 1 - j]])
		no = 0
		for j in range(len(pair_b)):
			markble = 0
			for k in range(len(pair_a)):
				if mark[k] == 0:
					if pair_a[k][0] == pair_b[j][0] and pair_a[k][1] == pair_b[j][1]:
						mark[k] = 1
						markble = 1
						break
					elif pair_a[k][0] == pair_b[j][1] and pair_a[k][1] == pair_b[j][0]:
						mark[k] = 1
						markble = 1
						break
			if markble == 0:
				no = 1
				break
		if no == 1:
			print('No')
		else:
			print('Yes')


from collections import defaultdict
for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	d = defaultdict(int)
	f = 0
	if n % 2 != 0:
		if a[n // 2] != b[n // 2]:
			print('No')
			continue
	for i in range(n // 2):
		p = (min(a[i], a[n - i - 1]), max(a[i], a[n - i - 1]))
		d[p] += 1
	for i in range(n // 2):
		p = (min(b[i], b[n - i - 1]), max(b[i], b[n - i - 1]))
		if d[p] <= 0:
			print('No')
			f = 1
			break
		d[p] -= 1
	if f == 0:
		print('Yes')


import sys
INF = 10 ** 20
MOD = 10 ** 9 + 7
I = lambda : list(map(int, input().split()))
from math import gcd
from math import ceil
from collections import defaultdict as dd, Counter
from bisect import bisect_left as bl, bisect_right as br

def solve():
	(n,) = I()
	a = I()
	b = I()
	if n % 2 and a[n // 2] != b[n // 2]:
		print('No')
		return
	pairs = dd(int)
	bpair = dd(int)
	for i in range(n // 2):
		(x, y) = (a[i], a[n - i - 1])
		if x > y:
			(x, y) = (y, x)
		pairs[x, y] += 1
		(x, y) = (b[i], b[n - i - 1])
		if x > y:
			(x, y) = (y, x)
		bpair[x, y] += 1
	for i in pairs:
		if pairs[i] != bpair[i]:
			print('No')
			return
	print('Yes')
(t,) = I()
while t:
	t -= 1
	solve()


import sys, os, io

def rs():
	return sys.stdin.readline().rstrip()

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

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

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
from collections import Counter

def solve(n, a, b):
	if n % 2 == 1 and a[n // 2] != b[n // 2]:
		return False
	pa = [(min(a[i], a[n - i - 1]), max(a[i], a[n - i - 1])) for i in range(n // 2)]
	pb = [(min(b[i], b[n - i - 1]), max(b[i], b[n - i - 1])) for i in range(n // 2)]
	ca = Counter(pa)
	cb = Counter(pb)
	return ca == cb

def main():
	for _ in range(ri()):
		n = ri()
		a = ria()
		b = ria()
		ws('Yes' if solve(n, a, b) else 'No')
main()


import math as mt
import sys, string
input = sys.stdin.readline
from collections import defaultdict
from heapq import heappush, heapify, heappop
L = lambda : list(map(int, input().split()))
Ls = lambda : list(input().split())
M = lambda : map(int, input().split())
I = lambda : int(input())
t = I()
for _ in range(t):
	n = I()
	l = L()
	b = L()
	c = 0
	f = 1
	if n % 2 == 1 and l[n // 2] != b[n // 2]:
		print('No')
		f = 0
	else:
		x = []
		y = []
		for i in range(n // 2):
			x.append(sorted([l[i], l[-(i + 1)]]))
			y.append(sorted([b[i], b[-(i + 1)]]))
		if sorted(x) != sorted(y):
			print('No')
		else:
			print('Yes')


import sys
import math

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

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

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

def SI():
	return sys.stdin.readline().strip()
t = II()
for q in range(t):
	n = II()
	a = LI()
	b = LI()
	if sorted(a) != sorted(b) or (n % 2 == 1 and a[n // 2] != b[n // 2]):
		print('No')
	else:
		x = []
		y = []
		for i in range(n // 2):
			x.append(tuple(sorted([a[i], a[n - 1 - i]])))
			y.append(tuple(sorted([b[i], b[n - 1 - i]])))
		print('Yes' if sorted(x) == sorted(y) else 'No')


T = int(input())
X = []
for i in range(0, T):
	C = []
	D = []
	n = int(input())
	A = [int(x) for x in input().split(' ')]
	B = [int(x) for x in input().split(' ')]
	for i in range(0, len(A) // 2):
		a = [A[i], A[len(A) - 1 - i]]
		b = [B[i], B[len(A) - 1 - i]]
		a.sort()
		b.sort()
		C.append(a)
		D.append(b)
	C.sort()
	D.sort()
	if n % 2 == 1 and A[n // 2] == B[n // 2] and (C == D):
		X.append('Yes')
	elif n % 2 == 0 and C == D:
		X.append('Yes')
	else:
		X.append('No')
for i in X:
	print(i)


q = int(input())
for _ in range(q):
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	x1 = 0
	x2 = 0
	if n % 2 == 1:
		x1 = l1.pop(n // 2)
		x2 = l2.pop(n // 2)
	if x1 != x2:
		print('No')
	else:
		if n % 2 == 1:
			n -= 1
		d1 = []
		d2 = []
		for i in range(n // 2):
			d1.append([min(l1[i], l1[n - i - 1]), max(l1[i], l1[n - i - 1])])
			d2.append([min(l2[i], l2[n - i - 1]), max(l2[i], l2[n - i - 1])])
		d1.sort()
		d2.sort()
		if d1 == d2:
			print('Yes')
		else:
			print('No')


for _ in range(int(input())):
	n = int(input())
	a = tuple(map(int, input().split()))
	b = tuple(map(int, input().split()))
	if sorted(zip(a, reversed(a))) == sorted(zip(b, reversed(b))):
		print('Yes')
	else:
		print('No')


import math
test = int(input())
a = []
b = []
for _ in range(test):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	sa = []
	sb = []
	for i in range(n):
		sa.append((min(a[i], a[n - i - 1]), max(a[i], a[n - i - 1])))
		sb.append((min(b[i], b[n - i - 1]), max(b[i], b[n - i - 1])))
	sa.sort()
	sb.sort()
	print('Yes' if sa == sb else 'No')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	d = {}
	f = True
	if n % 2 != 0 and a[n // 2] != b[n // 2]:
		f = False
	for i in range(n // 2):
		mn = min(a[i], a[n - i - 1])
		mx = max(a[i], a[n - i - 1])
		p = (mn, mx)
		if p not in d:
			d[p] = 0
		d[p] += 1
	for i in range(n // 2):
		mn = min(b[i], b[n - i - 1])
		mx = max(b[i], b[n - i - 1])
		p = (mn, mx)
		if p not in d or d[p] <= 0:
			f = False
			break
		d[p] -= 1
	if f:
		print('Yes')
	else:
		print('No')