#include<bits/stdc++.h>
//#include <ext/pb_ds/;assoc_container.hpp>
//using namespace __gnu_pbds
using namespace std;
# define lint           long long 
#define lint             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<lint,lint>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountlint(x)
#define zrobits(x)      __builtin_ctzlint(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define t(x)            int x=1; cin>>x; while(x--)
#define fori(i,n)        for(lint i=0;i<n;i++)
#define fo(k,i,n)        for(lint i=k;i<n;i++)
 
void c_p_c()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
 
lint calc(int a,int b)
{
    if(a%b==0)
        return a/b;
    else
        return a/b +1;
}
 
unsigned long long power(unsigned long long x,
                                  int y, int p)
{
    unsigned long long res = 1; // Initialize result
 
    x = x % p; // Update x if it is more than or
    // equal to p
 
    while (y > 0)
    {
     
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res * x) % p;
 
        // y must be even now
        y = y >> 1; // y = y/2
        x = (x * x) % p;
    }
    return res;
}
 
// Returns n^(-1) mod p
unsigned long long modInverse(unsigned long long n, 
                                            int p)
{
    return power(n, p - 2, p);
}
 
// Returns nCr % p using Fermat's little
// theorem.
long long fac[100001];
 
void solve()
{
    
fac[0] = 1;
    for (int i = 1; i <= 100000; i++)
        fac[i] = (fac[i - 1] * i) % mod;
}
 
unsigned long long nCrModPFermat(unsigned long long n,
                                 int r, int p)
{
    // If n<r, then nCr should return 0
    if (n < r)
        return 0;
    // Base case
    if (r == 0)
        return 1;
 
    // Fill factorial array so that we
    // can find all factorial of r, n
    // and n-r
 
    return (fac[n] * modInverse(fac[r], p) % p
            * modInverse(fac[n - r], p) % p)
           % p;
}



int main()
{
  c_p_c();
      
      t(x)
      {
        
        lint n;
        cin>>n;
        lint arr[n];
        fori(i,n)
        {
            cin>>arr[i];
        }

        set<lint> s;
        s.insert(arr[0]);
        bool f=true;

        for(int i=1;i<n;i++)
        {
            int a=arr[i-1];

            if(a>arr[i])
            {
                auto itr=s.lower_bound(a);

                if(itr!=s.begin() && *(--itr)>arr[i])
                {
                    f=false;
                    break;
                }
            }
            else if(a<arr[i])
            {
                 auto itr=s.upper_bound(a);

                 if(itr!=s.end() && *itr<arr[i])
                 {
                    f=false;
                    break;
                 }
            }

            s.insert(arr[i]);
        }

        if(f)
            cout<<"YES"<<endl;
        else
            cout<<"NO"<<endl;
      
      }

  return 0;
    
}