import sys
def check():
#n个元素
n = int(input())
#输入的元素
pushed = list(map(int,input().split()))
#输出顺序
poped = list(map(int,input().split()))
#辅助栈,用于模拟入栈出栈
stack = []
#定位出栈顺序
j = 0
for num in pushed:
#将输入的元素一个压入栈中
stack.append(num)
#同时比较辅助栈栈顶元素是否为,出栈顺序,相同则可以出栈,j++
while (stack and j<n and stack[-1]==poped[j]):
stack.pop()
j+=1
#栈为空则证明顺序正确
if not stack:
print("Yes")
#非空则为顺序有问题
else:
print("No")
N = int(input())
for _ in range(N):
check()

京公网安备 11010502036488号