#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define FASTIO
// #define endl "\n"  // Since endl forces a buffer flush which lows down large I/O operations.
#define ff first
#define ss second
#define pb push_back
#define input(c, n) for (int i = 0; i < n; i++) cin >> c[i];
#define exit_message(s) return 0*printf(s)
#define show(c) for (auto i: c) cout << i << " "; cout << "\n";
#define display(c, n) for (int i = 0; i < n; i++) cout << c[i] << " "; cout << "\n";
#define forl(i, a, n) for (int i = a; i < n; i++)
#define dugbe(k) cout << "-\t> " << #k << " = " << k << "\n";

// What follows is a magical ordered_set data structure.
// Supports the following functions:
// find_by_order(int k) - returns k'th smallest element (0-indexed)
// order_of_key(int k) - returns number of elements strictly smaller than k.
using namespace __gnu_pbds;
#define ordered_set tree <int, null_type, less_equal <int>, rb_tree_tag, tree_order_statistics_node_update>

/* TIPS FOR DEBUGGING
 * Check if values are not overflowing (use long long where required)
 * Check if ranges are inclusive or not.
 * Check properly if greedy will work or not before using it.
 * Check EDGE CASES!! Seriously, even in 2B, saving 8 points by being
 * 2 minutes faster will bite you in the ass if you don't make sure
 * it works on edge cases.
 * Keep adding to this list.
*/

using namespace std;
typedef long long ll;
typedef pair<int, int> pr;
typedef pair<ll, ll> prll;
typedef vector<int> vi;
typedef vector<ll> vill;
typedef vector<pr> vpr;
ifstream in("input.txt");
const ll mod = 998244353;
const long double eps = 1e-7;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

long long true_rand(long long n)
{
	// Returns a random number between 0 and n - 1 inclusive using mt19937.
    uniform_int_distribution<long long> uid(0, n - 1);
    return uid(rng);
}

ll mod_pow(ll a, ll b)
{
	if (b == 0)
		return 1LL;

	ll res = mod_pow(a, b >> 1);
	res = (res * res) % mod;
	if (b & 1LL)
		res = (res * a) % mod;

	return res;
}
ll count_inv(ll l, ll r, ll * a)
{
	ll count=0;
	if(l==r)
		return 0;
	ll mid = (l+r)/2;
	count+= count_inv(l,mid,a)+count_inv(mid+1,r,a);
	vector <ll> b,c,d;
	for(ll i=l ; i<=mid ; i++)
		b.pb(a[i]);
	for(ll i=mid+1 ; i<=r ; i++)
		c.pb(a[i]);
	while(!(b.empty()&& c.empty()))
	{
		if(b.empty())
		{
			d.pb(c.back());
			c.pop_back();
		}
		else if(c.empty())
		{
			d.pb(b.back());
			b.pop_back();
		}
		else
		{
			if(b.back()>c.back())
			{
				d.pb(b.back());
				b.pop_back();
				count+=c.size();
			}
			else
			{
				d.pb(c.back());
				c.pop_back();
				//count+=b.size();

			}
		}
	}
	reverse(d.begin(),d.end());
	for(ll i=l ; i<=r ; i++)
	{
		a[i]=d[i-l];
	}
	return count;

}

const int N = 2e5 + 5;

int32_t main()
{
	#ifdef FASTIO
		ios_base::sync_with_stdio(false);
		cin.tie(NULL);
	#endif
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);

	// TRY BINARY SEARCH. Always at least once.

	int t;
	cin >> t;
	while (t--)
	{
		int n;
		cin >> n;
		int a[n + 5] = {}, b[n + 5] = {};
		vi pos[n + 5] = {};
		int gt[n + 5] = {};
		forl(i, 0, n)
		{
			cin >> a[i];
			pos[a[i]].pb(i);
		}
		ordered_set st2;
		for (int i = n - 1; i >= 0; --i)
		{
			gt[i] = st2.order_of_key(a[i]);
			gt[i] = (int)st2.size() - gt[i];
			st2.insert(a[i]);
		}

		forl(i, 0, n)
		{
			cin >> b[i];
		}
		ordered_set st;
		int fail = 0;
		for (int i = n - 1; i >= 0; --i)
		{
			int x = b[i];
			int len = (int)pos[x].size();
			// Only swapping plix.
			if (len <= 0)
			{
				fail = 1;
				break;
			}

			int idx = pos[x][len - 1];

			int lesser = st.order_of_key(x);
			int greater = (int)st.size() - lesser;
			if (gt[idx] > greater)
			{
				fail = 1;
				// dugbe(i);
				break;
			}

			pos[x].pop_back();
			st.insert(b[i]);
		}
		if(count_inv(0,n-1,a)<count_inv(0,n-1,b))
			fail=1;
		if (fail)
			cout << "NO\n";
		else
			cout << "YES\n";
	}

	return 0;
}


    #include <bits/stdc++.h>
    using namespace std;

    #define int long long
    #define pb push_back
    #define S second
    #define F first
    #define f(i,n) for(int i=0;i<n;i++)
    #define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
    #define vi vector<int>
    #define pii pair<int,int>

    void solve()
    {
    int n;
    cin >> n;

    int a[n],b[n],c[n],d[n];

    f(i,n) cin >> a[i];
    f(i,n) cin >> b[i];

    f(i,n) c[i] = a[i],d[i] = b[i];

    sort(c,c+n);
    sort(d,d+n);

    f(i,n) if(c[i] != d[i])
    {
     cout << "NO\n"; return ;
    }

    multiset<int> s;

    int r = 0;

    f(i,n)
    {

     while(*s.begin() != b[i] && r < n) s.insert(a[r++]);

     if(*s.begin() != b[i])
     {
      cout <<"NO\n"; return;
     }

     s.erase(s.begin());

    }

     cout << "YES\n";

    }

    signed main()
    {
        fast;
        int t= 1;
        cin >> t;
        while(t--)
        solve();
    }


        #include <bits/stdc++.h>
        using namespace std;

        #define int long long
        #define pb push_back
        #define S second
        #define F first
        #define f(i,n) for(int i=0;i<n;i++)
        #define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
        #define vi vector<int>
        #define pii pair<int,int>

        void solve()
        {
        int n;
        cin >> n;

        int a[n],b[n],c[n],d[n];

        f(i,n) cin >> a[i];
        f(i,n) cin >> b[i];

        f(i,n) c[i] = a[i],d[i] = b[i];

        sort(c,c+n);
        sort(d,d+n);

        f(i,n) if(c[i] != d[i])
        {
         cout << "NO\n"; return ;
        }

        f(i,n)
        {
         if(a[i] == b[i]) continue;

         for(int j=i+1;j<n;j++)
         {
          if(a[j] == b[i])
          {
           for(int k=j;k>i;k--) if(a[k] < a[k-1]) swap(a[k],a[k-1]);
           break;
          }
         }

          if(a[i]!=b[i])
          {
              cout << "NO\n";
              return;
          }
        }

         cout << "YES\n";

        }

        signed main()
        {
            fast;
            int t= 1;
            cin >> t;
            while(t--)
            solve();
        }


#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<int>
#define pii pair<int,int>

const int N = 3e5 + 10;
int n;

const int init = 999999999999;

vector < int >st (2 * N, init);

int fun (int a, int b)
{
  return min (a, b);
}

void build ()
{
  for (int i = n - 1; i > 0; i--)
    st[i] = fun (st[i << 1], st[i << 1 | 1]);
}

void update (int id, int val)
{
  for (st[id += n] = val; id > 1; id >>= 1)
    st[id >> 1] = fun (st[id], st[id ^ 1]);
}

int query (int l, int r)
{
  int res = init;

  r++;

  for (l += n, r += n; l < r; l >>= 1, r >>= 1)
    {
      if (l & 1)
	res = fun (res, st[l++]);
      if (r & 1)
	res = fun (res, st[--r]);
    }

  return res;
}

void solve ()
{
  cin >> n;

  map < int, queue < int >>mp;

  int a[n], b[n], c[n], d[n];

  f (i, n) cin >> a[i];
  f (i, n) cin >> b[i];

  f (i, n) mp[a[i]].push (i);

  f (i, n) st[i + n] = a[i];

  build ();

  f (i, n) c[i] = a[i], d[i] = b[i];

  sort (c, c + n);
  sort (d, d + n);

  f (i, n) if (c[i] != d[i])
    {
      cout << "NO\n";
      return;
    }

  f (i, n)
  {
    int l = 0, r = mp[b[i]].front ();

    mp[b[i]].pop ();

    if (query (l, r) != b[i])
      {
	cout << "NO\n";
	return;
      }

    update (r, init);

  }

  cout << "YES\n";
}

signed main ()
{
  fast;
  int t = 1;
  cin >> t;
  while (t--)
    solve ();
}


        #include <bits/stdc++.h>
        using namespace std;

        #define int long long
        #define pb push_back
        #define S second
        #define F first
        #define f(i,n) for(int i=0;i<n;i++)
        #define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
        #define vi vector<int>
        #define pii pair<int,int>

        void solve()
        {
        int n,flag=1,flag1=1;
        cin >> n;

        int a[n],b[n],c[n],d[n];

        f(i,n) cin >> a[i];
        f(i,n) cin >> b[i];

        f(i,n) c[i] = a[i],d[i] = b[i];

        sort(c,c+n);
        sort(d,d+n);

        f(i,n) if(c[i] != d[i])
        {
         cout << "NO\n"; return ;
        }

        f(i,n)
        {
         if(a[i] == b[i]) continue;

         for(int j=i+1;j<n;j++)
         {
          if(a[j] == b[i])
          {
           for(int k=j;k>i;k--) swap(a[k],a[k-1]);
           break;
          }
          else if(j==n-1 || a[j] < b[i])
          {
              cout << "NO\n";
              return;
          }
         }

        }

         cout << "YES\n";

        }

        signed main()
        {
            fast;
            int t= 1;
            cin >> t;
            while(t--)
            solve();
        }


#include <bits/stdc++.h>
using namespace std;

#define int long long
#define pb push_back
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<int>
#define pii pair<int,int>

const int N = 3e5 + 10;
int n;

const int init = 999999999999;

vector < int >st (2 * N, init);

int fun (int a, int b)
{
  return min (a, b);
}

void build ()
{
  for (int i = n - 1; i > 0; i--)
    st[i] = fun (st[i << 1], st[i << 1 | 1]);
}

void update (int id, int val)
{
  for (st[id += n] = val; id > 1; id >>= 1)
    st[id >> 1] = fun (st[id], st[id ^ 1]);
}

int query (int l, int r)
{
  int res = init;

  r++;

  for (l += n, r += n; l < r; l >>= 1, r >>= 1)
    {
      if (l & 1)
	res = fun (res, st[l++]);
      if (r & 1)
	res = fun (res, st[--r]);
    }

  return res;
}

void solve ()
{
  cin >> n;

  map < int, queue < int >>mp;

  int a[n], b[n], c[n], d[n];

  f (i, n) cin >> a[i];
  f (i, n) cin >> b[i];

  f (i, n) mp[a[i]].push (i);

  f (i, n) st[i + n] = a[i];

  build ();

  f (i, n) c[i] = a[i], d[i] = b[i];

  sort (c, c + n);
  sort (d, d + n);

  f (i, n) if (c[i] != d[i])
    {
      cout << "NO\n";
      return;
    }

  f (i, n)
  {
    int l = 0, r = mp[b[i]].front ();

    mp[b[i]].pop ();

    if (query (l, r) != b[i])
      {
	cout << "NO\n";
	return;
      }

    update (r, init);

  }

  cout << "YES\n";
}

signed main ()
{
  fast;
  int t = 1;
  cin >> t;
  while (t--)
    solve ();
}


        #include <bits/stdc++.h>
        using namespace std;

        #define int long long
        #define pb push_back
        #define S second
        #define F first
        #define f(i,n) for(int i=0;i<n;i++)
        #define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
        #define vi vector<int>
        #define pii pair<int,int>

        const int N =2e5+10;
int n;

const int init = 999999999999;

vector<int> st(2*N,init);

int fun(int a,int b)
{
 return min(a,b);
}

void build()
{
 for(int i=n-1;i>0;i--) st[i] =fun( st[i<<1],st[i<<1|1] );
}

void update(int id,int val)
{
  for(st[id+=n]=val;id>1;id>>=1)
      st[id>>1] =fun( st[id],st[id^1] );
}

int query(int l,int r)
{
    int res = init;

    r++;

    for(l+=n,r+=n;l<r;l>>=1,r>>=1)
    {
     if(l&1) res=fun(res,st[l++]);
     if(r&1) res=fun(res,st[--r]);
    }

    return res;
}

        void solve()
        {
        cin >> n;

        map<int,queue<int> > mp;

        int a[n],b[n],c[n],d[n];

        f(i,n) cin >> a[i];
        f(i,n) cin >> b[i];

        f(i,n) mp[a[i]].push(i);

        f(i,n) st[i+n] = a[i];

        build();

        f(i,n) c[i] = a[i],d[i] = b[i];

        sort(c,c+n);
        sort(d,d+n);

        f(i,n)
           if(c[i] != d[i])
        {
         cout << "NO\n"; return ;
        }

        f(i,n)
        {
         int l = 0,r = mp[b[i]].front();

         mp[b[i]].pop();

         if(query(l,r) != b[i] )
         {
           cout << "NO\n"; return;
         }

         update(r,init);

         }

         cout << "YES\n";

        }

        signed main()
        {
            fast;
            int t= 1;
            cin >> t;
            while(t--)
            solve();
        }


