#include	<bits/stdc++.h>
using	namespace	std;
typedef	long long ll;
typedef	pair<int, int> pii;
typedef pair<ll, ll> pll;

// int/long:		-2,147,483,648 - 2,147,483,647 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

//#define	INF (1<<30)
#define	INF (2147483647)
// 2^31 -1
//= 1,073,741,824 *2 -1
//=   536,870,912 *4 -1

#define	MOD 1000000007

#define	Rep0(i, n)	for (auto i=0; i<n; i++)
#define	Rep1(i, n)	for (auto i=1; i<=n; i++)
#define Sort(P)	sort(P.begin(), P.end())
#define Rev(P)	reverse(P.begin(), P.end())

int	main() {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int t;
	cin >>t;
	Rep0(tt, t) {
		int n;
		cin >>n;
		vector<int> b(n, 0);
		Rep0(i, n)
			cin >>b.at(i);
		//
		vector<int> LOW={-MOD};
		vector<int> HIGH={MOD};
		int a1=b.at(0);
		bool OK=true;
		int a;
		Rep1(i, n-1) {
			a=b.at(i);
			if (a==a1)
				continue;
			if (a<a1) {
				if (a<LOW.back()) {
					OK=false;
					break;
				} else if (a==LOW.back()) {
					HIGH.push_back(a1);
					a1=a;
					LOW.pop_back();
				} else {
					HIGH.push_back(a1);
					a1=a;
				}
			} else { // a>a1
				if (a>HIGH.back()) {
					OK=false;
					break;
				} else if (a==HIGH.back()) {
					LOW.push_back(a1);
					a1=a;
					HIGH.pop_back();
				} else {
					LOW.push_back(a1);
					a1=a;
				}
			}
			if (!OK)
				break;
		}
		if (OK)
			cout <<"YES" <<endl;
		else
			cout <<"NO" <<endl;
	}
	return 0;
}

