import math def isPrime(n): if n == 1: return False for k in range(2, int(math.sqrt(n)) + 1): if n % k == 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")