#include <bits/stdc++.h>
using namespace std;

#define int long long
#define pb push_back
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<int>
#define pii pair<int,int>

void solve()
{
int n;
cin >> n;

int a[n],b[n],c[n],d[n];

f(i,n) cin >> a[i];
f(i,n) cin >> b[i];

f(i,n) c[i] = a[i],d[i] = b[i];

sort(c,c+n);
sort(d,d+n);

f(i,n) if(c[i] != d[i])
{
 cout << "NO\n"; return ;
}

multiset<int> s;

int r = 0;

f(i,n)
{

 while(*s.begin() != b[i] && r < n) s.insert(a[r++]);

 if(*s.begin() < b[i])
 {
  cout <<"NO\n"; return;
 }

 s.erase(s.begin());

}

 cout << "YES\n";

}

signed main()
{
    fast;
    int t= 1;
    cin >> t;
    while(t--)
    solve();
}


        #include <bits/stdc++.h>
        using namespace std;

        #define int long long
        #define pb push_back
        #define S second
        #define F first
        #define f(i,n) for(int i=0;i<n;i++)
        #define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
        #define vi vector<int>
        #define pii pair<int,int>

        void solve()
        {
        int n,flag=1,flag1=1;
        cin >> n;

        int a[n],b[n],c[n],d[n];

        f(i,n) cin >> a[i];
        f(i,n) cin >> b[i];

        f(i,n) c[i] = a[i],d[i] = b[i];

        sort(c,c+n);
        sort(d,d+n);

        f(i,n) if(c[i] != d[i])
        {
         cout << "NO\n"; return ;
        }

        multiset<int> s;
        multiset<int,greater<int> > ss;

        int r = 0;

        f(i,n)
        {

         while(*s.begin() != b[i] && r < n) s.insert(a[r++]);

            if(*s.begin() != b[i]){  flag = 0; break; }

         s.erase(s.begin());
        }

         r = n-1;

        for(int i=n-1;i>=0;i--)
        {
            while(*ss.begin() != b[i] && r > 0) ss.insert(a[r--]);

            if(*ss.begin()!=b[i]) { flag1 = 0; break; }

            ss.erase(ss.begin());
        }

        if(flag || flag1)
         cout << "YES\n";
        else cout << "NO\n";

        }

        signed main()
        {
            fast;
            int t= 1;
            cin >> t;
            while(t--)
            solve();
        }


#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<int>
#define pii pair<int,int>

const int N = 3e5 + 10;
int n;

const int init = 9999999;

vector < int >st (2 * N, init);

int fun (int a, int b)
{
  return min (a, b);
}

void build ()
{
  for (int i = n - 1; i > 0; i--)
    st[i] = fun (st[i << 1], st[i << 1 | 1]);
}

void update (int id, int val)
{
  for (st[id += n] = val; id > 1; id >>= 1)
    st[id >> 1] = fun (st[id], st[id ^ 1]);
}

int query (int l, int r)
{
  int res = init;

  r++;

  for (l += n, r += n; l < r; l >>= 1, r >>= 1)
    {
      if (l & 1)
	res = fun (res, st[l++]);
      if (r & 1)
	res = fun (res, st[--r]);
    }

  return res;
}

void solve ()
{
  cin >> n;

  map < int, queue < int >>mp;

  int a[n], b[n], c[n], d[n];

  f (i, n) cin >> a[i];
  f (i, n) cin >> b[i];

  f (i, n) mp[a[i]].push (i);

  f (i, n) st[i + n] = a[i];

  build ();

  f (i, n) c[i] = a[i], d[i] = b[i];

  sort (c, c + n);
  sort (d, d + n);

  f (i, n) if (c[i] != d[i])
    {
      cout << "NO\n";
      return;
    }

  f (i, n)
  {
    int l = 0, r = mp[b[i]].front ();

    mp[b[i]].pop ();

    if (query (l, r) != b[i])
      {
	cout << "NO\n";
	return;
      }

    update (r, init);

  }

  cout << "YES\n";
}

signed main ()
{
  fast;
  int t = 1;
  cin >> t;
  while (t--)
    solve ();
}


 By nishantshah123, contest: Educational Codeforces Round 67 (Rated for Div. 2), problem: (D) Subarray Sorting, Hacked, #

    #include <bits/stdc++.h>
    using namespace std;

    #define int long long
    #define pb push_back
    #define S second
    #define F first
    #define f(i,n) for(int i=0;i<n;i++)
    #define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
    #define vi vector<int>
    #define pii pair<int,int>

    void solve()
    {
    int n;
    cin >> n;

    int a[n],b[n],c[n],d[n];

    f(i,n) cin >> a[i];
    f(i,n) cin >> b[i];

    f(i,n) c[i] = a[i],d[i] = b[i];

    sort(c,c+n);
    sort(d,d+n);

    f(i,n) if(c[i] != d[i])
    {
     cout << "NO\n"; return ;
    }

    multiset<int> s;

    int r = 0;

    f(i,n)
    {

     while(*s.begin() != b[i] && r < n) s.insert(a[r++]);

     if(*s.begin() != b[i])
     {
      cout <<"NO\n"; return;
     }

     s.erase(s.begin());

    }

     cout << "YES\n";

    }

    signed main()
    {
        fast;
        int t= 1;
        cin >> t;
        while(t--)
        solve();
    }


#include <bits/stdc++.h>
using namespace std;

#define int long long
#define pb push_back
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<int>
#define pii pair<int,int>

void solve()
{
int n;
cin >> n;

int a[n],b[n],c[n],d[n];

f(i,n) cin >> a[i];
f(i,n) cin >> b[i];

f(i,n) c[i] = a[i],d[i] = b[i];

sort(c,c+n);
sort(d,d+n);

f(i,n) if(c[i] != d[i])
{
 cout << "NO\n"; return ;
}

map<int,deque<int> > mp;

f(i,n) mp[a[i]].pb(i);

f(i,n)
{

 if(mp[b[i]].empty() || a[i] < b[i])
 {
  cout <<"NO\n"; return;
 }

 int x = mp[b[i]].front();

 mp[b[i]].pop_front();

 if(x > i)
 sort(a+i,a+x+1);

}

 cout << "YES\n";

}

signed main()
{
    fast;
    int t= 1;
    cin >> t;
    while(t--)
    solve();
}


        #include <bits/stdc++.h>
        using namespace std;

        #define int long long
        #define pb push_back
        #define S second
        #define F first
        #define f(i,n) for(int i=0;i<n;i++)
        #define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
        #define vi vector<int>
        #define pii pair<int,int>

        void solve()
        {
        int n;
        cin >> n;

        int a[n],b[n],c[n],d[n];

        f(i,n) cin >> a[i];
        f(i,n) cin >> b[i];

        f(i,n) c[i] = a[i],d[i] = b[i];

        sort(c,c+n);
        sort(d,d+n);

        f(i,n) if(c[i] != d[i])
        {
         cout << "NO\n"; return ;
        }

        f(i,n)
        {
         if(a[i] == b[i]) continue;

         for(int j=i+1;j<n;j++)
         {
          if(a[j] == b[i])
          {
           for(int k=j;k>i;k--) swap(a[k],a[k-1]);
           break;
          }
         }

          if(a[i]!=b[i])
          {
              cout << "NO\n";
              return;
          }
        }

         cout << "YES\n";

        }

        signed main()
        {
            fast;
            int t= 1;
            cin >> t;
            while(t--)
            solve();
        }


        #include <bits/stdc++.h>
        using namespace std;

        #define int long long
        #define pb push_back
        #define S second
        #define F first
        #define f(i,n) for(int i=0;i<n;i++)
        #define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
        #define vi vector<int>
        #define pii pair<int,int>

        void solve()
        {
        int n,flag=1,flag1=1;
        cin >> n;

        int a[n],b[n],c[n],d[n];

        f(i,n) cin >> a[i];
        f(i,n) cin >> b[i];

        f(i,n) c[i] = a[i],d[i] = b[i];

        sort(c,c+n);
        sort(d,d+n);

        f(i,n) if(c[i] != d[i])
        {
         cout << "NO\n"; return ;
        }

        multiset<int> s;
        multiset<int,greater<int> > ss;

        int r = 0;

        f(i,n)
        {

         while(*s.begin() != b[i] && r < n) s.insert(a[r++]);

            if(*s.begin() != b[i]){  flag = 0; break; }

         s.erase(s.begin());
        }

         r = n-1;

        for(int i=n-1;i>=0;i--)
        {

            while(*ss.begin() != b[i] && r >= 0) ss.insert(a[r--]);

            if(*ss.begin()!=b[i]) { flag1 = 0; break; }

            ss.erase(ss.begin());
        }

        if(flag || flag1)
         cout << "YES\n";
        else cout << "NO\n";

        }

        signed main()
        {
            fast;
            int t= 1;
            cin >> t;
            while(t--)
            solve();
        }


#include <bits/stdc++.h>
using namespace std;

#define int long long
#define pb push_back
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<int>
#define pii pair<int,int>

void solve()
{
int n;
cin >> n;

int a[n],b[n];

f(i,n) cin >> a[i];
f(i,n) cin >> b[i];

map<int,deque<int> > mp;

f(i,n) mp[a[i]].pb(i);

f(i,n)
{

 if(mp[b[i]].empty() || a[i] < b[i])
 {
  cout <<"NO\n"; return;
 }

 int x = mp[b[i]].front();

 mp[b[i]].pop_front();

 if(x > i)
 sort(a+i,a+x+1);

}

 cout << "YES\n";

}

signed main()
{
    fast;
    int t= 1;
    cin >> t;
    while(t--)
    solve();
}


#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define MOD 1000000007
#define EPS 1e-10
#define INF 1000000002

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii, int> piii;
const int N = 200002;

int main() {
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
    int t;
    scanf("%d",&t);
    while(t--) {
        int n;
        scanf("%d",&n);
        vector <int> a(n), b(n);
        for(int i =0;i<n;i++)
            scanf("%d",&a[i]);
        for(int i =0;i<n;i++)
            scanf("%d",&b[i]);
        vector<int> sorted_a = a, sorted_b = b;
        sort(sorted_a.begin(), sorted_a.end());
        sort(sorted_b.begin(), sorted_b.end());
        if(sorted_a != sorted_b) {
            printf("NO\n");
            continue;
        }
        bool failed = false;
        multiset<int> ms;
        int nxt =0 ;
        for(int i =0;i<n;i++) {
            int curr = b[i];
            while(ms.find(curr) == ms.end())
                ms.insert(a[nxt++]);
            if(*ms.begin() == curr)
                ms.erase(ms.begin());
            else {
                failed = true;
                break;
            }
        }
        if(!failed)
            printf("YES\n");
        else
            printf("NO\n");
    }
    return 0;
}


#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define MOD 1000000007
#define EPS 1e-10
#define INF 1000000002

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii, int> piii;
const int N = 200002;

int main() {
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
    int t;
    scanf("%d",&t);
    while(t--) {
        int n;
        scanf("%d",&n);
        vector <int> a(n), b(n);
        for(int i =0;i<n;i++)
            scanf("%d",&a[i]);
        for(int i =0;i<n;i++)
            scanf("%d",&b[i]);
        vector<int> sorted_a = a, sorted_b = b;
        sort(sorted_a.begin(), sorted_a.end());
        sort(sorted_b.begin(), sorted_b.end());
        if(sorted_a != sorted_b) {
            printf("NO\n");
            continue;
        }
        bool failed = false;
        multiset<int> ms, ms2;
        int nxt =0 ;
        for(int i =0;i<n;i++) {
            int curr = b[i];
            if(ms.empty())
                ms = ms2, ms2.clear();
            while(ms.find(curr) == ms.end()) {
                if(a[nxt] <= curr)
                    ms.insert(a[nxt++]);
                else
                    ms2.insert(a[nxt++]);
            }
            if(ms.empty())
                ms = ms2, ms2.clear();
            if(*ms.begin() == curr)
                ms.erase(ms.begin());
            else {
                failed = true;
                break;
            }
        }
        if(!failed)
            printf("YES\n");
        else
            printf("NO\n");
    }
    return 0;
}


#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define MOD 1000000007
#define EPS 1e-10
#define INF 1000000002

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii, int> piii;
const int N = 200002;

