#include<bits/stdc++.h>		
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> pr;
typedef vector<pair<int,int> > vpr;
typedef vector<vi> vvi;
#define ff first
#define ss second
#define fort(i,m,n) for(int i=m;i<n;i++)
#define fora(arr,n) for(int i=0;i<n;i++) cin>>arr[i];
#define begud(k) cerr<<"\t-->"<<#k<<" = "<<k<<"\n";
#define endl "\n"
#define pb push_back
const int mod = 1e9 + 7;
ll power(ll a,ll b)
{
	if(b==0)
		return 1;
	ll res = power(a,b/2);
	ll ans = res*res;
	ans %= mod;
	if(b%2==0)
		return ans;
	return (a*ans)%mod;
}
bool sortbysec(const pair<int,int> &a,const pair<int,int> &b)                
{
	return (a.second < b.second); 
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);	
	int t;
	cin >> t;
	while(t--)
	{
		int n;
		cin >> n;
		vi b(n);
		fora(b,n);
		bool poss = true;
		set<int> ms;
		ms.insert(b[0]);
		int prev_median = b[0];
		int median;
		fort(i,1,n)
		{
			median = b[i];
			if(median == prev_median)
				continue;
			ms.insert(b[i]);
			if(median > prev_median)
			{
				auto it = ms.find(median);
				if(it != ms.begin())
				{
					it--;
					if(*it != prev_median)
					{
						// begud(*it);
						poss = false;
					}
				}
			}
			else
			{
				auto it = ms.find(median);
				it++;
				if(it != ms.end())
				{
					if(*it != prev_median)
					{
						// begud(*it);
						// begud(i);
						// begud(prev_median);
						poss = false;
					}
				}
			}
			prev_median = median;
		}
		if(poss)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}
    return 0;
}