//COYG
#include <bits/stdc++.h>
using namespace std;
#define ll 		long long
#define mod 	1000000007//998244353
#define mp 		make_pair
#define pb 		push_back
#define vi 		vector<int>
#define vl 		vector<ll>
#define pii 		pair<int,int>
#define pll 		pair<ll,ll>
#define vpi 		vector<pair<int,int> >
#define vpl		vector<pair<ll,ll> >
#define vvi 		vector<vector<int> >
#define vvl 		vector<vector<ll> >
#define ff 		first
#define ss 		second
#define FOREACH(i,t) 	for (auto i=t.begin(); i!=t.end(); i++)
#define all(x)		(x).begin(),(x).end()
#define forn(x,n) for(int x=0;x<n;x++)
int n;vector<int> a;
int chk(int x)
{
    if(x==0||x==n-1)return 0;
    if(a[x]>a[x+1]&&a[x]>a[x-1])return 1;
    if(a[x]<a[x+1]&&a[x]<a[x-1])return 1;
    return 0;
}
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    int zz=1;
    cin>>zz;
    for(int zzz=1;zzz<=zz;zzz++)
    {
        //cout<<"Case #"<<zzz<<": ";
        cin>>n;a.clear();
        forn(i,n){int tmp;cin>>tmp;a.pb(tmp);}
        int ans=0;vector<int> h(n);
        for(int i=0;i<n;i++)
        {
            if(chk(i)){++ans;h[i]=1;}
        }
        int ret=ans;
        for(int i=1;i<n-1;i++)
        {
            if(h[i]==0)continue;
            int fuckinghell=a[i];
            a[i]=a[i-1];
            ret=min(ret,ans-(h[i-1]+h[i]+h[i+1])+(chk(i-1)+chk(i)+chk(i+1)));
            a[i]=a[i+1];
            ret=min(ret,ans-(h[i-1]+h[i]+h[i+1])+(chk(i-1)+chk(i)+chk(i+1)));
            a[i]=fuckinghell;
        }
        cout<<ret<<endl;
    }
    return 0;
}