int main() {
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
    int t;
    scanf("%d",&t);
    while(t--) {
        int n;
        scanf("%d",&n);
        vector <int> a(n), b(n);
        for(int i =0;i<n;i++)
            scanf("%d",&a[i]);
        for(int i =0;i<n;i++)
            scanf("%d",&b[i]);
        vector<int> sorted_a = a, sorted_b = b;
        sort(sorted_a.begin(), sorted_a.end());
        sort(sorted_b.begin(), sorted_b.end());
        if(sorted_a != sorted_b) {
            printf("NO\n");
            continue;
        }
        bool failed = false;
        multiset<int> ms;
        int nxt =0 ;
        for(int i =0;i<n;i++) {
            int curr = b[i];
            while(ms.find(curr) == ms.end())
                ms.insert(a[nxt++]);
            if(*ms.begin() == curr)
                ms.erase(ms.begin());
            else {
                failed = true;
            }
        }
        if(!failed)
            printf("YES\n");
        else
            printf("NO\n");
    }
    return 0;
}


#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define MOD 1000000007
#define EPS 1e-10
#define INF 1000000002

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii, int> piii;
const int N = 200002;

int main() {
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
    int t;
    scanf("%d",&t);
    while(t--) {
        int n;
        scanf("%d",&n);
        vector <int> a(n), b(n);
        for(int i =0;i<n;i++)
            scanf("%d",&a[i]);
        for(int i =0;i<n;i++)
            scanf("%d",&b[i]);
        vector<int> sorted_a = a, sorted_b = b;
        sort(sorted_a.begin(), sorted_a.end());
        sort(sorted_b.begin(), sorted_b.end());
        if(sorted_a != sorted_b) {
            printf("NO\n");
            continue;
        }
        bool failed = false;
        multiset<int> ms, ms2;
        int nxt =0 ;
        for(int i =0;i<n;i++) {
            int curr = b[i];
            if(ms.empty())
                ms = ms2;
            while(ms.find(curr) == ms.end()) {
                if(a[nxt] <= curr)
                    ms.insert(a[nxt++]);
                else
                    ms2.insert(a[nxt++]);
            }
            if(ms.empty())
                ms = ms2;
            if(*ms.begin() == curr)
                ms.erase(ms.begin());
            else {
                failed = true;
                break;
            }
        }
        if(!failed)
            printf("YES\n");
        else
            printf("NO\n");
    }
    return 0;
}


#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define MOD 1000000007
#define EPS 1e-10
#define INF 1000000002

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii, int> piii;
const int N = 300003;
int arr[N];

class SegmentTree {
    int tree[4*N] = {};
public:
    int build(int pos, int l, int r) {
        if(l == r)
            return tree[pos] = arr[l];
        int mid = (l+r)>>1;
        return tree[pos] = min(build(pos<<1, l, mid), build(pos<<1|1, mid+1, r));
    }

    int update(int pos, int l, int r, int x, int val) {
        if(l > x || r < x)
            return tree[pos];
        if(l == r)
            return tree[pos] = val;
        int mid = (l+r)>>1;
        return tree[pos] = min(update(pos<<1, l, mid, x, val), update(pos<<1|1, mid+1, r, x, val));
    }

    int get(int pos, int l, int r, int qLow, int qHigh) {
        if(l > qHigh || r < qLow)
            return INF;
        if(l >= qLow && r <= qHigh)
            return tree[pos];
        int mid = (l+r)>>1;
        return min(get(pos<<1, l, mid, qLow, qHigh), get(pos<<1|1, mid+1, r, qLow, qHigh));
    }

};

int main() {
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
    int t;
    scanf("%d",&t);
    while(t--) {
        int n;
        scanf("%d",&n);
        vector <int> b(n);
        for(int i =0;i<n;i++)
            scanf("%d",&arr[i]);
        for(int i =0;i<n;i++)
            scanf("%d",&b[i]);
        int nxt =0 ;
        SegmentTree* segmentTree = new SegmentTree();
        segmentTree->build(1, 0, n-1);
        bool failed = false;
        for(int i =0;i<n && !failed;i++) {
            int curr = b[i];
            int l = 0, r = n-1, ans = -1;
            while(l <= r) {
                int mid = (l+r)>>1;
                int best = segmentTree->get(1, 0, n-1, 0, mid);
                if(best < curr) {
                    r = mid-1;
                } else if(best == curr) {
                    ans = mid, r = mid-1;
                } else {
                    l = mid+1;
                }
            }
            if(ans == -1)
                failed = true;
            else
                segmentTree->update(1, 0, n-1, ans, 1e9);
        }
        if(failed)
            printf("NO\n");
        else
            printf("YES\n");
        delete segmentTree
    }
    return 0;
}


#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define MOD 1000000007
#define EPS 1e-10
#define INF 1000000002

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii, int> piii;
const int N = 300003;
int arr[N];

class SegmentTree {
    vector<int> tree;
public:
    SegmentTree(int n) {
        tree.resize(4*n);
    }
    ~SegmentTree() {
        tree.clear();
    }
    int build(int pos, int l, int r) {
        if(l == r)
            return tree[pos] = arr[l];
        int mid = (l+r)>>1;
        return tree[pos] = min(build(pos<<1, l, mid), build(pos<<1|1, mid+1, r));
    }

    int update(int pos, int l, int r, int x, int val) {
        if(l > x || r < x)
            return tree[pos];
        if(l == r)
            return tree[pos] = val;
        int mid = (l+r)>>1;
        return tree[pos] = min(update(pos<<1, l, mid, x, val), update(pos<<1|1, mid+1, r, x, val));
    }

    int get(int pos, int l, int r, int qLow, int qHigh) {
        if(l > qHigh || r < qLow)
            return INF;
        if(l >= qLow && r <= qHigh)
            return tree[pos];
        int mid = (l+r)>>1;
        return min(get(pos<<1, l, mid, qLow, qHigh), get(pos<<1|1, mid+1, r, qLow, qHigh));
    }

};

int main() {
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
    int t;
    scanf("%d",&t);
    while(t--) {
        int n;
        scanf("%d",&n);
        vector <int> b(n);
        for(int i =0;i<n;i++)
            scanf("%d",&arr[i]);
        for(int i =0;i<n;i++)
            scanf("%d",&b[i]);
        int nxt =0 ;
        SegmentTree* segmentTree = new SegmentTree(n);
        segmentTree->build(1, 0, n-1);
        bool failed = false;
        for(int i =0;i<n && !failed;i++) {
            int curr = b[i];
            int l = 0, r = n-1, ans = -1;
            while(l <= r) {
                int mid = (l+r)>>1;
                int best = segmentTree->get(1, 0, n-1, 0, mid);
                if(best < curr) {
                    r = mid-1;
                } else if(best == curr) {
                    ans = mid, r = mid-1;
                } else {
                    l = mid+1;
                }
            }
            if(ans == -1)
                failed = true;
            else
                segmentTree->update(1, 0, n-1, ans, 1e9);
        }
        if(failed)
            printf("NO\n");
        else
            printf("YES\n");
        delete segmentTree;
    }
    return 0;
}


#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define MOD 1000000007
#define EPS 1e-10
#define INF 1000000002

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii, int> piii;
const int N = 300003;
int arr[N];

class SegmentTree {
    int tree[4*N] = {};
public:
    int build(int pos, int l, int r) {
        if(l == r)
            return tree[pos] = arr[l];
        int mid = (l+r)>>1;
        return tree[pos] = min(build(pos<<1, l, mid), build(pos<<1|1, mid+1, r));
    }

    int update(int pos, int l, int r, int x, int val) {
        if(l > x || r < x)
            return tree[pos];
        if(l == r)
            return tree[pos] = val;
        int mid = (l+r)>>1;
        return tree[pos] = min(update(pos<<1, l, mid, x, val), update(pos<<1|1, mid+1, r, x, val));
    }

    int get(int pos, int l, int r, int qLow, int qHigh) {
        if(l > qHigh || r < qLow)
            return INF;
        if(l >= qLow && r <= qHigh)
            return tree[pos];
        int mid = (l+r)>>1;
        return min(get(pos<<1, l, mid, qLow, qHigh), get(pos<<1|1, mid+1, r, qLow, qHigh));
    }

};

int main() {
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
    int t;
    scanf("%d",&t);
    while(t--) {
        int n;
        scanf("%d",&n);
        vector <int> b(n);
        for(int i =0;i<n;i++)
            scanf("%d",&arr[i]);
        for(int i =0;i<n;i++)
            scanf("%d",&b[i]);
        int nxt =0 ;
        SegmentTree* segmentTree = new SegmentTree();
        segmentTree->build(1, 0, n-1);
        bool failed = false;
        for(int i =0;i<n && !failed;i++) {
            int curr = b[i];
            int l = 0, r = n-1, ans = -1;
            while(l <= r) {
                int mid = (l+r)>>1;
                int best = segmentTree->get(1, 0, n-1, 0, mid);
                if(best < curr) {
                    r = mid-1;
                } else if(best == curr) {
                    ans = mid, r = mid-1;
                } else {
                    l = mid+1;
                }
            }
            if(ans == -1)
                failed = true;
            else
                segmentTree->update(1, 0, n-1, ans, 1e9);
        }
        if(failed)
            printf("NO\n");
        else
            printf("YES\n");
        delete segmentTree;
    }
    return 0;
}


#include <cstdio>
#include <memory.h>
#include <cstring>
#include <vector>
#include <deque>
#include <cstdlib>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cassert>
#include <functional>
#include <iostream>
#include <set>
#include <list>
#include <map>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
using namespace std;

typedef long long ll;
typedef unsigned long long llu;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<string, int> psi;
typedef pair<char, int> pci;
typedef pair<int, char> pic;
const ll MOD = (ll)1e9 + 7;
const long double PI = 3.141592653589793238462643383279502884197;

priority_queue<int, vector<int>, greater<int> > pq;
vector<int> v;

pii a[300000];
pii b[300000];

multiset<int> aa, bb;
int tree[1048576];
int val[300000];
int szz;

int find(int i, int l, int r, int le, int ri) {
	if (le > r || ri < l) return 0;
	if (le >= l && ri <= r) return tree[i];
	return find(i * 2, l, r, le, (le + ri) / 2) + find(i * 2 + 1, l, r, (le + ri) / 2 + 1, ri);
}

void update(int i, int val) {
	i += szz;
	tree[i] += val;
	i /= 2;

	while (i) {
		tree[i] = tree[i * 2] + tree[i * 2 + 1];
		i /= 2;
	}
}

int main() {
	int q;
	scanf("%d", &q);

	while (q--) {
		aa.clear();
		bb.clear();

		int n;
		scanf("%d", &n);
		szz = 1;
		while (szz < n) szz *= 2;
		memset(tree, 0, sizeof(int) * szz * 2);

		for (int i = 0; i < n; i++) {
			scanf("%d", &a[i].first);
			aa.insert(a[i].first);

			a[i].second = i;
		}

		for (int i = 0; i < n; i++) {
			scanf("%d", &b[i].first);
			bb.insert(b[i].first);

			b[i].second = i;
		}

		if (aa != bb) {
			printf("NO\n");
			continue;
		}

		sort(a, a + n, greater<pii>());
		sort(b, b + n, greater<pii>());

		for (int i = 0; i < n; i++) {
			update(a[i].second, 1);
			val[i] = find(1, 0, a[i].second, 0, szz - 1); // val[i]에다가 해줌.
		}
		// 자신보다 앞에 있는 나보다 큰 애의 개수...
		//

		int flag = 0;
		memset(tree, 0, sizeof(int) * szz * 2);
		for (int i = 0; i < n; i++) {
			update(b[i].second, 1);
			int tt = find(1, 0, b[i].second, 0, szz - 1);

			if (val[i] < tt) {
				printf("NO\n");
				flag = 1;
				break;
			}
		}

		if (!flag) printf("YES\n");
		// 이제 이걸 b에 대해서도 똑같이 해주는데..
		//
	}
}


#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <climits>
#include <unordered_set>
#include <unordered_map>
#include <cassert>
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define pdi pair<double,int>
#define mod 1000000007
#define mod1 1000000009
#define mod2 1000000021
#define INF 100000000001
#define MAX 1000000000
#define M 1001
long double PI = 3.141592653589793238462643383279502884197;
using namespace std;

/* 🐣🐥 */
int num[300001], tree[1048576];
pii arr[300001];
priority_queue<pii> pq;
void init(int idx, int s, int e) {
	tree[idx] = MAX;
	if (s == e) return;
	init(idx * 2, s, (s + e) / 2);
	init(idx * 2 + 1, (s + e) / 2 + 1, e);
}
void update(int idx, int s, int e, int k, int val) {
	if (k > e || k < s) return;
	tree[idx] = val;
	if (s == e) return;
	update(idx * 2, s, (s + e) / 2, k, val);
	update(idx * 2 + 1, (s + e) / 2 + 1, e,  k, val);
	tree[idx] = min(tree[idx * 2], tree[idx * 2 + 1]);
}
int mx(int idx, int s, int e, int l, int r) {
	if (s > r || e < l) return MAX;
	if (l <= s && e <= r) return tree[idx];
	return min(mx(idx * 2, s, (s + e) / 2, l, r),
		mx(idx * 2 + 1, (s + e) / 2 + 1, e, l, r));
}
int main() {
	int t, n, a;
	scanf("%d", &t);
	while (t--) {
		bool suc = true;
		scanf("%d", &n);
		fill(num, num + n, 0);
		while (!pq.empty()) pq.pop();
		for (int i = 0; i < n; i++) {
			scanf("%d", &arr[i].first);
			num[arr[i].first]++;
			arr[i].second = i;
		}
		sort(arr, arr + n, greater<pii>());
		for (int i = 0; i < n; i++) {
			scanf("%d", &a);
			num[a]--;
			if (num[a] < 0) suc = false;
			pq.push({ a,i });
		}
		if (!suc) {
			printf("NO\n");
			continue;
		}
		init(1, 0, n - 1);
		for (int i = 0; i < n; i++) {
			pii cur = pq.top();
			pq.pop();
			int xx = mx(1, 0, n - 1, arr[i].second, n - 1);
			if (xx < cur.second) {
				suc = false;
			}
			update(1, 0, n - 1, arr[i].second, cur.second);
		}
		if (!suc) {
			printf("NO\n");
		}
		else printf("YES\n");
	}

	return 0;
}


