q = int(input().strip())
for _ in range(q):
t, j, n, pushed, popped = (
[],
0,
int(input().strip()),
list(map(str, input().strip().split(" "))),
list(map(str, input().strip().split(" "))),
)
for i in pushed:
t.append(i)
while t and t[-1] == popped[j]:
t.pop()
j += 1
print("Yes" if not t else "No")

京公网安备 11010502036488号