#include #include #include #include using namespace std; typedef pair P; template struct SegmentTree { using F = function; const F f; const T e; int n; vector seg; SegmentTree(int nn, const F f, const T e) : f(f), e(e){ n = 1; while(n <= nn) n <<= 1; seg.assign(n * 2, e); } void set(int i, T x){ seg[i + n] = x; } void build(){ for(int k = n - 1; k > 0; k--){ seg[k] = f(seg[k * 2], seg[k * 2 + 1]); } } void update(int i, T x){ int k = i + n; seg[k] = x; while(k >>= 1){ seg[k] = f(seg[k * 2], seg[k * 2 + 1]); } } T query(int l, int r){ l += n, r += n; T L = e, R = e; for(; l != r; l >>= 1, r >>= 1){ if(l % 2) L = f(L, seg[l++]); if(r % 2) R = f(seg[--r], R); } return f(L, R); } T operator[](const int i)const { return seg[i + n]; } template int right_bound_sub(int k, const C &check, T x){ while(k < n){ if(check(f(x, seg[k * 2]))){ k = k * 2; } else{ x = f(x, seg[k * 2]); k = k * 2 + 1; } } return k - n; } template int right_bound(int i, const C &check){ T x = e; for(int l = i + n, r = n * 2; l != r; l >>= 1, r >>= 1){ if(l % 2){ if(check(f(x, seg[l]))){ return right_bound_sub(l, check, x); } x = f(x, seg[l]); l++; } } return -1; } template int left_bound_sub(int k, const C &check, T x){ while(k < n){ if(check(f(seg[k * 2 + 1], x))){ k = k * 2 + 1; } else{ x = f(seg[k * 2 + 1], x); k = k * 2; } } return k - n; } template int left_bound(int i, const C &check){ T x = e; for(int l = n, r = i + n; l != r; l >>= 1, r >>= 1){ if(r % 2){ if(check(f(seg[--r], x))){ return left_bound_sub(r, check, x); } x = f(x, seg[r]); } } return -1; } }; vector v[200005]; int main() { int t; cin >> t; while(t--){ int n; cin >> n; int a[200005], b[200005]; P p[200005]; for(int i = 0; i < n; i++){ cin >> a[i]; a[i]--; v[a[i]].push_back(i); } for(int i = 0; i < n; i++){ cin >> b[i]; b[i]--; p[i] = P(b[i], i); } sort(p, p + n); SegmentTree seg(n, [](int a, int b){return max(a, b);}, 0); for(int i = 0; i < n; i++) seg.set(i, a[i]); seg.build(); bool f = true; for(int u = 0; u < n; u++){ f = false; int i = p[u].second; int j = lower_bound(v[b[i]].begin(), v[b[i]].end(), i) - v[b[i]].begin(); if(j < (int)v[b[i]].size()){ if(seg.query(i, v[b[i]][j] + 1) == b[i]) f = true; } if(j > 0){ if(seg.query(v[b[i]][j - 1], i + 1) == b[i]) f = true; } if(!f) break; } if(f) cout << "Yes" << endl; else cout << "No" << endl; for(int i = 0; i < n; i++) v[i].clear(); } }