#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <climits>
#include <unordered_set>
#include <unordered_map>
#include <cassert>
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define pdi pair<double,int>
#define mod 1000000007
#define mod1 1000000009
#define mod2 1000000021
#define INF 100000000001
#define MAX 1000000000
#define M 1001
long double PI = 3.141592653589793238462643383279502884197;
using namespace std;

/* 🐣🐥 */
int num[300001], tree[1048576];
pii arr[300001];
priority_queue<pii> pq;
void init(int idx, int s, int e) {
	tree[idx] = MAX;
	if (s == e) return;
	init(idx * 2, s, (s + e) / 2);
	init(idx * 2 + 1, (s + e) / 2 + 1, e);
}
void update(int idx, int s, int e, int k, int val) {
	if (k > e || k < s) return;
	tree[idx] = val;
	if (s == e) return;
	update(idx * 2, s, (s + e) / 2, k, val);
	update(idx * 2 + 1, (s + e) / 2 + 1, e,  k, val);
	tree[idx] = min(tree[idx * 2], tree[idx * 2 + 1]);;
}
int mx(int idx, int s, int e, int l, int r) {
	if (s > r || e < l) return MAX;
	if (l <= s && e <= r) return tree[idx];
	return min(mx(idx * 2, s, (s + e) / 2, l, r),
		mx(idx * 2 + 1, (s + e) / 2 + 1, e, l, r));
}
int main() {
	int t, n, a;
	scanf("%d", &t);
	while (t--) {
		bool suc = true;
		scanf("%d", &n);
		fill(num, num + n, 0);
		while (!pq.empty()) pq.pop();
		for (int i = 0; i < n; i++) {
			scanf("%d", &arr[i].first);
			num[arr[i].first]++;
			arr[i].second = i;
		}
		sort(arr, arr + n, greater<pii>());
		for (int i = 0; i < n; i++) {
			scanf("%d", &a);
			num[a]--;
			if (num[a] < 0) suc = false;
			pq.push({ a,i });
		}
		if (!suc) {
			printf("NO\n");
			continue;
		}
		init(1, 0, n - 1);
		for (int i = 0; i < n; i++) {
			pii cur = pq.top();
			pq.pop();
			int xx = mx(1, 0, n - 1, arr[i].second, n - 1);
			if (xx < cur.second) {
				suc = false;
			}
			update(1, 0, n - 1, arr[i].second, cur.second);
		}
		if (!suc) {
			printf("NO\n");
		}
		else printf("YES\n");
	}

	return 0;
}


#include <cstdio>
#include <memory.h>
#include <cstring>
#include <vector>
#include <deque>
#include <cstdlib>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cassert>
#include <functional>
#include <iostream>
#include <set>
#include <list>
#include <map>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
using namespace std;

typedef long long ll;
typedef unsigned long long llu;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<string, int> psi;
typedef pair<char, int> pci;
typedef pair<int, char> pic;
const ll MOD = (ll)1e9 + 7;
const long double PI = 3.141592653589793238462643383279502884197;

priority_queue<int, vector<int>, greater<int> > pq;
vector<int> v;

pii a[300000];
pii b[300000];

multiset<int> aa, bb;
int tree[1048576];
int val[300000];
int szz;

int find(int i, int l, int r, int le, int ri) {
	if (le > r || ri < l) return 0;
	if (le >= l && ri <= r) return tree[i];
	return max(find(i * 2, l, r, le, (le + ri) / 2), find(i * 2 + 1, l, r, (le + ri) / 2 + 1, ri));
}

void update(int i, int val) {
	i += szz;
	tree[i] += val;
	i /= 2;

	while (i) {
		tree[i] = max(tree[i * 2], tree[i * 2 + 1]);
		i /= 2;
	}
}

int main() {
	int q;
	scanf("%d", &q);

	while (q--) {
		aa.clear();
		bb.clear();

		int n;
		scanf("%d", &n);
		szz = 1;
		while (szz < n) szz *= 2;
		memset(tree, 0, sizeof(int) * szz * 2);

		for (int i = 0; i < n; i++) {
			scanf("%d", &a[i].first);
			aa.insert(a[i].first);

			a[i].second = i;
		}

		for (int i = 0; i < n; i++) {
			scanf("%d", &b[i].first);
			bb.insert(b[i].first);

			b[i].second = i;
		}

		if (aa != bb) {
			printf("NO\n");
			continue;
		}

		sort(a, a + n, greater<pii>());
		sort(b, b + n, greater<pii>());

		int flag = 0;
		for (int i = 0; i < n; i++) {
			val[i] = find(1, 0, b[i].second, 0, szz - 1);
			update(b[i].second, a[i].second);

			if (val[i] > b[i].second) {
				printf("NO\n");
				flag = 1;
				break;
			}
		}

		if (!flag) printf("YES\n");
	}
}


#include <cstdio>
#include <memory.h>
#include <cstring>
#include <vector>
#include <deque>
#include <cstdlib>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cassert>
#include <functional>
#include <iostream>
#include <set>
#include <list>
#include <map>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
using namespace std;

typedef long long ll;
typedef unsigned long long llu;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<string, int> psi;
typedef pair<char, int> pci;
typedef pair<int, char> pic;
const ll MOD = (ll)1e9 + 7;
const long double PI = 3.141592653589793238462643383279502884197;

priority_queue<int, vector<int>, greater<int> > pq;
vector<int> v;

pii a[300000];
pii b[300000];

multiset<int> aa, bb;
int tree[1048576];
int val[300000];
int szz;

int find(int i, int l, int r, int le, int ri) {
	if (le > r || ri < l) return 0;
	if (le >= l && ri <= r) return tree[i];
	return max(find(i * 2, l, r, le, (le + ri) / 2), find(i * 2 + 1, l, r, (le + ri) / 2 + 1, ri));
}

void update(int i, int val) {
	i += szz;
	tree[i] += val;
	i /= 2;

	while (i) {
		tree[i] = max(tree[i * 2], tree[i * 2 + 1]);
		i /= 2;
	}
}

int main() {
	int q;
	scanf("%d", &q);

	while (q--) {
		aa.clear();
		bb.clear();

		int n;
		scanf("%d", &n);
		szz = 1;
		while (szz < n) szz *= 2;
		memset(tree, 0, sizeof(int) * szz * 2);

		for (int i = 0; i < n; i++) {
			scanf("%d", &a[i].first);
			aa.insert(a[i].first);

			a[i].second = i;
		}

		for (int i = 0; i < n; i++) {
			scanf("%d", &b[i].first);
			bb.insert(b[i].first);

			b[i].second = i;
		}

		if (aa != bb) {
			printf("NO\n");
			continue;
		}

		sort(a, a + n, greater<pii>());
		sort(b, b + n, greater<pii>());

		int flag = 0;
		for (int i = 0; i < n; i++) {
			val[i] = find(1, 0, b[i].second, 0, szz - 1);
			update(b[i].second, a[i].second);

			if (val[i] > a[i].second) {
				printf("NO\n");
				flag = 1;
				break;
			}
		}

		if (!flag) printf("YES\n");
	}
}


#include <bits/stdc++.h>

using namespace std;

const int oo = 1000000009;

vector<int> p[300005];
int test, n, a[300005], t[1200005];

void build(int l, int r, int id) {
    if (l == r) {
        if (p[l].empty()) t[id] = oo; else t[id] = p[l].back();
        return;
    }
    int m = (l + r) >> 1;
    build(l, m, id << 1); build(m + 1, r, id << 1 | 1);
    t[id] = min(t[id << 1], t[id << 1 | 1]);
}

int get(int l, int r, int x, int y, int id) {
    if (r < x || y < l) return oo;
    if (x <= l && r <= y) return t[id];
    int m = (l + r) >> 1;
    return min(get(l, m, x, y, id << 1), get(m + 1, r, x, y, id << 1 | 1));
}

void update(int l, int r, int x, int id) {
    if (l == r) {
        if (p[l].empty()) t[id] = oo; else t[id] = p[l].back();
        return;
    }
    int m = (l + r) >> 1;
    if (x <= m) update(l, m, x, id << 1);
    else update(m + 1, r, x, id << 1 | 1);
    t[id] = min(t[id << 1], t[id << 1 | 1]);
}

bool check() {
    int b;
    for (int i = 1; i <= n; i++) {
        cin >> b;

        if (p[b].empty()) return false;
        if (get(1, n, 1, b, 1) < p[b].back()) return false;

        p[b].pop_back(); update(1, n, b, 1);
    }
    return true;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("CODEFORCES.INP", "r", stdin);
    freopen("CODEFORCES.OUT", "w", stdout);
#endif

    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    cin >> test;
    while (test--) {
        cin >> n;
        for (int i = 1; i <= n; i++) {
            cin >> a[i];
            p[i].clear();
        }

        for (int i = n; i > 0; i--) p[a[i]].push_back(i);

        for (int i = 1; i <= 4 * n + 10; i++) t[i] = oo;
        build(1, n, 1);

        cout << (check() ? "YES\n" : "NO\n");
    }
}


#include <bits/stdc++.h>

using namespace std;

const int oo = 1000000009;

vector<int> p[300005];
int test, n, a[300005], t[1200005];

void build(int l, int r, int id) {
    if (l == r) {
        t[id] = (p[l].empty() ? oo : p[l].back());
        return;
    }
    int m = (l + r) >> 1;
    build(l, m, id << 1); build(m + 1, r, id << 1 | 1);
    t[id] = min(t[id << 1], t[id << 1 | 1]);
}

int get(int l, int r, int x, int y, int id) {
    if (r < x || y < l) return oo;
    if (x <= l && r <= y) return t[id];
    int m = (l + r) >> 1;
    return min(get(l, m, x, y, id << 1), get(m + 1, r, x, y, id << 1 | 1));
}

void update(int l, int r, int x, int id) {
    if (l == r) {
        t[id] = (p[l].empty() ? oo : p[l].back());
        return;
    }
    int m = (l + r) >> 1;
    if (x <= m) update(l, m, x, id << 1);
    else update(m + 1, r, x, id << 1 | 1);
    t[id] = min(t[id << 1], t[id << 1 | 1]);
}

bool check() {
    int b;
    for (int i = 1; i <= n; i++) {
        cin >> b;
        if (p[b].empty() || get(1, n, 1, b, 1) < p[b].back()) return false;
        p[b].pop_back(); update(1, n, b, 1);
    }
    return true;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("CODEFORCES.INP", "r", stdin);
    freopen("CODEFORCES.OUT", "w", stdout);
#endif

    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    cin >> test;
    while (test--) {
        cin >> n;
        for (int i = 1; i <= n; i++) {
            cin >> a[i];
            p[i].clear();
        }

        for (int i = n; i > 0; i--) p[a[i]].push_back(i);

        for (int i = 1; i <= 4 * n + 10; i++) t[i] = oo;
        build(1, n, 1);

        cout << (check() ? "YES\n" : "NO\n");
    }
}


#include <bits/stdc++.h>

using namespace std;

int test, n, a[300005], t[1200005];
vector<int> p[300005];

void build(int l, int r, int id) {
    if (l == r) {
        t[id] = (p[l].empty() ? n + 2 : p[l].back());
        return;
    }
    int m = (l + r) >> 1;
    build(l, m, id << 1); build(m + 1, r, id << 1 | 1);
    t[id] = min(t[id << 1], t[id << 1 | 1]);
}

int get(int l, int r, int x, int y, int id) {
    if (r < x || y < l) return n + 2;
    if (x <= l && r <= y) return t[id];
    int m = (l + r) >> 1;
    return min(get(l, m, x, y, id << 1), get(m + 1, r, x, y, id << 1 | 1));
}

void update(int l, int r, int x, int id) {
    if (l == r) {
        t[id] = (p[l].empty() ? n + 2 : p[l].back());
        return;
    }
    int m = (l + r) >> 1;
    if (x <= m) update(l, m, x, id << 1);
    else update(m + 1, r, x, id << 1 | 1);
    t[id] = min(t[id << 1], t[id << 1 | 1]);
}

