M=10**5 primeset=set() isprime=[1]*(M+1) isprime[0]=isprime[1]=0 for i in range(2,M+1): if not isprime[i]: continue primeset.add(i) for j in range(i*i,M+1,i): isprime[j]=0 def solve(N,A,B): if sorted(A)!=sorted(B): return False if A[0]!=B[0]: return False for i in range(1,N+1): if i not in primeset: continue if i*2<=N: continue if A[i-1]!=B[i-1]: return False else: return True def main(): T=int(input()) ans=[] for _ in range(T): N=int(input()) A=list(map(int,input().split())) B=list(map(int,input().split())) ans.append('Yes' if solve(N,A,B) else 'No') print(*ans,sep='\n') main()