T=int(input()) for i in range(T): N=int(input()) A=list(map(int,input().split())) B=list(map(int,input().split())) cnt=0 for j in range(N): if A[j]!=B[j]: #print(i,A[A[j]]) if A[A[j]-1]!=B[j]: if B[A[j]-1]!=B[j]: cnt+=1 #else: # A[j]=B[j] print("Yes" if cnt==0 else "No")