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() } for (i in 0 until n) { if (i == 0 || (isprime(i + 1) && 2 * (i + 1) > n)) { if (a[i] != b[i]) { println("No") continue@case } } } println("Yes") } } 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