N = int(input())
for _ in range(N):
    n = int(input())
    in_list = list(map(int,input().split()))
    res_list = list(map(int,input().split()))
    stack = []
    out = []
    j = 0
    for i in in_list:
        stack.append(i)
        while stack:
            if stack[-1] == res_list[j]:
                out.append(stack.pop())
                j += 1
            else:
                break
    if out == res_list:
        print("Yes")
    else:
        print("No")