#include<bits/stdc++.h>
#define int long long
#define lld long long double
#define pb push_back
#define mp make_pair
#define M 1000000007
using namespace std;

bool solve(vector<int> v, int n)
{
	set<int> s;
	s.insert(v[0]);
	for (int i = 1; i < v.size(); i++) {
		s.insert(v[i]);
		if (v[i] == v[i - 1])continue;
		else if (v[i] > v[i - 1]) {
			auto c = s.upper_bound(v[i - 1]);
			if (*c != v[i])return false;
		}
		else {
			auto c = s.upper_bound(v[i]);
			if (*c != v[i - 1])return false;
		}
	}
	return true;
}

int32_t main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int t; cin >> t; while (t--)
	{
		int n;
		cin >> n;
		vector<int>v(n);
		for (int i = 0; i < n; i++) cin >> v[i];

		bool ans = solve(v, n);
		if (ans)
			cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}