#include <bits/stdc++.h>
#ifdef mlocal
#include "./Competitive-Code-Library/snippets/prettyprint.h"
#endif
using namespace std;
#define for_(i, s, e) for (int i = s; i < (int) e; i++)
#define for__(i, s, e) for (ll i = s; i < e; i++)
typedef long long ll;
typedef vector<int> vi;
typedef array<int, 2> ii;
#define endl '\n'


int main() {
#ifdef mlocal
	freopen("test.in", "r", stdin);
#endif
	
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	const int INF = 2e9;
	int t; cin >> t;
	while (t--) {
		int n; cin >> n;
		vi nums(n);
		for_(i, 0, n) cin >> nums[i];
		set<int> s;
		s.insert(INF); s.insert(-INF); s.insert(nums[0]);
		
		bool valid = true;
		for_(i, 1, n) {
			auto pt = s.lower_bound(nums[i-1]);
			
			if (nums[i] > nums[i-1]) {
				int v = *(next(pt));
				if (nums[i] > v) valid = false;
			}
			else {
				int v = *(prev(pt));
				if (nums[i] < v) valid = false;
			}
			
			s.insert(nums[i]);
		}
		
		cout << (valid ? "YES" : "NO") << endl;
	}
}