bool check() {
    int b;
    for (int i = 1; i <= n; i++) {
        cin >> b;
        if (p[b].empty() || get(1, n, 1, b, 1) < p[b].back()) return false;
        p[b].pop_back(); update(1, n, b, 1);
    }
    return true;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("CODEFORCES.INP", "r", stdin);
    freopen("CODEFORCES.OUT", "w", stdout);
#endif

    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    cin >> test;
    while (test--) {
        cin >> n;
        for (int i = 1; i <= n; i++) {
            cin >> a[i];
            p[a[i]].clear();
        }

        for (int i = n; i > 0; i--) p[a[i]].push_back(i);

        for (int i = 1; i <= 4 * n + 10; i++) t[i] = n + 3;
        build(1, n, 1);

        cout << (check() ? "YES\n" : "NO\n");
    }
}


#include <bits/stdc++.h>

using namespace std;

int test, n;
vector<int> a, t;
vector< vector<int> > p;

void build(int l, int r, int id) {
    if (l == r) {
        t[id] = (p[l].empty() ? n + 2 : p[l].back());
        return;
    }
    int m = (l + r) >> 1;
    build(l, m, id << 1); build(m + 1, r, id << 1 | 1);
    t[id] = min(t[id << 1], t[id << 1 | 1]);
}

int get(int l, int r, int x, int y, int id) {
    if (r < x || y < l) return n + 2;
    if (x <= l && r <= y) return t[id];
    int m = (l + r) >> 1;
    return min(get(l, m, x, y, id << 1), get(m + 1, r, x, y, id << 1 | 1));
}

void update(int l, int r, int x, int id) {
    if (l == r) {
        t[id] = (p[l].empty() ? n + 2 : p[l].back());
        return;
    }
    int m = (l + r) >> 1;
    if (x <= m) update(l, m, x, id << 1);
    else update(m + 1, r, x, id << 1 | 1);
    t[id] = min(t[id << 1], t[id << 1 | 1]);
}

bool check() {
    int b;
    for (int i = 1; i <= n; i++) {
        cin >> b;
        if (p[b].empty() || get(1, n, 1, b, 1) < p[b].back()) return false;
        p[b].pop_back(); update(1, n, b, 1);
    }
    return true;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("CODEFORCES.INP", "r", stdin);
    freopen("CODEFORCES.OUT", "w", stdout);
#endif

    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    cin >> test;
    while (test--) {
        cin >> n;

        a.clear(); a.resize(n + 3);
        for (int i = 1; i <= n; i++) cin >> a[i];

        p.clear(); p.resize(n + 3);
        for (int i = n; i > 0; i--) p[a[i]].push_back(i);

        t.clear(); t.resize(n * 4 + 100);
        build(1, n, 1);

        cout << (check() ? "YES\n" : "NO\n");
    }
}


#include <bits/stdc++.h>

using namespace std;

const int oo = 1000000009;

vector<int> p[300005];
int test, n, a[300005], b[300005], t[1200005];

void build(int l, int r, int id) {
    if (l == r) {
        t[id] = (p[l].empty() ? oo : p[l].back());
        return;
    }
    int m = (l + r) >> 1;
    build(l, m, id << 1); build(m + 1, r, id << 1 | 1);
    t[id] = min(t[id << 1], t[id << 1 | 1]);
}

int get(int l, int r, int x, int y, int id) {
    if (r < x || y < l) return oo;
    if (x <= l && r <= y) return t[id];
    int m = (l + r) >> 1;
    return min(get(l, m, x, y, id << 1), get(m + 1, r, x, y, id << 1 | 1));
}

void update(int l, int r, int x, int id) {
    if (l == r) {
        t[id] = (p[l].empty() ? oo : p[l].back());
        return;
    }
    int m = (l + r) >> 1;
    if (x <= m) update(l, m, x, id << 1);
    else update(m + 1, r, x, id << 1 | 1);
    t[id] = min(t[id << 1], t[id << 1 | 1]);
}

bool check() {
    for (int i = 1; i <= n; i++) {
        if (p[b[i]].empty() || get(1, n, 1, b[i], 1) < p[b[i]].back()) return false;
        p[b[i]].pop_back(); update(1, n, b[i], 1);
    }
    return true;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("CODEFORCES.INP", "r", stdin);
    freopen("CODEFORCES.OUT", "w", stdout);
#endif

    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    cin >> test;
    while (test--) {
        cin >> n;
        for (int i = 1; i <= n; i++) {
            cin >> a[i];
            p[i].clear();
        }

        for (int i = n; i > 0; i--) p[a[i]].push_back(i);

        for (int i = 1; i <= 4 * n + 10; i++) t[i] = oo;
        build(1, n, 1);

        for (int i = 1; i <= n; i++) cin >> b[i];

        cout << (check() ? "YES\n" : "NO\n");
    }
}


#include <bits/stdc++.h>

using namespace std;

int test, n, a[300005], t[1200005];
vector<int> p[300005];

void build(int l, int r, int id) {
    if (l == r) {
        t[id] = (p[l].empty() ? n + 2 : p[l].back());
        return;
    }
    int m = (l + r) >> 1;
    build(l, m, id << 1); build(m + 1, r, id << 1 | 1);
    t[id] = min(t[id << 1], t[id << 1 | 1]);
}

int get(int l, int r, int x, int y, int id) {
    if (r < x || y < l) return n + 2;
    if (x <= l && r <= y) return t[id];
    int m = (l + r) >> 1;
    return min(get(l, m, x, y, id << 1), get(m + 1, r, x, y, id << 1 | 1));
}

void update(int l, int r, int x, int id) {
    if (l == r) {
        t[id] = (p[l].empty() ? n + 2 : p[l].back());
        return;
    }
    int m = (l + r) >> 1;
    if (x <= m) update(l, m, x, id << 1);
    else update(m + 1, r, x, id << 1 | 1);
    t[id] = min(t[id << 1], t[id << 1 | 1]);
}

bool check() {
    int b;
    for (int i = 1; i <= n; i++) {
        cin >> b;
        if (p[b].empty() || get(1, n, 1, b, 1) < p[b].back()) return false;
        p[b].pop_back(); update(1, n, b, 1);
    }
    return true;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("CODEFORCES.INP", "r", stdin);
    freopen("CODEFORCES.OUT", "w", stdout);
#endif

    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    cin >> test;
    while (test--) {
        cin >> n;
        for (int i = 1; i <= n; i++) {
            cin >> a[i];
            p[a[i]].clear();
        }

        for (int i = n; i > 0; i--) p[a[i]].push_back(i);

        build(1, n, 1);

        cout << (check() ? "YES\n" : "NO\n");
    }
}


#include <bits/stdc++.h>

using namespace std;

int test, n;
vector<int> a, t;
vector< stack<int> > p;

void build(int l, int r, int id) {
    if (l == r) {
        t[id] = (p[l].empty() ? n + 2 : p[l].top());
        return;
    }
    int m = (l + r) >> 1;
    build(l, m, id << 1); build(m + 1, r, id << 1 | 1);
    t[id] = min(t[id << 1], t[id << 1 | 1]);
}

int get(int l, int r, int x, int y, int id) {
    if (r < x || y < l) return n + 2;
    if (x <= l && r <= y) return t[id];
    int m = (l + r) >> 1;
    return min(get(l, m, x, y, id << 1), get(m + 1, r, x, y, id << 1 | 1));
}

void update(int l, int r, int x, int id) {
    if (l == r) {
        t[id] = (p[l].empty() ? n + 2 : p[l].top());
        return;
    }
    int m = (l + r) >> 1;
    if (x <= m) update(l, m, x, id << 1);
    else update(m + 1, r, x, id << 1 | 1);
    t[id] = min(t[id << 1], t[id << 1 | 1]);
}

bool check() {
    int b;
    for (int i = 1; i <= n; i++) {
        cin >> b;
        if (p[b].empty() || get(1, n, 1, b, 1) < p[b].top()) return false;
        p[b].pop(); update(1, n, b, 1);
    }
    return true;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("CODEFORCES.INP", "r", stdin);
    freopen("CODEFORCES.OUT", "w", stdout);
#endif

    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    cin >> test;
    while (test--) {
        cin >> n;

        a.clear(); a.resize(n + 3);
        for (int i = 1; i <= n; i++) cin >> a[i];

        p.clear(); p.resize(n + 3);
        for (int i = n; i > 0; i--) p[a[i]].push(i);

        t.clear(); t.resize(n * 4 + 100);
        build(1, n, 1);

        cout << (check() ? "YES\n" : "NO\n");
    }
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    int q;
    cin>>q;
    while(q--){
        int n;
        cin >> n;
        int a[n],b[n];
        for(int i=0;i<n;i++){
            cin>>a[i];
        }
        for(int i=0;i<n;i++){
            cin>>b[i];
        }
        multiset<ll> st;
        int now = n-1;
        st.insert(a[n-1]);
        a[n-1] = -1;
        bool pos = true;
        for(int i=n-1;i>=0;i--){
            if(!st.empty()){
                auto itr = st.end();
                itr--;
                if(*itr > b[i]){
                    pos = false;
                    break;
                }
                if(*itr == b[i]){
                    st.erase(itr);
                    continue;
                }
            }
            while(now>0 && a[now]!=b[i]){
                now--;
                st.insert(a[now]);
                a[now] = -1;
            }
            auto itr = st.end();
            itr--;
            if(*itr == b[i]){
                st.erase(itr);
                continue;
            }
            pos = false;
            break;
        }
        if(pos){
            cout << "YES" << "\n";
        }
        else cout << "NO\n";
    }

}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    int q;
    cin>>q;
    while(q--){
        int n;
        cin >> n;
        int a[n],b[n];
        for(int i=0;i<n;i++){
            cin>>a[i];
        }
        for(int i=0;i<n;i++){
            cin>>b[i];
        }
        multiset<ll> st;
        int now = n-1;
        st.insert(a[n-1]);
        a[n-1] = -1;
        bool pos = true;
        for(int i=n-1;i>=0;i--){
            if(!st.empty()){
                auto itr = st.end();
                itr--;
                if(*itr > b[i]){
                    pos = false;
                    break;
                }
                if(*itr == b[i]){
                    st.erase(itr);
                    continue;
                }
            }
            while(now>0){
                now--;
                st.insert(a[now]);
                if(a[now] == b[i]){
                    a[now] = -1;
                    break;
                }
                a[now]=-1;
            }
            auto itr = st.end();
            itr--;
            if(*itr == b[i]){
                st.erase(itr);
                continue;
            }
            pos = false;
            break;
        }
        if(pos){
            cout << "YES" << "\n";
        }
        else cout << "NO\n";
    }

}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

ll INF = 1e9+7;
ll N, dat[2222222];
void init(ll n){
    N = 1;
    while(N < n) N *= 2;
    for(ll i=0;i<2*N-1;i++) dat[i] = INF;
}

void update(ll ind, ll val){
    ind += N-1;
    dat[ind] = val;
    while(ind>0){
        ind = (ind-1)/2;
        dat[ind] = min(dat[ind*2 + 1], dat[ind*2+2]);
    }
}

// query(a,b,0,0,n) �� [a,b)
ll query(ll a, ll b, ll k, ll l, ll r){
    if(r<=a || b<=l) return INF;
    if(a<=l && r<=b) return dat[k];
    else{
        ll vl = query(a,b,k*2+1,l,(l+r)/2);
        ll vr = query(a,b,k*2+2,(l+r)/2,r);
        return min(vl,vr);
    }
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    int q;
    cin>>q;
    while(q--){
        int n;
        cin>>n;
        init(n);
        int a[n],b[n];
        queue<int> q[n+1];
        for(int i=0;i<n;i++){
            cin>>a[i];
            q[a[i]].push(i);
            update(i,a[i]);
        }
        bool pos = true;
        for(int i=0;i<n;i++){
            cin>>b[i];
        }
        for(int i=0;i<n;i++){
            if(q[b[i]].empty()){
                pos = false;
                break;
            }
            int t = q[b[i]].front();
            q[b[i]].pop();
            int mi = query(0,t+1,0,0,N);
            update(t,INF);
            if(mi < b[i]){
                pos = false;
                break;
            }
        }
        if(pos) cout << "YES\n";
        else cout << "NO\n";

    }

}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    int q;
    cin>>q;
    while(q--){
        int n;
        cin >> n;
        int a[n],b[n];
        for(int i=0;i<n;i++){
            cin>>a[i];
        }
        for(int i=0;i<n;i++){
            cin>>b[i];
        }
        multiset<ll> st;
        int now = 0;
        st.insert(a[0]);
        bool pos = true;
        for(int i=0;i<n;i++){
            if(!st.empty()){
                auto itr = st.begin();
                if(*itr == b[i]){
                    st.erase(itr);
                    continue;
                }
                if(*itr < b[i]){
                    pos = false;
                    break;
                }
            }
            while(now < n){
                now++;
                st.insert(a[now]);
                if(a[now] == b[i]) break;
            }
            auto itr = st.begin();
            if(*itr == b[i]){
                st.erase(itr);
                continue;
            }
            pos = false;
            break;
        }

        if(pos){
            cout << "YES" << "\n";
        }
        else cout << "NO\n";
    }

}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    int q;
    cin>>q;
    while(q--){
        int n;
        cin >> n;
        int a[n],b[n];
        for(int i=0;i<n;i++){
            cin>>a[i];
        }
        int p[n]={};
        int now = 0;
        for(int i=0;i<n;i++){
            cin>>b[i];
            if(i){
                if(b[i]>=b[i-1]) p[i] = now;
                else {
                    now = i;
                    p[i] = now;
                }
            }
        }
        bool pos = true;
        for(int i=0;i<n;){
            int now = p[i];
            multiset<int> sa,sb;
            while(i<n && p[i]==now){
                sa.insert(a[i]);
                sb.insert(b[i]);
                i++;
            }
            if(sa!=sb){
                pos = false;
                cout << "NO\n";
                break;
            }
        }
        if(pos){
            cout << "YES" << "\n";
        }
    }

}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

