#include<bits/stdc++.h>
using namespace std;




int main()
{
   
   
   
   
    long long t;cin>>t;
    
    
    
    while(t--)
        
    {
        
        
        
        
    long long n;cin>>n;
    
    bool lool=true;
    long long has[n+991];
    
    
    for(long long i=0;i<n;i++)
        ///in elements
        cin>>has[i];
        
set<long long> s;



    long long qwe=has[0];
    
    
    
    
    s.insert(has[0]);
    
    
    
    for(long long i=1;i<n;i++)
    {if(has[i]==qwe && 1==1)
            /// go on
            continue;
        
        
        
        else if(has[i]>qwe && 1==1)
            {auto lo=s.upper_bound(qwe);
            
            ///check if s 0
            if(lo==s.end())
                  
                  
                  
                  s.insert(has[i]);
            
            else
                /// recheck here
                {if(*lo<has[i])
                {lool=false;
                    break;}
                else
                    s.insert(has[i]);}}
                    
                    
                    /// other wise 2
                    
        else
            
            
            
            {auto lo=s.lower_bound(qwe);
            if(lo==s.begin()){
                s.insert(has[i]);}
                
                
           
           
            else
                
                
            
            
            {
                
                    
                lo--;
                if(*lo>has[i] && 1==1)
                    {lool=false;
                ///out
                    break;}
                
                
                
                else
                    
                    
                    s.insert(has[i]);}}
        qwe=has[i];}
        
        
        
        
        
    if(lool>0 && 1==1)
        cout<<"YES"<<endl;
    
    else
        
        
        cout<<"NO"<<endl;}

        
        
        
      return 0;  
        
    }
        
        /// Lool
        
        
        
        
        /*
 
#include<bits/stdc++.h>
 
using namespace std;
 
 
 
 
int main()
{
 
    int  t;cin>>t;
    while(t--)
    
    
        {
        
        
        
        
    long long n;cin>>n;
    
    vector<long long> has(n+991);
    set<long long>lol;
    
    
    
    
    for(long long i=0;i<n;i++)
        {cin>>has[i];
        lol.insert(has[i]);}
        
        
    queue<long long>jeme;
    
    
    for(long long i=1;i<n;i++)
    {for(long long j=0;j<i;j++)     {jeme.push(abs(has[i]-has[j]));}}
            
    while(!jeme.empty() && lol.size()<=300){
        long long lool=jeme.front();
        jeme.pop();
        
        
        if(lol.count(lool))
            continue;
        
        for(long long i=0;i<has.size();i++)
            jeme.push(abs(lool-has[i]));
            
            
        has.push_back(lool);
        lol.insert(lool);}
        
        
        
    if(lol.size()<=300)
        {cout<<"YES"<<endl;
        
        
        
        cout<<lol.size()<<endl;
        
        
        for(auto h1:lol)
            cout<<h1<<" ";
        
        cout<<endl;}
        
        
    else   cout<<"NO"<<endl;}
        
       
    return 0;
}
 
*/
        
        
        
        
        
        
        
        
        
        
    
