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

#define int long long
#define IBS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)

#define PB          push_back
#define MP          make_pair
#define FF          first
#define SS          second
#define CNT 		continue
#define BK 			break
#define LB          lower_bound
#define UB          upper_bound
#define ALL(ele)    ele.begin(), ele.end()
#define IN(key,b)   ((b).find(key) != (b).end())
#define INS        insert
#define MOD9       1000000009
#define MOD7       1000000007
#define INF        1e18
#define CLR(x)     x.clear()
#define FND(x,key) x.find(key)
#define REV(x)     reverse(ALL(x))
#define RSZ(ar,n)  ar.resize(n)
#define REVSTR(str) string(str.rbegin(),str.rend())
#define SZ(x)      (int)((x).size())
#define LN(x)      (int)((x).length())
#define RR         return
#define W(t)       while(t--)
#define NL         "\n"
#define SORTVI(a)  sort(ALL(a))
#define SET_BITS   __builtin_popcountll
#define SORTAR(a,start,end) sort(a+start,a + end)
#define NOOFTESTCASES(x)    int t; cin>>t; W(t) x()
#define FON(i,a,b)          for(int i=a;i<b;i++)
#define REP(i,a,b)          for(int i=a;i<=b;i++)
#define RPBCK(i,a,b)        for(int i =  a ; i >= b;i--)

typedef unsigned long long ull;
typedef long double lld;
typedef vector<int> VI;
typedef pair<int, int>  PII;
typedef vector<PII>   VPII;
typedef vector<VI>    VVI;

//////////////////#####################DEBUG###############///////////////////////
#ifndef ONLINE_JUDGE
#define debug(x) cerr << #x <<" "; PNT(x); cerr << endl;
#else
#define debug(x)
#endif
void PNT(int t) {cerr << t;}
void PNT(string t) {cerr << t;}
void PNT(char t) {cerr << t;}
void PNT(lld t) {cerr << t;}
void PNT(double t) {cerr << t;}
void PNT(ull t) {cerr << t;}
template <class T, class V> void PNT(pair <T, V> p);
template <class T> void PNT(vector <T> v);
template <class T> void PNT(set <T> v);
template <class T, class V> void PNT(map <T, V> v);
template <class T> void PNT(multiset <T> v);
template <class T, class V> void PNT(pair <T, V> p) {cerr << "{"; PNT(p.FF); cerr << ","; PNT(p.SS); cerr << "}";}
template <class T> void PNT(vector <T> v) {cerr << "[ "; for (T i : v) {PNT(i); cerr << " ";} cerr << "]";}
template <class T> void PNT(set <T> v) {cerr << "[ "; for (T i : v) {PNT(i); cerr << " ";} cerr << "]";}
template <class T> void PNT(multiset <T> v) {cerr << "[ "; for (T i : v) {PNT(i); cerr << " ";} cerr << "]";}
template <class T, class V> void PNT(map <T, V> v) {cerr << "[ "; for (auto i : v) {PNT(i); cerr << " ";} cerr << "]";}

////////////////#####################INPUT###############///////////////////////
template <typename T> void read(T &p) { cin >> p;}
template <typename T, typename T1> void read(pair<T, T1> &p) {read(p.FF); read(p.SS);}
template <typename T> void read(T arr[], int n) {FON(i, 0, n) read(arr[i]);}
template <typename T> void read(vector<T> &arr) { FON(i, 0, SZ(arr)) read(arr[i]);}

////////////////#####################OUPUT###############///////////////////////
template <typename T> void out(T& n) { cout << n; }
template <typename T, typename T1> void out(pair<T, T1> &p) {out(p.FF); cout << " "; out(p.SS); cout << NL; }
template <typename T> void out(T arr[], int n) { FON(i, 0, n) {out(arr[i]); cout << " "; }}
template <typename T>void out(vector<T> &arr) {FON(i, 0, SZ(arr)) {out(arr[i]); cout << " ";} }
template <typename T>void out(set<T> &arr) {for (auto i : arr) {out(i); cout << " ";}}
void OJ();
bool isPrime(int);
bool is_palindrome(string);
int powmod(int, int, int);
VI ar ;
int n , ans , res , count ;
set<int> st;
bool ispos = false;
string ys = "YES" , no = "NO";
void cal1(int ele, int currele) {
	auto key = st.UB(ele);
	if (st.end() == key) {
		st.INS(currele);
	} else {
		int mks = *key;
		if (currele > mks) {
			ispos = 0 ;
			RR;
		} else {
			st.INS(currele);
		}
	}
}
void cal2(int ele, int currele) {
	auto key = st.LB(ele);
	if (st.begin() == key) st.INS(currele);
	else {
		key--;
		int mks = *key;
		if (currele < mks) {
			ispos = 0 ;
			RR;
		} else
		{st.INS(currele);}
	}
}
void solve() {
	// “Let the games begin!
	CLR(st);
	CLR(ar);

	read(n);
	RSZ(ar, n);

	int ele ;
	ispos = 1 ;
	FON(i, 0, n) {
		cin >> ar[i];
		if (i == 0) {
			ele = ar[i];
			st.INS(ele);
		}
	}

	FON(i, 1, n)
	{
		int currele = ar[i];
		if (currele == ele) {
			CNT ;
		} else if (ele < currele) {
			cal1(ele, currele);
		} else {
			cal2(ele, currele);
		}
		ele = currele;
	}
	cout << ((ispos) ? ys : no) << NL ;
}
signed main() {
	IBS;
	OJ();
	int tc = 1;
	read(tc);
	W(tc) solve();
}

void OJ() {
#ifndef ONLINE_JUDGE
	freopen("ip.txt", "r", stdin);
	freopen("op.txt", "w", stdout);
	freopen("er.txt", "w", stderr);
#endif
}
bool isPrime(int n) { if (n == 1) RR false ; for (int i = 2 ; i * i <= n ; i++) { if (n % i == 0) RR false ;} RR true;}
bool is_palindrome(string s) { RR equal(s.begin(), s.begin() + s.size() / 2, s.rbegin());}
int powmod(int a, int b, int mod) { a %= mod; int ans = 1; while (b > 0) {  if (b & 1) {ans = (ans * a) % mod;} a = (a * a) % mod; b >>= 1; } RR ans;}
