import std; const int N_MAX = 10 ^^ 5; int[] primes; bool solve(){ auto N = readln.chomp.to!int; auto A = readln.chomp.split(" ").to!(int[]); auto B = readln.chomp.split(" ").to!(int[]); if(A[0] != B[0]) return false; if(A.sort != B.sort) return false; auto i = primes.countUntil!(a => (a * 2 > N)); auto j = primes.countUntil!(a => (a > N)); foreach(p; primes[i .. j]){ if(A[p - 1] != B[p - 1]) return false; } return true; } void main(){ auto T = readln.chomp.to!int; primes ~= 2; for(auto n = 3; n <= N_MAX; n += 2){ auto f = true; foreach(p; primes){ if(n % p == 0){ f = false; break; } } if(f){ primes ~= n; } } for(auto t = 0; t < T; t++){ if(solve){ writeln("Yes"); }else{ writeln("No"); } } }