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

void solve() {
	int n;
	cin >> n;
	vector<int> b(n);
	for (int i = 0; i < n; ++i) {
		cin >> b[i];
	}

	set<int> bst;
	bst.insert(b[0]);
	bool correct = true;
	for (int i = 1; i < n; ++i) {
		if (b[i] > b[i - 1]) {
			auto itr = bst.upper_bound(b[i - 1]);
			if (itr != bst.end() && *itr < b[i]) {
				correct = false;
				break;
			}
			bst.insert(b[i]);
		}
		else if (b[i] < b[i - 1]) {
			auto itr = bst.lower_bound(b[i - 1]);
			if (itr != bst.begin() && *(--itr) > b[i]) {
				correct = false;
				break;
			}
			bst.insert(b[i]);
		}
	}

	cout << (correct ? "YES" : "NO") << "\n";
	return;
}

int main() {
	int t;
	cin >> t;
	while (t--) {
		solve();
	}
	return 0;
}