#include #include #include #include #include #include #include #include #include #include #include #include #include #include #define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl; #define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; typedef long long ll; template vector> vec2d(int n, int m, T v){ return vector>(n, vector(m, v)); } template vector>> vec3d(int n, int m, int k, T v){ return vector>>(n, vector>(m, vector(k, v))); } template void print_vector(vector v, char delimiter=' '){ if(v.empty()) { cout << endl; return; } for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter; cout << v.back() << endl; } using T = int; using S = int; T INF = 1e9; T e(){ return -INF; } T op(T a, T b){ return max(a, b); } T id(){ return -1; } T mapping(S a, T b){ if(a == id()) return b; return a; } T composition(T a, T b){ if(a == id()) return b; return a; } using Seg = atcoder::lazy_segtree; void solve(){ int n; cin >> n; vector a(n), b(n); vector> a_idx(n), b_idx(n); for(int i = 0; i < n; i++) { cin >> a[i]; a[i]--; a_idx[a[i]].push_back(i); } for(int i = 0; i < n; i++) { cin >> b[i]; b[i]--; b_idx[b[i]].push_back(i); } Seg seg(n); for(int j = 0; j < n; j++) seg.apply(j, j+1, a[j]); for(int i = 0; i < n; i++){ for(int idx: a_idx[i]){ auto g = [&](T x){ return x <= i; }; int l = seg.min_left(idx+1, g); int r = seg.max_right(idx, g); seg.apply(l, r, i); } for(int idx: b_idx[i]){ if(seg.get(idx) != i){ cout << "No" << endl; return; } seg.set(idx, INF); } } cout << "Yes" << endl; } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; int t; cin >> t; while(t--) solve(); }