ll INF = 1e9+7;
ll N, dat[1000010];
void init(ll k){
    N = 1;
    while(N < k) N *= 2;
    for(ll i=0;i<2*N-1;i++) dat[i] = INF;
}

void update(ll k, ll num){
    k += N-1;
    dat[k] = num;
    while(k>0){
        k = (k-1)/2;
        dat[k] = min(dat[k*2 + 1], dat[k*2+2]);
    }
}

// query(a,b,0,0,n) �� [a,b)
ll query(ll a, ll b, ll k, ll l, ll r){
    if(r<=a || b<=l) return INF;
    if(a<=l && r<=b) return dat[k];
    else{
        ll vl = query(a,b,k*2+1,l,(l+r)/2);
        ll vr = query(a,b,k*2+2,(l+r)/2,r);
        return min(vl,vr);
    }
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    int q;
    cin>>q;
    while(q--){
        int n;
        cin>>n;
        init(n);
        int a[n],b[n];
        queue<int> q[n+1];
        for(int i=0;i<n;i++){
            cin>>a[i];
            q[a[i]].push(i);
            update(i,a[i]);
        }
        bool pos = true;
        for(int i=0;i<n;i++){
            cin>>b[i];
        }
        for(int i=0;i<n;i++){
            if(q[b[i]].empty()){
                pos = false;
                break;
            }
            int t = q[b[i]].front();
            q[b[i]].pop();
            int mi = query(0,t+1,0,0,n);
            update(t,INF);
            if(mi != b[i]) pos = false;
        }
        if(pos) cout << "YES\n";
        else cout << "NO\n";

    }

}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

ll INF = 1e9+7;
ll N, dat[2222222];
void init(ll n){
    N = 1;
    while(N < n) N *= 2;
    for(ll i=0;i<2*N-1;i++) dat[i] = INF;
}

void update(ll ind, ll val){
    ind += N-1;
    dat[ind] = val;
    while(ind>0){
        ind = (ind-1)/2;
        dat[ind] = min(dat[ind*2 + 1], dat[ind*2+2]);
    }
}

// query(a,b,0,0,n) �� [a,b)
ll query(ll a, ll b, ll k, ll l, ll r){
    if(r<=a || b<=l) return INF;
    if(a<=l && r<=b) return dat[k];
    else{
        ll vl = query(a,b,k*2+1,l,(l+r)/2);
        ll vr = query(a,b,k*2+2,(l+r)/2,r);
        return min(vl,vr);
    }
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    int q;
    cin>>q;
    while(q--){
        int n;
        cin>>n;
        init(n);
        int a[n],b[n];
        queue<int> q[n+1];
        for(int i=0;i<n;i++){
            cin>>a[i];
            q[a[i]].push(i);
            update(i,a[i]);
        }
        bool pos = true;
        for(int i=0;i<n;i++){
            cin>>b[i];
        }
        for(int i=0;i<n;i++){
            if(q[b[i]].empty()){
                pos = false;
                break;
            }
            int t = q[b[i]].front();
            q[b[i]].pop();
            int mi = query(0,t+1,0,0,n);
            update(t,INF);
            if(mi < b[i]){
                pos = false;
                break;
            }
        }
        if(pos) cout << "YES\n";
        else cout << "NO\n";

    }

}


#include <bits/stdc++.h>
typedef long long ll;
//typedef unsigned long long ll;
using namespace std;
#define forii for(int i=1;i<=n;++i)
#define forji for(int j=1;j<=n;++j)
#define forij for(int i=1;i<=m;++i)
#define forjj for(int j=1;j<=m;++j)

int a[300005],b[300005];
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        forii cin>>a[i];
        forii cin>>b[i];
        int r=1;
        int ok=1;
        for(int i=1;i<=n;)
        {
            while(r<=n && b[r]!=a[i]) r++;
            if(r>n) {ok=0;break;}
            swap(a[i],a[r]);
            sort(a+i,a+r);
            sort(b+i,b+r);
            for(int j=i;j<r;++j) {
                if(a[j]!=b[j] || a[j]>a[r]) {ok=0;break;}
            }
            i=++r;
            if(!ok) break;
        }
        ok?cout<<"YES\n":cout<<"NO\n";
    }
}


#include <bits/stdc++.h>
typedef long long ll;
//typedef unsigned long long ll;
using namespace std;
#define forii for(int i=1;i<=n;++i)
#define forji for(int j=1;j<=n;++j)
#define forij for(int i=1;i<=m;++i)
#define forjj for(int j=1;j<=m;++j)

int a[300005],b[300005];
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        forii cin>>a[i];
        forii cin>>b[i];
        int r=1;
        int ok=1;
        for(int i=1;i<=n;)
        {
            while(r<=n && b[r]!=a[i]) r++;
            if(r>n) {ok=0;break;}
            swap(a[i],a[r]);
            sort(a+i,a+r);
            for(int j=i;j<r;++j) {
                if(a[j]!=b[j] || a[j]>a[r]) {ok=0;break;}
            }
            i=++r;
            if(!ok) break;
        }
        ok?cout<<"YES\n":cout<<"NO\n";
    }
}


#include <bits/stdc++.h>
typedef long long ll;
//typedef unsigned long long ll;
using namespace std;
#define forii for(int i=1;i<=n;++i)
#define forji for(int j=1;j<=n;++j)
#define forij for(int i=1;i<=m;++i)
#define forjj for(int j=1;j<=m;++j)

int mn[1200005];
void update(int pos,int val,int l,int r,int rt) {
    if(l==r) {
        mn[rt]=val;
        return;
    }
    int m=(l+r)/2;
    if(pos<=m) update(pos,val,l,m,rt<<1);
    else update(pos,val,m+1,r,rt<<1|1);
    mn[rt]=min(mn[rt<<1],mn[rt<<1|1]);
}
int query(int L,int R,int l,int r,int rt){
    if(L<=l&&r<=R) return mn[rt];
    int m=(l+r)/2;
    int ret = 1e9;
    if(L<=m) ret=min(ret,query(L,R,l,m,rt<<1));
    if(m< R) ret=min(ret,query(L,R,m+1,r,rt<<1|1));
    return ret;
}
int a[300005],b[300005],aa[300005],bb[300005];
queue<int> q[300005];
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t;
    cin>>t;
    while(t--) {
        int n;
        cin>>n;
        forii cin>>a[i],aa[i]=a[i];
        forii cin>>b[i],bb[i]=b[i];
        sort(aa+1,aa+1+n);
        sort(bb+1,bb+1+n);
        int ok1=1;
        forii if(aa[i]!=bb[i]) {ok1=0;break;}
        if(ok1) {cout<<"YES"<<endl;continue;}
        forii while(!q[a[i]].empty()) q[a[i]].pop();
        forii update(i,a[i],1,n,1);
        forii q[a[i]].push(i);
        int ok=1;
        forii {
            if(q[b[i]].empty()) {ok=0;break;}
            int m=query(1,q[b[i]].front(),1,n,1);
            if(m!=b[i]) {ok=0;break;}
            update(q[b[i]].front(),1e9,1,n,1);
            q[b[i]].pop();
        }
        if(ok) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
}


#include <bits/stdc++.h>
typedef long long ll;
//typedef unsigned long long ll;
using namespace std;
#define forii for(int i=1;i<=n;++i)
#define forji for(int j=1;j<=n;++j)
#define forij for(int i=1;i<=m;++i)
#define forjj for(int j=1;j<=m;++j)

int a[300005],b[300005];
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        forii cin>>a[i];
        forii cin>>b[i];
        int l=1,r=1;
        int ok=1;
        for(int i=1;i<=n;)
        {
            while(r<=n && b[r] != a[i]) r++;
            swap(a[i],a[r]);
            sort(a+i,a+r);
            sort(b+i,b+r);
            for(int j=i;j<r;++j) {
                if(a[j]!=b[j] || a[j]>a[r]) {ok=0;break;}
            }
            i=++r;
            if(!ok) break;
        }
        ok?cout<<"YES\n":cout<<"NO\n";
    }
}


#include <bits/stdc++.h>
typedef long long ll;
//typedef unsigned long long ll;
using namespace std;
#define forii for(int i=1;i<=n;++i)
#define forji for(int j=1;j<=n;++j)
#define forij for(int i=1;i<=m;++i)
#define forjj for(int j=1;j<=m;++j)

int mn[300005];
void update(int pos,int val,int l,int r,int rt) {
    if(l==r) {
        mn[rt]=val;
        return;
    }
    int m=(l+r)/2;
    if(pos<=m) update(pos,val,l,m,rt<<1);
    else update(pos,val,m+1,r,rt<<1|1);
    mn[rt]=min(mn[rt<<1],mn[rt<<1|1]);
}
int query(int L,int R,int l,int r,int rt){
    if(L<=l&&r<=R) return mn[rt];
    int m=(l+r)/2;
    int ret = 1e9;
    if(L<=m) ret=min(ret,query(L,R,l,m,rt<<1));
    if(m< R) ret=min(ret,query(L,R,m+1,r,rt<<1|1));
    return ret;
}
int a[300005],b[300005];
queue<int> q[300005];
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t;
    cin>>t;
    while(t--) {
        int n;
        cin>>n;
        forii {
            cin>>a[i];
            while(!q[a[i]].empty()) q[a[i]].pop();
        }
        forii update(i,a[i],1,n,1);
        forii q[a[i]].push(i);
        forii cin>>b[i];
        int ok=1;
        forii {
            if(q[b[i]].empty()) {ok=0;break;}
            int m=query(1,q[b[i]].front(),1,n,1);
            if(m!=b[i]) {ok=0;break;}
            update(q[b[i]].front(),1e9,1,n,1);
            q[b[i]].pop();
        }
        if(ok) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
}


#include <bits/stdc++.h>
typedef long long ll;
//typedef unsigned long long ll;
using namespace std;
#define forii for(int i=1;i<=n;++i)
#define forji for(int j=1;j<=n;++j)
#define forij for(int i=1;i<=m;++i)
#define forjj for(int j=1;j<=m;++j)

int a[300005],b[300005];
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        forii cin>>a[i];
        forii cin>>b[i];
        int r=1,r2=1;
        int ok=1;
        for(int i=1;i<=n;)
        {
            while(r<=n && b[r]!=a[i]) r++;
            int cnt=r-i;
            while(r2<=n && cnt) {
                r2++;
                if(a[r2]<a[i]) --cnt;
            }
            //cout<<i<<" "<<r2<<endl;
            if(r2>n) {ok=0;break;}
            sort(a+i,a+r2+1);
            for(int j=i;j<=r2;++j) {
                if(a[j]!=b[j]) {ok=0;break;}
            }
            r=i=++r2;
            if(!ok) break;
        }
        ok?cout<<"YES\n":cout<<"NO\n";
    }
}


#include <bits/stdc++.h>
typedef long long ll;
//typedef unsigned long long ll;
using namespace std;
#define forii for(int i=1;i<=n;++i)
#define forji for(int j=1;j<=n;++j)
#define forij for(int i=1;i<=m;++i)
#define forjj for(int j=1;j<=m;++j)

int mn[1200005];
void update(int pos,int val,int l,int r,int rt) {
    if(l==r) {
        mn[rt]=val;
        return;
    }
    int m=(l+r)/2;
    if(pos<=m) update(pos,val,l,m,rt<<1);
    else update(pos,val,m+1,r,rt<<1|1);
    mn[rt]=min(mn[rt<<1],mn[rt<<1|1]);
}
int query(int L,int R,int l,int r,int rt){
    if(L<=l&&r<=R) return mn[rt];
    int m=(l+r)/2;
    int ret = 1e9;
    if(L<=m) ret=min(ret,query(L,R,l,m,rt<<1));
    if(m< R) ret=min(ret,query(L,R,m+1,r,rt<<1|1));
    return ret;
}
int a[300005],b[300005],aa[300005],bb[300005];
queue<int> q[300005];
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t;
    cin>>t;
    while(t--) {
        int n;
        cin>>n;
        forii cin>>a[i],aa[i]=a[i];
        forii cin>>b[i],bb[i]=b[i];
        sort(aa+1,aa+1+n);
        sort(bb+1,bb+1+n);
        int ok1=0;
        forii if(aa[i]!=bb[i]) {ok1=1;break;}
        if(ok1) {cout<<"NO"<<endl;continue;}
        forii while(!q[a[i]].empty()) q[a[i]].pop();
        forii update(i,a[i],1,n,1);
        forii q[a[i]].push(i);
        int ok=1;
        forii {
            if(q[b[i]].empty()) {ok=0;break;}
            int m=query(1,q[b[i]].front(),1,n,1);
            if(m!=b[i]) {ok=0;break;}
            update(q[b[i]].front(),1e9,1,n,1);
            q[b[i]].pop();
        }
        if(ok) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
}


