#include <bits/stdc++.h>

using namespace std;

int t, n, b[200000];

int main() {
    cin >> t;
    while(t--) {
        cin >> n;
        set<int> s;
        bool good = true;
        for(int i = 0; i<n; i++) {
            cin >> b[i];
        }
        for(int i = 0; i<n; i++) {
            if(i>0) {
                auto it = s.find(b[i-1]);
                if(it!=s.begin()&&(*(--it)>b[i]))
                    good = false;
                it = s.find(b[i-1]);
                if(it!=(--s.end())&&(*(++it)<b[i]))
                    good = false;
            }
            s.insert(b[i]);
        }
        cout << (good?"YES":"NO") << endl;
    }
}
