#line 1 "main.cpp" #include #include // #include "library/templates/template.cpp" using namespace atcoder; using namespace std; using ll = long long int; using ull = unsigned long long int; using ld = long double; using pii = pair; using pll = pair; const std::string YES = "Yes"; const std::string NO = "No"; using S = int; S op(S x, S y) { return max(x, y); } S e() { return 0; } bool solve(int N, vector &A, vector &B) { for (int i = 0; i < N; i++) { if (A[i] > B[i]) { return false; } } segtree seg(A), segB(B); int le = 0, ri = 0; while (ri < N) { while (ri + 1 < N && B[le] == B[ri + 1]) { ri++; } if (seg.prod(le, ri + 1) == B[le]) { // ok } else { // seg.prod(le, ri + 1) < B[le] int riok = ri + 1, ring = N; while (abs(ring - riok)) { int rimid = (riok + ring) / 2; if (seg.prod(le, rimid) < B[le]) { riok = rimid; } else { ring = rimid; } } bool isok = false; if (seg.prod(le, ring) == B[le]) { if (segB.prod(le, ring) == B[le]) { // ok isok = true; } } int leok = le, leng = 0; while (abs(ring - riok)) { int lemid = (leok + leng) / 2; if (seg.prod(leok, ri) < B[le]) { leok = lemid; } else { leng = lemid; } } if (seg.prod(leng, ri) == B[le]) { if (segB.prod(leng, ri) == B[le]) { // ok isok = true; } } if (!isok) { return false; } } le = ri + 1; ri = ri + 1; } return true; } int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); std::cout.tie(nullptr); int T; cin >> T; while (T--) { int N; cin >> N; vector A(N), B(N); for (int i = 0; i < N; i++) { cin >> A[i]; } for (int i = 0; i < N; i++) { cin >> B[i]; } cout << (solve(N, A, B) ? YES : NO) << endl; } return 0; }