#include <bits/stdc++.h>
using namespace std;
#define getbit(n, i) (((n) & (1LL << (i))) != 0) 
#define setbit0(n, i) ((n) & (~(1LL << (i)))) 
#define setbit1(n, i) ((n) | (1LL << (i))) 
#define togglebit(n, i) ((n) ^ (1LL << (i))) 
#define lastone(n) ((n) & (-(n))) 
char gap = 32;
#define ll long long 
#define lll __int128_t
#define pb push_back

void solve(){
    ll i,j,k,l,n,m;
    cin >> n;
    ll data[n + 1];
    for(i = 1 ; i <= n ; i++) cin >> data[i];
    set<ll>s;
    for(i = 1 ; i < n ; i++){
        if(data[i] != data[i + 1]){
            auto pos = s.upper_bound(min(data[i] , data[i + 1]));
            if(pos != s.end() and *pos < max(data[i + 1] , data[i])){
                cout << "NO\n";
                return ;
            }
        }
        s.insert(data[i]);
    }
    cout << "YES\n";
    return ;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll t;
    cin >> t;
    while(t--){
        solve();
    }
    return 0;
}