#include<bits/stdc++.h>
using namespace std;
vector<long long>a;
long long f(long long i)
{
    if(i==0||i==a.size()-1) return 0;
    else if((a[i]>a[i-1]&&a[i]>a[i+1])||(a[i]<a[i-1]&&a[i]<a[i+1])) return 1;
    return 0;
}
int main()
{
    //ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
    long long t=1,n,i,j,k,val,m,d,p,q,ans;
    cin>>t;
    while(t--)
    {
        cin>>n; k=0; j=-1; m=1; d=1; ans=1e12;
        a.resize(n);
        for(auto &x:a) cin>>x;
        if(n>3)
        {
            for(i=0;i<n;i++) k+=f(i);
            ans=k;
            for(i=1;i<n-1;i++)
            {
                m=k;
                val=a[i];
                p=f(i-1)+f(i)+f(i+1);
                m-=p;
                a[i]=a[i-1];
                q=f(i-1)+f(i)+f(i+1);
                m+=q;
                ans=min(ans,m);
                m-=q;
                a[i]=a[i+1];
                q=f(i-1)+f(i)+f(i+1);
                m+=q;
                ans=min(ans,m);
                m-=q;
                m+=q;
                a[i]=val;
            }
            cout<<ans<<'\n';
        }
        else cout<<0<<'\n';        
    }
    return 0;
}