#include <bits/stdc++.h>
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define ninpo ios_base::sync_with_stdio(false);cin.tie(NULL);
#define dbg(x) cout<<#x<<" = "<<(x)<<endl;
#define sz(cntainer) (int)cntainer.size()
#define tc int t;cin>>t;for(int i=0;i<t;++i)
#define ll long long
#define pii pair<int,int>
using namespace std;
int n;vector<ll> v(300005);
int brk[300005];
bool vld(int i)
{
    return ((i>-1 )&&( i<n));
}
bool horv(int i1,int i2, int i3)
{
    if(i1<0 || i3>= n)return false;
    if(v[i2]>v[i1] && v[i2]>v[i3])return true;
    if(v[i2]<v[i1] && v[i2]<v[i3])return true;
    return false;
}
int check(int i)//returns max reducible
{
    int ls=0,t1=0,in=0;
    in=brk[i]+brk[i-1];
    if(i+1<n)
    in=brk[i-1]+brk[i]+brk[i+1];//check
    //rt k eql
    t1+=horv(i-2,i-1,i+1);
    ls=max(ls,in-t1);
    //lft k eql
    t1=horv(i-1,i+1,i+2);
    ls=max(ls,in-t1);
    return ls;
}

void solve()
{
    cin>>n;
    for (int i = 0; i < n; i++)
    {
        cin>>v[i];brk[i]=0;
    }
    int ct=0,d=0,f=0;
    for (int i = 1; i < n-1; i++)
    {
        ct+=brk[i]=horv(i-1,i,i+1);
    }
    int ans=-0;
    for (int i = 1; i < n-1; i++)
    {
        if(brk[i])
        ans=max(ans,check(i));
    }
    cout<<ct-ans<<endl;
}

int main()
{
       #ifndef ONLINE_JUDGE
           freopen("input.txt", "r", stdin);
           freopen("output.txt", "w", stdout);
       #endif
   ninpo;
   tc
    solve();
}