#include #include #include #include #include #include #include #include #include #include using namespace std; void solve(){ int N; cin >> N; vector A(N), B(N); multiset st1, st2; for (int i=0; i> A[i]; st1.insert(A[i]); } for (int i=0; i> B[i]; st2.insert(B[i]); } if (st1 != st2){ cout << "No" << endl; return; } vector ok(N+1, 1); for (int i=2; i<=N/2; i++){ for (int j=i; j<=N; j+=i) ok[j] = 0; } for (int i=1; i<=N; i++){ if (ok[i]){ if (A[i-1] != B[i-1]){ cout << "No" << endl; return; } } } cout << "Yes" << endl; return; } int main(){ long long T; cin >> T; while(T){ solve(); T--; } return 0; }