#include using namespace std; int N; int A[100009], B[100009]; bool isprime[100009]; void solve() { cin >> N; for (int i = 1; i <= N; i++) cin >> A[i]; for (int i = 1; i <= N; i++) cin >> B[i]; bool f = A[1] == B[1]; for (int i = 1; i <= N; i++) { if (!isprime[i]) continue; if (2*i > N) { f &= A[i] == B[i]; } } sort(A+1, A+N+1); sort(B+1, B+N+1); for (int i = 1; i <= N; i++) { f &= A[i] == B[i]; } if (f) cout << "Yes" << endl; else cout << "No" << endl; } int main() { for (int i = 2; i <= 100000; i++) isprime[i] = true; for (int i = 2; i <= 100000; i++) { if (!isprime[i]) continue; for (int j = 2*i; j <= 100000; j += i) isprime[j] = false; } int T; cin >> T; while (T--) { solve(); } }