#include using namespace std; #define int long long int32_t main() { ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); int t;cin>>t; while(t--) { int n;cin>>n; int a[n];for(int i=0;i>a[i];--a[i];} int b[n];for(int i=0;i>b[i];--b[i];} bool ok[n]={0}; int u[n][20];for(int i=0;i v) { multiset d;for(int i:v) d.insert(b[i]); for(int i=0;i1) { bool ok1=false; bool ok2=true; for(int i=0;i v; int j=i; while(true) { if(h[j]) break; h[j]=true;v.push_back(j); j=a[j]; } res&=check(v); } } puts(res ? "Yes" : "No"); } return 0; }