#include<bits/stdc++.h> usingnamespace std; constint LEN = 1e5 + 10;
voidf() { int a[LEN], b[LEN]; stack<int> st; int n; cin >> n; for (int i = 1; i <= n; ++i) cin >> a[i]; for (int i = 1; i <= n; ++i) cin >> b[i]; int i = 1, j = 1; while (i <= n || j <= n) { while (!st.empty() && b[j] == st.top()) { st.pop(); ++j; } if (i > n && !st.empty()) break; if (i <= n) st.emplace(a[i++]); } if (st.empty()) cout << "Yes" << endl; else cout << "No" << endl; }
intmain() { int q; cin >> q; while (q--) f(); return0; }