#include using namespace std; #define rep(i,n) for(int i=0;i inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; }return false; } template inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; }return false; } template class SparseTable { using T = typename Op::T; vector> dat; vector len; int n, log; public: SparseTable(const vector& a) : n(a.size()), log(log2(n)) { dat = vector>(log + 1, vector(n)); len.resize(n + 1); rep(i, n)dat[0][i] = a[i]; rep(j, log)rep(i, n - (1 << j)) { dat[j + 1][i] = Op::comp(dat[j][i], dat[j][i + (1 << j)]); } for (int i = 2; i <= n; ++i)len[i] = len[i >> 1] + 1; } T value(int l, int r) { int k = len[r - l]; return Op::comp(dat[k][l], dat[k][r - (1 << k)]); } }; template struct node { using T = Type; inline static T comp(T x, T y) { return max(x, y); } }; void solve() { int n; cin >> n; vector a(n), b(n); rep(i, n) { cin >> a[i]; --a[i]; } rep(i, n) { cin >> b[i]; --b[i]; } set sa, sb; rep(i, n)sa.insert(i); vector>> p(n); rep(i, n)p[a[i]].emplace_back(i, true); rep(i, n)p[b[i]].emplace_back(i, false); SparseTable> sp(a); for (auto& val : p) { for (auto [i, f] : val)if (f)sa.erase(i); for (auto [i, f] : val) { if (f)continue; int l = -1, r = n; for (auto it = sa.lower_bound(i);;) { if (it != sa.begin())chmax(l, *prev(it)); if (it != sa.end())chmin(r, *it); break; } for (auto it = sb.lower_bound(i);;) { if (it != sb.begin())chmax(l, *prev(it)); if (it != sb.end())chmin(r, *it); break; } ++l, --r; if (r < i || i < l || l > r || sp.value(l, r + 1) != b[i]) { cout << "No\n"; return; } } for (auto [i, f] : val)if (!f)sb.insert(i); } cout << "Yes\n"; } int main() { int t; cin >> t; while (t--)solve(); return 0; }