#include <bits/stdc++.h>
typedef long long ll;
//typedef unsigned long long ll;
using namespace std;
#define forii for(int i=1;i<=n;++i)
#define forji for(int j=1;j<=n;++j)
#define forij for(int i=1;i<=m;++i)
#define forjj for(int j=1;j<=m;++j)

int mn[1200005];
void update(int pos,int val,int l,int r,int rt) {
    if(l==r) {
        mn[rt]=val;
        return;
    }
    int m=(l+r)/2;
    if(pos<=m) update(pos,val,l,m,rt<<1);
    else update(pos,val,m+1,r,rt<<1|1);
    mn[rt]=min(mn[rt<<1],mn[rt<<1|1]);
}
int query(int L,int R,int l,int r,int rt){
    if(L<=l&&r<=R) return mn[rt];
    int m=(l+r)/2;
    int ret = 1e9;
    if(L<=m) ret=min(ret,query(L,R,l,m,rt<<1));
    if(m< R) ret=min(ret,query(L,R,m+1,r,rt<<1|1));
    return ret;
}
int a[300005],b[300005];
queue<int> q[300005];
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t;
    cin>>t;
    while(t--) {
        int n;
        cin>>n;
        forii {
            cin>>a[i];
            while(!q[a[i]].empty()) q[a[i]].pop();
        }
        forii update(i,a[i],1,n,1);
        forii q[a[i]].push(i);
        forii cin>>b[i];
        int ok=1;
        forii {
            if(q[b[i]].empty()) {ok=0;break;}
            int m=query(1,q[b[i]].front(),1,n,1);
            if(m!=b[i]) {ok=0;break;}
            update(q[b[i]].front(),1e9,1,n,1);
            q[b[i]].pop();
        }
        if(ok) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
}


#include <bits/stdc++.h>

