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

#define ll long long
#define ld long double
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define F first
#define S second
#define nl "\n"
#define pll pair<ll, ll>
#define all(v) (v).begin(), (v).end()
#define decimal(n) cout << fixed << setprecision(n)
#define mod 1000000007
// #define mod 998244353
#define pi 3.14159265358979323846

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t = 1, tc;
    cin >> t;
    for (tc = 1; tc <= t; tc++)
    {
        ll n,i,j;
        cin>>n;
        ll a[n+3];
        for(i=0;i<n;i++)cin>>a[i];
        
        set<ll> s;
        s.insert(a[0]);
        
        bool f=0;
        for(i=1;i<n;i++){
            ll x=min(a[i],a[i-1]), y=max(a[i-1],a[i]);
            auto it=s.ub(x);
            
            if(it!=s.end() && *it<y){
                f=1;
                break;
            }
            s.insert(a[i]);
        }
        cout<<(f?"NO\n":"YES\n");
    }
    return 0;
}