import sys input = sys.stdin.readline x=10**6 import math L=math.floor(math.sqrt(x)) # 平方根を求める Primelist=[i for i in range(x+1)] Primelist[1]=0 # 1は素数でないので0にする. for i in Primelist: if i>L: break if i==0: continue for j in range(2*i,x+1,i): Primelist[j]=0 Primes=[Primelist[j] for j in range(x+1) if Primelist[j]!=0] Primes=set(Primes) T=int(input()) for tests in range(T): N=int(input()) A=list(map(int,input().split())) B=list(map(int,input().split())) flag=1 if sorted(A)!=sorted(B): print("No") continue if A[0]!=B[0]: print("No") continue for i in range(N): if (i+1) in Primes and (i+1)>N//2 and A[i]!=B[i]: flag=0 break if flag==1: print("Yes") else: print("No")