#include <bits/stdc++.h>
    using namespace std;
     
    #define ll long long
    #define ft first
    #define sd second
    #define pb push_back
    #define all(v) v.begin(),v.end()
    #define mset(a,b) memset(a, b, sizeof(a))
    #define mp make_pair
    #define ins(p) insert(p)
    #define vi vector<int>
    #define vvi vector<vi>
    #define vll vector<ll int>
    #define vvll vector<vll>
    #define loop(i,j,n) for(ll i=j; i<n; i++)
    #define loopto(i,j,n) for(ll i=j; i<=n; i++)
    #define yup cout<<"YES\n"
    #define nope cout<<"NO\n"
     
    bool hill(vll &vec,ll i)
    {
        if(i>0&&i<vec.size()-1)
        {
            return (vec[i]>vec[i-1])&&(vec[i]>vec[i+1]);
        }

        return false;
    }

    bool valley(vll &vec,ll i)
    {
        if(i>0&&i<vec.size()-1)
        {
            return (vec[i]<vec[i-1])&&(vec[i]<vec[i+1]);
        }
        return false;
    }
     
    int manipulate(vll &vec,int i,ll replace)
    {
        ll start, end;
        
        
            start=hill(vec,i-1)+hill(vec,i)+hill(vec,i+1)+valley(vec,i-1)+valley(vec,i)+valley(vec,i+1);

            ll temp=vec[i];
            vec[i]=replace;
            end=hill(vec,i-1)+hill(vec,i)+hill(vec,i+1)+valley(vec,i-1)+valley(vec,i)+valley(vec,i+1);

            vec[i]=temp;

            return end-start;
    } 
    void solve(){
    	ll n,x; cin>>n;

        

        vll vec(n);

        ll i;
        for(i=0;i<n;i++)
        {
            cin>>vec[i];
        }
       
         ll ans=0;
         ll temp;
        ll minm=0;
        int count=0;
        

        for(i=1;i<n-1;i++)
        {  
            if(hill(vec,i)||valley(vec,i))
            ans++;
            
            temp=min(manipulate(vec,i,vec[i-1]),manipulate(vec,i,vec[i+1]));
            if(temp<minm)
            minm=temp;
            
        }

        ans=ans+minm;

       
        cout<<ans<<endl;
    	
    }
     
    int main() {
        ios_base::sync_with_stdio(0);
        cin.tie(0); cout.tie(0);
        
        int t=1;
        cin>>t;
        while(t--){
        	solve();
    	}
    	return 0;
    }