#yuki1779 import math def isPrime(n): if n==2: return True if n%2==0: return False m=math.floor(math.sqrt(n))+1 for p in range(3,m,2): if n%p==0: return False return True t=int(input()) for _ in range(t): n=int(input()) a=list(map(int,input().split())) b=list(map(int,input().split())) flag=0 for i in range(n): if(isPrime(i+1) and (i+1)*2>n) or i==0: if(a[i]!=b[i]): flag=1 if sorted(a)!=sorted(b): flag=1 if flag==0: print("Yes") else: print("No")