#include <bits/stdc++.h>

using namespace std;

const int mod = 1e9 + 7;
const int N = 5e6 + 132;
const long long WOW = 1e12;

int n;

long long a[N];
map <long long, long long> mp;
set <pair <long long, int> > q;

void solve() {
	q.clear();
	cin >> n;
	for(int i = 1; i <= n; i++) 
		cin >> a[i], mp[a[i]] = 1;
	/*
	mp[-WOW] = 1;
	mp[WOW] = 1;

	for(int i = 1; i <= n; i++)
		a[i] = mp[a[i]];
	long long big = mp[WOW];
	long long small = mp[-WOW];
	*/
	long long med = 0;
	bool ok = 1;
	for(int i = 1; i <= n; i++) {
		if(i == 1) {
			q.insert(make_pair(a[i], i));
			med = a[i];
		}else {
			if(a[i] < med) {
				set <pair <long long, int> > :: iterator it = q.lower_bound(make_pair(a[i] + 1, 0));
				if(it == q.end()) assert(0);
				if((*it).first != med) {
					ok = 0;
					break;
				}
				med = a[i];
				q.insert(make_pair(-WOW, i));
				q.insert(make_pair(a[i], i));
			} else if(a[i] > med) {
				set <pair <long long, int> > :: iterator it = q.lower_bound(make_pair(a[i], 0));
				if(it == q.begin()) {
//					cout << i << "AAA";
					assert(0);
				}
				it--;
				if((*it).first != med) {
					ok = 0;
					break;
				}
				med = a[i];
				q.insert(make_pair(WOW, i));
				q.insert(make_pair(a[i], i));
			}else {
				q.insert(make_pair(WOW, i));
				q.insert(make_pair(-WOW, i));
			}
		}
	}
	if(!ok) cout << "NO\n";
	else cout << "YES\n";
}
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);


	int T;
	cin >> T;
	while(T--) solve();
	
}























