#include<bits/stdc++.h>
#define lowbit(x) ((x)&(-x))
#define mp make_pair
#define num(x) tree[x].num
#define val(x) tree[x].val
#define ls(x) tree[x].ls
#define rs(x) tree[x].rs
#define ch(x,y) tree[x].ch[y]
#define sz(x) tree[x].sz
#define fa(x) tree[x].fa
#define exist(x) !(num(x) == 0 && ls(x) == 0 && rs(x) == 0)
using namespace std;
typedef long long ll;
typedef complex<double> comp;
typedef pair<int,int> paii;
const int inf=1e9+7;
const double eps=1e-8;
const comp I(0, 1);
const double PI=acos(-1);
const double alpha=0.7;
int a[200005];
void solve()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    if(n<=2)
    {
        cout<<"YES"<<'\n';
        return;
    }
    priority_queue<int,vector<int>,less<int> >q1;
    priority_queue<int,vector<int>,greater<int> >q2;
    int val=a[2];
    if(a[2]>a[1])
    {
        q1.push(a[1]);
        q2.push(inf);
    }
    else if(a[2]<a[1])
    {
        q2.push(a[1]);
        q1.push(-inf);
    }
    else
    {
        q1.push(-inf);
        q2.push(inf);
    }
    for(int i=3;i<=n;i++)
    {
        if(a[i]>val)
        {
            if(a[i]<q2.top())
            {
                q1.push(val);
                val=a[i];
                q2.push(inf);
            }
            else if(a[i]>q2.top())
            {
                cout<<"NO"<<'\n';
                return;
            }
            else
            {
                q1.push(val);
                val=a[i];
                q2.pop();
                q2.push(inf);
                q2.push(inf);
            }
        }
        else if(a[i]<val)
        {
           if(a[i]>q1.top())
            {
                q2.push(val);
                val=a[i];
                q1.push(-inf);
            }
            else if(a[i]<q1.top())
            {
                cout<<"NO"<<'\n';
                return;
            }
            else
            {
                q2.push(val);
                val=a[i];
                q1.pop();
                q1.push(-inf);
                q1.push(-inf);
            }
        }
        else
        {
            q1.push(-inf);
            q2.push(inf);
        }
    }
    cout<<"YES"<<'\n';
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}
