#include <bits/stdc++.h>
using namespace std;
#define int         long long
int mod = 4e5;
vector<int>v(mod);
int n;
int32_t hi(int i){
    if(i>0 && i<n-1 && v[i]>v[i-1] && v[i]>v[i+1])return 1;
    if(i>0 && i<n-1 && v[i]<v[i-1] && v[i]<v[i+1])return 1;
    return 0;
}
int32_t main() {
    int t;
	cin >> t;
    while (t--)
    {
        int i,j=0,var,ans=0;
        cin>>n;
        vector<int>v1(n,0);
        for(i=0;i<n;i++){
            cin>>v[i];
        }
        for(i=1;i<n-1;i++){
            if(hi(i)){
                j++;
                v1[i]=1;
            }
        }
        ans=j;
        for(i=1;i<n-1;i++){
            var=v[i];
            v[i]=v[i-1];
            ans=min(ans,j-v1[i-1]-v1[i]-v1[i+1]+hi(i-1)+hi(i)+hi(i+1));
            v[i]=v[i+1];
            ans=min(ans,j-v1[i-1]-v1[i]-v1[i+1]+hi(i-1)+hi(i)+hi(i+1));
            v[i]=var;
        }
        cout<<ans<<endl;
    }
	return 0;
}