#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <map>
#include <cstdio>
#include <stack>
#include <set>
#include <climits>
#include <utility>
#pragma GCC optimize("O3")
#pragma GCC optimize("-Ofast", "-funroll-all-loops", "-ffast-math")
#pragma GCC target("avx2,fma")
#pragma GCC optimize("unroll-loops")
using namespace std;
#define endl '\n'
#define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define bug system("pause")
#define re(i, a, b) for (int i = a; i <= b; i++)
#define rre(i, a) for (int i = 0; i < a; i++)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
const int N = 5e5 + 10;
const int M = 2e5 + 10;
const int inf = 0x3f3f3f3f;
const int mod = 998244353;
const double eps = 1e-6;
const double pi = acos(-1.0);
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

map<int, int> mp;
int a[N];
int t, n;

int main()
{
	IOS;
	cin >> t;
	while (t--)
	{
		mp.clear();
		cin >> n;
		for (int i = 0; i < n; i++)
			cin >> a[i];
		int l = -1e9 - 1, r = 1e9 + 1, mid = a[0];
		bool flag = 1;
		mp[mid] = 1;
		for (int i = 1; i < n; i++)
		{
			map<int, int>::iterator it = mp.find(mid);
			if (it == mp.begin())
				l = -1e9 - 1;
			else
				l = (--it)->first;
			it = mp.find(mid);
			if ((++it) == mp.end())
				r = 1e9 + 1;
			else
				r = it->first;
			mid = a[i];
			mp[mid] = 1;
			if (l > a[i] || a[i] > r)
			{
				flag = 0;
				break;
			}
		}
		cout << (flag ? "YES\n" : "NO\n");
	}
	return 0;
}