import java.io.PrintWriter import java.util.* import kotlin.math.* fun isprime(n: Int): Boolean { if (n == 1) return false var d = 2 while (d * d <= n) { if (n % d == 0) return false d++ } return true } fun PrintWriter.solve() { val numCases = nextInt() case@ for (_i in 0 until numCases) { val n = nextInt() val a = Array(n) { nextInt() } val b = Array(n) { nextInt() } val la = mutableListOf() val lb = mutableListOf() for (i in 0 until n) { if (i == 0 || (isprime(i + 1) && 2 * i > n)) { if (a[i] != b[i]) { println("No") continue@case } } else { la.add(a[i]) lb.add(b[i]) } } val arr_a = la.sorted().toTypedArray() val arr_b = lb.sorted().toTypedArray() if (arr_a.contentEquals(arr_b)) { println("Yes") } else { println("No") } } } fun main() { Thread(null, { val writer = PrintWriter(System.out, false) writer.solve() writer.flush() }, "solve", 1.shl(26)) .apply { setUncaughtExceptionHandler { _, e -> e.printStackTrace(); kotlin.system.exitProcess(1) } } .apply { start() }.join() } // region Scanner private var st = StringTokenizer("") private val br = System.`in`.bufferedReader() fun next(): String { while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine()) return st.nextToken() } fun nextInt() = next().toInt() fun nextLong() = next().toLong() fun nextLine() = br.readLine() fun nextDouble() = next().toDouble() // endregion