#include #define FOR(i, n, m) for(long long i = (n); i < (long long)(m); i++) #define REP(i, n) FOR(i, 0, n) #define ALL(v) v.begin(), v.end() #define pb push_back using namespace std; using ll = long long; using ld = long double; using P = pair; constexpr ll inf = 1000000000; constexpr ll mod = 998244353; constexpr ld eps = 1e-6; template ostream &operator<<(ostream &os, pair p) { os << to_string(p.first) << " " << to_string(p.second); return os; } template ostream &operator<<(ostream &os, vector &v) { REP(i, v.size()) { if(i) os << " "; os << v[i]; } return os; } template struct segment_tree { private: int n; const function op; const T ie; vector seq; public: segment_tree(int _n, function op, const T ie) : op(op), ie(ie) { n = 1; while(n < _n) n *= 2; seq.resize(2 * n - 1); for(int i = 0; i < 2 * n - 1; i++) seq[i] = ie; } void update(int k, const T e) { k += n - 1; seq[k] = e; while(k > 0) { k = (k - 1) / 2; seq[k] = op(seq[k * 2 + 1], seq[k * 2 + 2]); } } T get(int k) { k += n - 1; return seq[k]; } T query(int a, int b, int k = 0, int l = 0, int r = -1) { if(r == -1) r = n; if(r <= a || b <= l) return ie; if(a <= l && r <= b) return seq[k]; T vl = query(a, b, k * 2 + 1, l, (l + r) / 2); T vr = query(a, b, k * 2 + 2, (l + r) / 2, r); return op(vl, vr); } }; // segment_tree rsq(n, [] (ll a, ll b) { return a + b; }, 0) // segment_tree rMq(n, [] (ll a, ll b) { return max(a, b); }, -1e18) // segment_tree rmq(n, [] (ll a, ll b) { return min(a, b); }, 1e18) int main() { cin.tie(0); ios::sync_with_stdio(false); int t; cin >> t; REP(testcase, t) { int n; cin >> n; vector a(n), b(n); REP(i, n) cin >> a[i]; REP(i, n) cin >> b[i]; vector ok(n, false); segment_tree rmq( n + 1, [](ll a, ll b) { return min(a, b); }, 1e18); REP(i, n) rmq.update(i, b[i]); vector last_i(n + 1, -1); REP(i, n) { last_i[a[i]] = i; if(last_i[b[i]] != -1 && rmq.query(last_i[b[i]], i + 1) >= b[i]) ok[i] = true; } REP(i, n + 1) last_i[i] = -1; for(int i = n - 1; i >= 0; i--) { last_i[a[i]] = i; if(last_i[b[i]] != -1 && rmq.query(i, last_i[b[i]] + 1) >= b[i]) ok[i] = true; } REP(i, n) if(a[i] > b[i]) ok[i] = false; if(count(ALL(ok), false) == 0) cout << "Yes" << "\n"; else cout << "No" << "\n"; } return 0; }