#include <bits/stdc++.h>
#define int long long
#define BIG 10000000000
#define SMALL -10000000000
using namespace std;

struct Tree{
    int n,N=1,k=0;
    vector<int> tree;
    Tree(int i, int _n){
        n = _n+2;
        while(N < n){
            N <<= 1; k ++;
        }
        tree.resize(2*N); tree[N] = tree[N+i] = tree[2*N-1] = 1;
        for(int i = N-1; i > 0; i --) tree[i] = tree[2*i] + tree[2*i+1];
    }
    void update(int i){
        i += N; tree[i] = 1; i /= 2;
        while(i){
            tree[i] = 1; i /= 2;
        }
    }
    int sum(int l, int r){
        l += N; r += N;
        int s = 0;
        while(l < r){
            if(l % 2){
                s += tree[l]; l ++;
            }
            if(r % 2){
                r --; s += tree[r];
            }
            l /= 2; r /= 2;
        }
        return s;
    }
    int findl(int i){
        /*i --;
        while(tree[i+N] == 0) i --;
        return i;*/
        int l = 0, r = i;
        while(l+1 < r){
            int m = (l+r)/2;
            (sum(m,i) == 0 ? r : l) = m;
        }
        return l;
    }
    int findr(int i){
        /*i ++;
        while(tree[i+N] == 0) i ++;
        return i;*/
        int l = i+1, r = N;
        while(l+1 < r){
            int m = (l+r)/2;
            (sum(i+1,m) == 0 ? l : r) = m;
        }
        return l;
    }
};

signed main(){
    int t; cin >> t;
    while(t--){
        int n; cin >> n;
        vector<int> b(n); for(auto &v : b) cin >> v;
        //coord compress
        vector<int> c = b;
        sort(c.begin(), c.end());
        map<int,int> a;
        for(int i = 0; i < n; i ++) a[c[i]] = i;
        for(auto &v : b) v = a[v]+1;
        //
        bool okay = true;
        int p = b[0];
        Tree tree(b[0],n);
        for(int i : b){
            if(p == i) continue;
            else if(i < p){
                int l = tree.findl(p);
                if(i < l){
                    okay = false; break;
                }
                p = i; tree.update(i);
            }else{
                int r = tree.findr(p);
                if(i > r){
                    okay = false; break;
                }
                p = i; tree.update(i);
            }
        }
        cout << (okay ? "YES\n" : "NO\n");
    }
}