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

void program() {
	int n; cin>>n;
	vector<int> a(n, 0);
	for(int &k : a) cin>>k;
	set<int> ss; 
	int prev;
	for(int k : a) {
		if(ss.empty()) {
			ss.insert(k);
			prev = k;
			continue;
		}
		if(k == prev) continue;
		int sm = min(k, prev);
		int bg = max(k, prev);
		ss.insert(k);
		prev = k;
		if(*ss.upper_bound(sm) != bg) {
			cout<<"NO\n";
			return;
		}
	}
	cout<<"YES\n";
	return;
}

int main() {
	ios::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin >> t;
    while(t--) program();
}