import sys
s=int(input())
for _ in range(s):
    n=int(input())
    pushed=list(map(int,input().split()))
    poped=list(map(int,input().split()))
    stack=[]
    j=0
    for k in pushed:
        stack.append(k)
        while stack and stack[-1]==poped[j]:
            stack.pop()
            j+=1
    print("Yes" if not stack else "No")