import sys n = int(input().strip()) for _ in range(n): length = int(input().strip()) pushed_s = list(map(int,input().strip().split(" "))) popped_s = list(map(int,input().strip().split(" "))) stack = [] j = 0 for i in range(length): stack.append(pushed_s[i]) while stack and stack[-1] == popped_s[j]: stack.pop() j += 1 if len(stack) == 0: print("Yes") else: print("No")