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

#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define REVERSE(v) reverse((v).begin(), (v).end())
#define MAX(v) (*max_element((v).begin(), (v).end()))
#define MIN(v) (*min_element((v).begin(), (v).end()))
#define pb push_back
#define FOR(i, n) for(int i = 0; i < (n); i++)
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;

const int mod = 1e9 + 7;
const int mod2 = 998244353;

inline void modsum(int&a, int b){a += b;if(a >= mod) a -= mod;if(a < 0) a += mod;}
inline void modmul(int&a, int b){a = 1ll*a*b % mod;}
inline int modexp(ll b, ll p){b %= mod;int res = 1;int mul = b;while(p){if(p&1) modmul(res, mul);p >>= 1;modmul(mul, mul);}return res;}

const int N = 1e5 + 5;

int main(){
    ios::sync_with_stdio(false); cin.tie(NULL);
	int t; cin>>t;
	while(t--){
		int n; cin>>n;
		int a[n];
		set<int> s;
		bool ok = true;
		FOR(i, n){
			cin>>a[i];
			if(i <= 1){
				s.insert(a[i]);
				continue;
			}
			auto it = s.find(a[i-1]);
			if(a[i] > a[i-1]){
				it++;
				if(it != s.end() && *it < a[i]){
					ok = false;
				}
			}else{
				if(it != s.begin()){
					it--;
					if(*it > a[i]){
						ok = false;
					}
				}
			}
			s.insert(a[i]);
		}
		cout<<(ok ? "YES\n" : "NO\n");
	}
}