import scala.collection.mutable import scala.collection.mutable.ArrayBuffer import scala.io.StdIn.* import scala.util.chaining.* import scala.math.* def calcPrime(upperLimit: Int): Array[Int] = val isPrime = Array.fill(upperLimit + 1){true} for p <- 2 to sqrt(upperLimit).toInt do if isPrime(p) then for j <- p * p to upperLimit by p do isPrime(j) = false (2 to upperLimit).filter(isPrime).toArray extension (array: Array[Int]) def upperBound(value: Int): Int = var min = 0 var max = array.length while min < max do val mid = (min + max) >>> 1 if array(mid) <= value then min = mid + 1 else max = mid max @main def main = val prime = calcPrime(100000) val testCase = readLine().toInt val isOk = Array.fill(testCase){false} for t <- 0 until testCase do val n = readLine().toInt val a = readLine().split(' ').map(_.toInt) val b = readLine().split(' ').map(_.toInt) if a.sorted sameElements b.sorted then isOk(t) = a(0) == b(0) && (prime.upperBound(n / 2) until prime.upperBound(n)).forall(i => a(prime(i) - 1) == b(prime(i) - 1)) println( isOk.map(if _ then "Yes" else "No").mkString("\n") )