#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ss second
#define ff first
#define cw "cw"
#define ccw "ccw"
bool fmjj(const pair<ll,pair<ll,ll>> a,const pair<ll,pair<ll,ll>> b)
{
        if(a.ff==b.ff)
       {
                return a.ss.ff<b.ss.ff;
        }
        else
        return a.ff>b.ff;
}
ll gcd(ll a,ll b)
{
        if(a==0)
        return b;
        return gcd(b%a,a);
}                        
  ll aa[10][10];      
int main(void)
{
        ll t;
        t=1;
        cin>>t;
          
        while(t--)
        {
        ll n,i,j,b;
        vector<ll> z,w;
        ll a[200005]={0};
        cin>>n;
        string s;
        for(i=0;i<n;i++)
        {
                cin>>b;
                z.push_back(b);
                w.push_back(b);
                s+='0';
        }
        ll x=0;
        for(i=1;i<z.size()-1;i++)
        {
              if(z[i]>z[i-1] && z[i]>z[i+1])
              {
              s[i]='H';
              x++;
              }
              if(z[i]<z[i-1] && z[i]<z[i+1])
              {
              s[i]='V';
              x++;
              }
        }
        //cout<<x<<endl;
        /*s+="00";
        ll c=0;
        for(i=0;i<n;i++)
        {
                ll p=1,q=2,r=3;
           if(s[i]=='H' && s[i+1]=='V' && s[i+2]=='H')
           c=max(c,r); 
           if(s[i]=='V' && s[i+1]=='H' && s[i+2]=='V')
           c=max(c,r);
           if((s[i]=='H' && s[i+1]=='V') ||  (s[i]=='V' && s[i+1]=='H'))
           c=max(c,q);
           if(s[i]=='H' || s[i]=='V')
           c=max(c,p);
        }
        cout<<s<<endl;
        ll p=0;
        cout<<max(x-c,p)<<endl;  */
        ll xx=x;
        for(i=1;i<z.size()-1;i++)
        {
               
                     w[i]=w[i-1];
                    j=i-1;
                     ll pp=0,xp=0;
                     for(ll p=j;p<=i+1;p++)
                     {
                                if(p==0 || p==n-1)
                                continue;
                               if(s[p]!='0')
                               pp++;
                               if(w[p]>w[p-1] && w[p]>w[p+1])
                               xp++;
                               if(w[p]<w[p-1] && w[p]<w[p+1])
                               xp++;
                    } 
                    for(ll p=j;p<i+1;p++)
                    w[p]=z[p];
                    if(xp<pp)
                    x=min(x,xx-(pp-xp));
                    //cout<<i<<" "<<pp<<" "<<xp<<endl;
                    w[i]=w[i+1];
                        j=i-1;
                      pp=0,xp=0;
                     for(ll p=j;p<=i+1;p++)
                     {
                                 if(p==0 || p==n-1)
                                continue;
                               if(s[p]!='0')
                               pp++;
                               if(w[p]>w[p-1] && w[p]>w[p+1])
                               xp++;
                               if(w[p]<w[p-1] && w[p]<w[p+1])
                               xp++;
                    } 
                    if(xp<pp)
                    x=min(x,xx-(pp-xp));
                    for(ll p=j;p<i+1;p++)
                    w[p]=z[p];
                   // cout<<i<<" "<<pp<<" "<<xp<<endl;
              
        }            
           cout<<x<<endl;         
                              
                               
                     
                        
           
                               
        
                
        
        
        
        
        }
                              
   
   
     
           
 }
               
                                                    
               
      
                            
                                         
                
       
                        
                        
                                 
                   
 // cout<<ss<<endl;
 
                    
                                                          
                                                         
                                                      
                                        
                                       
                                                                   
                                                            
                                        
                                          
                                                                        
                                
                             
                                                                              
                                              
                                                
                                
                                
                                
                                                    
                                                
                                                                                 
                                                               
                                