using namespace std;
int q;
vector <pair<int, int> > a;
vector <pair<int, int> > b;
int ida[300001];
int idb[300001];
int elotta[300001];
int mna[300001];
int elottb[300001];
int mnb[300001];
void aert(int s, int f)
{
    if (s==f) {
        return;
    }
    int t=(s+f)/2;
    vector<int> q;
    for (int i=s; i<=t; i++) {
        q.push_back(ida[i]);
    }
    for (int i=t+1; i<=f; i++) {
        int x=-1, y=q.size();
        while(y-x>1) {
            int z=(x+y)/2;
            if (ida[i]>=q[z]) {
                x=z;
            } else {
                y=z;
            }
        }
        elotta[ida[i]]+=y;
    }
    aert(s, t);
    aert(t+1, f);
}
void bert(int s, int f)
{
    if (s==f) {
        return;
    }
    int t=(s+f)/2;
    vector<int> q;
    for (int i=s; i<=t; i++) {
        q.push_back(idb[i]);
    }
    for (int i=t+1; i<=f; i++) {
        int x=-1, y=q.size();
        while(y-x>1) {
            int z=(x+y)/2;
            if (idb[i]>=q[z]) {
                x=z;
            } else {
                y=z;
            }
        }
        elottb[idb[i]]+=y;
    }
    bert(s, t);
    bert(t+1, f);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin >> q;
    for (int i=1; i<=q; i++) {
        a.clear();
        b.clear();
        int n;
        cin >> n;
        a.push_back({0, 0});
        b.push_back({0, 0});
        for (int i=1; i<=n; i++) {
            int x;
            cin >> x;
            a.push_back({x, i});
        }
        for (int i=1; i<=n; i++) {
            int x;
            cin >> x;
            b.push_back({x, i});
        }
        sort(a.begin(), a.end());
        sort(b.begin(), b.end());
        for (int i=1; i<=n; i++) {
            ida[a[i].second]=i;
            idb[b[i].second]=i;
        }
        for (int i=1; i<=n; i++) {
            elotta[i]=0;
            elottb[i]=0;
        }
        aert(1, n);
        bert(1, n);
        for (int i=1; i<=n; i++) {
            int x=ida[i];
            mna[x]=n-x-i+elotta[x]+1;
            x=idb[i];
            mnb[x]=n-x-i+elottb[x]+1;
        }
        bool ans=true;
        for (int i=1; i<=n; i++) {
            if (a[i].first!=b[i].first) {
                ans=false;
            }
            if (elotta[i]>elottb[i]) {
                ans=false;
            }
            if (mnb[i]<mna[i]) {
                ans=false;
            }
            //cout << elotta[i] << " " << elottb[i] << " " << mna[i] << " " << mnb[i] << "\n";
        }
        if (ans) {
            cout << "YES";
        } else {
            cout << "NO";
        }
        cout << "\n";
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
int q;
vector <pair<int, int> > a;
vector <pair<int, int> > b;
int id[300001];
int idb[300001];
int re[300001];
int main()
{
    ios_base::sync_with_stdio(false);
    cin >> q;
    for (int i=1; i<=q; i++) {
        a.clear();
        b.clear();
        int n;
        cin >> n;
        a.push_back({0, 0});
        b.push_back({0, 0});
        for (int i=1; i<=n; i++) {
            int x;
            cin >> x;
            a.push_back({x, i});
        }
        for (int i=1; i<=n; i++) {
            int x;
            cin >> x;
            b.push_back({x, i});
        }
        sort(a.begin(), a.end());
        sort(b.begin(), b.end());
        for (int i=1; i<=n; i++) {
            id[a[i].second]=i;
            idb[b[i].second]=i;
        }
        for (int i=1; i<=n; i++) {
            re[idb[i]]=i;
        }
        bool ans=true;
        for (int i=1; i<=n; i++) {
            if (a[i].first!=b[i].first) {
                ans=false;
            }
            if (i>1) {
                if (id[i]>id[i-1] && re[id[i]]<re[id[i-1]]) {
                    ans=false;
                }
            }
        }
        if (ans) {
            cout << "YES";
        } else {
            cout << "NO";
        }
        cout << "\n";
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
int q;
vector <pair<int, int> > a;
vector <pair<int, int> > b;
int ida[300001][2];
int idb[300001];
int elotta[300001];
int mna[300001];
int elottb[300001];
int mnb[300001];
bool aert(int s, int f)
{
    if (s==f) {
        return true;
    }
    int t=(s+f)/2;
    vector<pair<int, int> > q;
    for (int i=s; i<=t; i++) {
        q.push_back({ida[i][0], ida[i][1]});
    }
    sort(q.begin(), q.end());
    for (int i=1; i<q.size(); i++) {
        q[i].second=max(q[i].second, q[i-1].second);
    }
    for (int i=t+1; i<=f; i++) {
        int x=-1, y=q.size();
        while(y-x>1) {
            int z=(x+y)/2;
            if (ida[i][0]>=q[z].first) {
                x=z;
            } else {
                y=z;
            }
        }
        if (x!=-1 && ida[i][1]<q[x].second) {
            return false;
        }
    }
    if (!aert(s, t)) {
        return false;
    }
    return aert(t+1, f);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin >> q;
    for (int i=1; i<=q; i++) {
        a.clear();
        b.clear();
        int n;
        cin >> n;
        a.push_back({0, 0});
        b.push_back({0, 0});
        for (int i=1; i<=n; i++) {
            int x;
            cin >> x;
            a.push_back({x, i});
        }
        for (int i=1; i<=n; i++) {
            int x;
            cin >> x;
            b.push_back({x, i});
        }
        sort(a.begin(), a.end());
        sort(b.begin(), b.end());
        for (int i=1; i<=n; i++) {
            ida[a[i].second][0]=i;
            idb[b[i].second]=i;
        }
        for (int i=1; i<=n; i++) {
            elottb[idb[i]]=i;
        }
        for (int i=1; i<=n; i++) {
            ida[i][1]=elottb[ida[i][0]];
        }
        bool ans=true;
        ans=aert(1, n);
        for (int i=1; i<=n; i++) {
            if (a[i].first!=b[i].first) {
                ans=false;
            }
        }
        if (ans) {
            cout << "YES";
        } else {
            cout << "NO";
        }
        cout << "\n";
    }
    return 0;
}
/*
1
7
1 7 2 3 4 5 6
1 2 3 4 5 7 6
*/


#include <bits/stdc++.h>

using namespace std;
int q;
vector <pair<int, int> > a;
vector <pair<int, int> > b;
int ida[300001];
int idb[300001];
int elotta[300001];
int elottb[300001];
int re[300001];
void aert(int s, int f)
{
    if (s==f) {
        return;
    }
    int t=(s+f)/2;
    vector<int> q;
    for (int i=s; i<=t; i++) {
        q.push_back(ida[i]);
    }
    for (int i=t+1; i<=f; i++) {
        int x=-1, y=q.size();
        while(y-x>1) {
            int z=(x+y)/2;
            if (ida[i]>=q[z]) {
                x=z;
            } else {
                y=z;
            }
        }
        elotta[ida[i]]+=y;
    }
    aert(s, t);
    aert(t+1, f);
}
void bert(int s, int f)
{
    if (s==f) {
        return;
    }
    int t=(s+f)/2;
    vector<int> q;
    for (int i=s; i<=t; i++) {
        q.push_back(idb[i]);
    }
    for (int i=t+1; i<=f; i++) {
        int x=-1, y=q.size();
        while(y-x>1) {
            int z=(x+y)/2;
            if (idb[i]>=q[z]) {
                x=z;
            } else {
                y=z;
            }
        }
        elottb[idb[i]]+=y;
    }
    bert(s, t);
    bert(t+1, f);
}
int main()
{
    ios_base::sync_with_stdio(false);
    /*int n;
    cin >> n;
    for (int i=1; i<=n; i++) {
        cin >> ida[i];
    }
    aert(1, n);
    for (int i=1; i<=n; i++) {
        cout << elotta[i] << " ";
    }*/
    cin >> q;
    for (int i=1; i<=q; i++) {
        a.clear();
        b.clear();
        int n;
        cin >> n;
        a.push_back({0, 0});
        b.push_back({0, 0});
        for (int i=1; i<=n; i++) {
            int x;
            cin >> x;
            a.push_back({x, i});
        }
        for (int i=1; i<=n; i++) {
            int x;
            cin >> x;
            b.push_back({x, i});
        }
        sort(a.begin(), a.end());
        sort(b.begin(), b.end());
        for (int i=1; i<=n; i++) {
            ida[a[i].second]=i;
            idb[b[i].second]=i;
        }
        for (int i=1; i<=n; i++) {
            elotta[i]=0;
            elottb[i]=0;
        }
        aert(1, n);
        bert(1, n);
        for (int i=1; i<=n; i++) {
            re[idb[i]]=i;
        }
        bool ans=true;
        for (int i=1; i<=n; i++) {
            if (a[i].first!=b[i].first) {
                ans=false;
            }
            if (elotta[i]>elottb[i]) {
                ans=false;
            }
        }
        if (ans) {
            cout << "YES";
        } else {
            cout << "NO";
        }
        cout << "\n";
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
int q;
vector <pair<int, int> > a;
vector <pair<int, int> > b;
int ida[300001][2];
int idb[300001];
int elotta[300001];
int mna[300001];
int elottb[300001];
int mnb[300001];
bool aert(int s, int f)
{
    if (s==f) {
        return true;
    }
    int t=(s+f)/2;
    vector<pair<int, int> > q;
    for (int i=s; i<=t; i++) {
        q.push_back({ida[i][0], ida[i][1]});
    }
    sort(q.begin(), q.end());
    for (int i=1; i<q.size(); i++) {
        q[i].second=max(q[i].second, q[i-1].second);
    }
    for (int i=t+1; i<=f; i++) {
        int x=-1, y=q.size();
        while(y-x>1) {
            int z=(x+y)/2;
            if (ida[i][0]>=q[z].first) {
                x=z;
            } else {
                y=z;
            }
        }
        if (x!=-1 && ida[i][1]<q[x].second) {
            return false;
        }
    }
    if (!aert(s, t)) {
        return false;
    }
    aert(s, t);
    return aert(t+1, f);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin >> q;
    for (int i=1; i<=q; i++) {
        a.clear();
        b.clear();
        int n;
        cin >> n;
        a.push_back({0, 0});
        b.push_back({0, 0});
        for (int i=1; i<=n; i++) {
            int x;
            cin >> x;
            a.push_back({x, i});
        }
        for (int i=1; i<=n; i++) {
            int x;
            cin >> x;
            b.push_back({x, i});
        }
        sort(a.begin(), a.end());
        sort(b.begin(), b.end());
        for (int i=1; i<=n; i++) {
            ida[a[i].second][0]=i;
            idb[b[i].second]=i;
        }
        for (int i=1; i<=n; i++) {
            elottb[idb[i]]=i;
        }
        for (int i=1; i<=n; i++) {
            ida[i][1]=elottb[ida[i][0]];
        }
        bool ans=true;
        ans=aert(1, n);
        for (int i=1; i<=n; i++) {
            if (a[i].first!=b[i].first) {
                ans=false;
            }
        }
        if (ans) {
            cout << "YES";
        } else {
            cout << "NO";
        }
        cout << "\n";
    }
    return 0;
}
/*
1
7
1 7 2 3 4 5 6
1 2 3 4 5 7 6
*/


#include <bits/stdc++.h>

using namespace std;
int q;
vector<pair<int, int> > t;
vector<pair<int, int> > p;
int main()
{
    ios_base::sync_with_stdio(false);
    cin >> q;
    for (int i=1; i<=q; i++) {
        t.clear();
        p.clear();
        int n;
        cin >> n;
        for (int i=1; i<=n; i++) {
            int a;
            cin >> a;
            t.push_back({a, i});
        }
        for (int i=1; i<=n; i++) {
            int a;
            cin >> a;
            p.push_back({a, i});
        }
        sort(t.begin(), t.end());
        sort(p.begin(), p.end());
        bool ans=true;
        for (int i=0; i<n; i++) {
            int a=t[i].first;
            int tse=t[i].second;
            int b=p[i].first;
            int pse=p[i].second;
            if (a!=b) {
                ans=false;
            }
            if (i>=1) {
                if (pse<p[i-1].second && tse>t[i-1].second) {
                    ans=false;
                }
            }
        }
        if (ans) {
            cout << "YES";
        } else {
            cout << "NO";
        }
        cout << "\n";
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
int q;
vector <pair<int, int> > a;
vector <pair<int, int> > b;
int ida[300001][2];
int idb[300001];
int elotta[300001];
int mna[300001];
int elottb[300001];
int mnb[300001];
bool aert(int s, int f)
{
    if (s==f) {
        return true;
    }
    int t=(s+f)/2;
    vector<pair<int, int> > q;
    for (int i=s; i<=t; i++) {
        q.push_back({ida[i][0], ida[i][1]});
    }
    sort(q.begin(), q.end());
    for (int i=1; i<q.size(); i++) {
        q[i].second=max(q[i].second, q[i-1].second);
    }
    for (int i=t+1; i<=f; i++) {
        int x=-1, y=q.size();
        while(y-x>1) {
            int z=(x+y)/2;
            if (ida[i][0]>=q[z].first) {
                x=z;
            } else {
                y=z;
            }
        }
        if (ida[i][1]>q[y].second) {
            return false;
        }
    }
    if (!aert(s, t)) {
        return false;
    }
    aert(s, t);
    return aert(t+1, f);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin >> q;
    for (int i=1; i<=q; i++) {
        a.clear();
        b.clear();
        int n;
        cin >> n;
        a.push_back({0, 0});
        b.push_back({0, 0});
        for (int i=1; i<=n; i++) {
            int x;
            cin >> x;
            a.push_back({x, i});
        }
        for (int i=1; i<=n; i++) {
            int x;
            cin >> x;
            b.push_back({x, i});
        }
        sort(a.begin(), a.end());
        sort(b.begin(), b.end());
        for (int i=1; i<=n; i++) {
            ida[a[i].second][0]=i;
            idb[b[i].second]=i;
        }
        for (int i=1; i<=n; i++) {
            elottb[idb[i]]=i;
        }
        for (int i=1; i<=n; i++) {
            ida[i][1]=elottb[ida[i][0]];
        }
        bool ans=true;
        ans=aert(1, n);
        for (int i=1; i<=n; i++) {
            if (a[i].first!=b[i].first) {
                ans=false;
            }
        }
        if (ans) {
            cout << "YES";
        } else {
            cout << "NO";
        }
        cout << "\n";
    }
    return 0;
}
/*
1
7
1 7 2 3 4 5 6
1 2 3 4 5 7 6
*/


#include <bits/stdc++.h>

using namespace std;
int q;
vector <pair<int, int> > a;
vector <pair<int, int> > b;
int ida[300001];
int idb[300001];
int elotta[300001];
int mna[300001];
int elottb[300001];
int mnb[300001];
void aert(int s, int f)
{
    if (s==f) {
        return;
    }
    int t=(s+f)/2;
    vector<int> q;
    for (int i=s; i<=t; i++) {
        q.push_back(ida[i]);
    }
    for (int i=t+1; i<=f; i++) {
        int x=-1, y=q.size();
        while(y-x>1) {
            int z=(x+y)/2;
            if (ida[i]>=q[z]) {
                x=z;
            } else {
                y=z;
            }
        }
        elotta[ida[i]]+=y;
    }
    aert(s, t);
    aert(t+1, f);
}
void bert(int s, int f)
{
    if (s==f) {
        return;
    }
    int t=(s+f)/2;
    vector<int> q;
    for (int i=s; i<=t; i++) {
        q.push_back(idb[i]);
    }
    for (int i=t+1; i<=f; i++) {
        int x=-1, y=q.size();
        while(y-x>1) {
            int z=(x+y)/2;
            if (idb[i]>=q[z]) {
                x=z;
            } else {
                y=z;
            }
        }
        elottb[idb[i]]+=y;
    }
    bert(s, t);
    bert(t+1, f);
}
int main()
{
    ios_base::sync_with_stdio(false);
    /*int n;
    cin >> n;
    for (int i=1; i<=n; i++) {
        cin >> ida[i];
    }
    aert(1, n);
    for (int i=1; i<=n; i++) {
        cout << elotta[i] << " ";
    }*/
    cin >> q;
    for (int i=1; i<=q; i++) {
        a.clear();
        b.clear();
        int n;
        cin >> n;
        a.push_back({0, 0});
        b.push_back({0, 0});
        for (int i=1; i<=n; i++) {
            int x;
            cin >> x;
            a.push_back({x, i});
        }
        for (int i=1; i<=n; i++) {
            int x;
            cin >> x;
            b.push_back({x, i});
        }
        sort(a.begin(), a.end());
        sort(b.begin(), b.end());
        for (int i=1; i<=n; i++) {
            ida[a[i].second]=i;
            idb[b[i].second]=i;
        }
        for (int i=1; i<=n; i++) {
            elotta[i]=0;
            elottb[i]=0;
        }
        aert(1, n);
        bert(1, n);
        for (int i=1; i<=n; i++) {
            int x=ida[i];
            mna[x]=n-x-i+elotta[x]+1;
            x=idb[i];
            mnb[x]=n-x-i+elottb[x]+1;
        }
        bool ans=true;
        for (int i=1; i<=n; i++) {
            if (a[i].first!=b[i].first) {
                ans=false;
            }
            if (elotta[i]>elottb[i]) {
                ans=false;
            }
            if (mnb[i]>mna[i]) {
                ans=false;
            }
        }
        if (ans) {
            cout << "YES";
        } else {
            cout << "NO";
        }
        cout << "\n";
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
int q;
vector <pair<int, int> > a;
vector <pair<int, int> > b;
int ida[300001];
int idb[300001];
int elotta[300001];
int mna[300001];
int elottb[300001];
int mnb[300001];
void aert(int s, int f)
{
    if (s==f) {
        return;
    }
    int t=(s+f)/2;
    vector<int> q;
    for (int i=s; i<=t; i++) {
        q.push_back(ida[i]);
    }
    sort(q.begin(), q.end());
    for (int i=t+1; i<=f; i++) {
        int x=-1, y=q.size();
        while(y-x>1) {
            int z=(x+y)/2;
            if (ida[i]>=q[z]) {
                x=z;
            } else {
                y=z;
            }
        }
        elotta[ida[i]]+=y;
    }
    aert(s, t);
    aert(t+1, f);
}
void bert(int s, int f)
{
    if (s==f) {
        return;
    }
    int t=(s+f)/2;
    vector<int> q;
    for (int i=s; i<=t; i++) {
        q.push_back(idb[i]);
    }
    sort(q.begin(), q.end());
    for (int i=t+1; i<=f; i++) {
        int x=-1, y=q.size();
        while(y-x>1) {
            int z=(x+y)/2;
            if (idb[i]>=q[z]) {
                x=z;
            } else {
                y=z;
            }
        }
        elottb[idb[i]]+=y;
    }
    bert(s, t);
    bert(t+1, f);
}
int main()
{
    ios_base::sync_with_stdio(false);
    /*int n;
    cin >> n;
    for (int i=1; i<=n; i++) {
        cin >> ida[i];
    }
    aert(1, n);
    for (int i=1; i<=n; i++) {
        cout << elotta[i] << endl;
    }*/
    cin >> q;
    for (int i=1; i<=q; i++) {
        a.clear();
        b.clear();
        int n;
        cin >> n;
        a.push_back({0, 0});
        b.push_back({0, 0});
        for (int i=1; i<=n; i++) {
            int x;
            cin >> x;
            a.push_back({x, i});
        }
        for (int i=1; i<=n; i++) {
            int x;
            cin >> x;
            b.push_back({x, i});
        }
        sort(a.begin(), a.end());
        sort(b.begin(), b.end());
        for (int i=1; i<=n; i++) {
            ida[a[i].second]=i;
            idb[b[i].second]=i;
        }
        for (int i=1; i<=n; i++) {
            elotta[i]=0;
            elottb[i]=0;
        }
        aert(1, n);
        bert(1, n);
        for (int i=1; i<=n; i++) {
            int x=ida[i];
            mna[x]=n-x-i+elotta[x]+1;
            x=idb[i];
            mnb[x]=n-x-i+elottb[x]+1;
        }
        bool ans=true;
        for (int i=1; i<=n; i++) {
            if (a[i].first!=b[i].first) {
                ans=false;
            }
            if (elotta[i]>elottb[i]) {
                ans=false;
            }
            if (mnb[i]<mna[i]) {
                ans=false;
            }
            //cout << elotta[i] << " " << elottb[i] << " " << mna[i] << " " << mnb[i] << "\n";
        }
        if (ans) {
            cout << "YES";
        } else {
            cout << "NO";
        }
        cout << "\n";
    }
    return 0;
}
/*
1
7
1 7 2 3 4 5 6
1 2 3 4 5 7 6
*/


#include <bits/stdc++.h>

using namespace std;
int q;
vector <pair<int, int> > a;
vector <pair<int, int> > b;
int ida[300001];
int idb[300001];
int elotta[300001];
int mna[300001];
int elottb[300001];
int mnb[300001];
void aert(int s, int f)
{
    if (s==f) {
        return;
    }
    int t=(s+f)/2;
    vector<int> q;
    for (int i=s; i<=t; i++) {
        q.push_back(ida[i]);
    }
    sort(q.begin(), q.end());
    for (int i=t+1; i<=f; i++) {
        int x=-1, y=q.size();
        while(y-x>1) {
            int z=(x+y)/2;
            if (ida[i]>=q[z]) {
                x=z;
            } else {
                y=z;
            }
        }
        elotta[ida[i]]+=y;
    }
    aert(s, t);
    aert(t+1, f);
}
void bert(int s, int f)
{
    if (s==f) {
        return;
    }
    int t=(s+f)/2;
    vector<int> q;
    for (int i=s; i<=t; i++) {
        q.push_back(idb[i]);
    }
    sort(q.begin(), q.end());
    for (int i=t+1; i<=f; i++) {
        int x=-1, y=q.size();
        while(y-x>1) {
            int z=(x+y)/2;
            if (idb[i]>=q[z]) {
                x=z;
            } else {
                y=z;
            }
        }
        elottb[idb[i]]+=y;
    }
    bert(s, t);
    bert(t+1, f);
}
int main()
{
    ios_base::sync_with_stdio(false);
    /*int n;
    cin >> n;
    for (int i=1; i<=n; i++) {
        cin >> ida[i];
    }
    aert(1, n);
    for (int i=1; i<=n; i++) {
        cout << elotta[i] << endl;
    }*/
    cin >> q;
    for (int i=1; i<=q; i++) {
        a.clear();
        b.clear();
        int n;
        cin >> n;
        a.push_back({0, 0});
        b.push_back({0, 0});
        for (int i=1; i<=n; i++) {
            int x;
            cin >> x;
            a.push_back({x, i});
        }
        for (int i=1; i<=n; i++) {
            int x;
            cin >> x;
            b.push_back({x, i});
        }
        sort(a.begin(), a.end());
        sort(b.begin(), b.end());
        for (int i=1; i<=n; i++) {
            ida[a[i].second]=i;
            idb[b[i].second]=i;
        }
        for (int i=1; i<=n; i++) {
            elotta[i]=0;
            elottb[i]=0;
        }
        aert(1, n);
        bert(1, n);
        for (int i=1; i<=n; i++) {
            int x=ida[i];
            mna[x]=n-x-i+elotta[x]+1;
            x=idb[i];
            mnb[x]=n-x-i+elottb[x]+1;
        }
        bool ans=true;
        for (int i=1; i<=n; i++) {
            if (a[i].first!=b[i].first) {
                ans=false;
            }
            if (elotta[i]>elottb[i]) {
                ans=false;
            }
            if (mnb[i]<mna[i]) {
                ans=false;
            }
            cout << elotta[i] << " " << elottb[i] << " " << mna[i] << " " << mnb[i] << "\n";
        }
        if (ans) {
            cout << "YES";
        } else {
            cout << "NO";
        }
        cout << "\n";
    }
    return 0;
}
/*
1
7
1 7 2 3 4 5 6
1 2 3 4 5 7 6
*/