#include #include #include #include using namespace std; using u32 = uint32_t; using u64 = uint64_t; #define rep(i,n) for(int i=0; i<(n); i++) void testcase(){ int N; cin >> N; vector A(N); rep(i,N) cin >> A[i]; vector B(N); rep(i,N) cin >> B[i]; atcoder::dsu G(N); for(int k=2; k<=N; k++) for(int i=2; k*i<=N; i++) G.merge(k-1,k*i-1); bool ok = true; for(auto& group : G.groups()){ vector tmpA; vector tmpB; for(auto a : group){ tmpA.push_back(A[a]); tmpB.push_back(B[a]); } sort(tmpA.begin(), tmpA.end()); sort(tmpB.begin(), tmpB.end()); if(tmpA != tmpB) ok = false; } if(ok) cout << "Yes\n"; else cout << "No\n"; } int main() { int T; cin >> T; while(T--) testcase(); return 0; } struct ios_do_not_sync{ ios_do_not_sync(){ ios::sync_with_stdio(false); cin.tie(nullptr); } } ios_do_not_sync_instance;