#include <bits/stdc++.h>
#define arr array 
#define pb push_back
#define fs first 
#define sc second
#define eb emplace_back
#define vt vector
#define all(x) (x).begin(), (x).end()
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
 
using namespace std;
typedef long long ll;
const int maxn=1e5;
const ll MAXLL=9223372036854775807;
 
void solve(){
    int n;
    cin >> n;
    vt<int> a(n);
    rep(i, 0, n) cin >> a[i];
    set<int> s;
 
    auto ok=[&](int x, int y) -> bool {
        if (x==y) return true;
        auto lo=s.lower_bound(x);
        auto hi=s.upper_bound(x);
        if (y<x && (lo==s.begin()||*prev(lo)<=y)) return true;
        if (y>x && (hi==s.end()||*hi>=y)) return true;
        return false;
    };
    
    s.insert(a[0]);
    rep(i, 1, n){
        if (ok(a[i], a[i-1])==false){
            cout << "NO" << endl;
            return;
        }
        s.insert(a[i]);
    }
    cout << "YES" << endl;
}
 
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int t;
    cin >> t;
    while(t--){
        solve();
    }
}
