#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
//using namespace __gnu_pbds;
#define rep(i,a,b) for(i=(a);i<=(b);i++)
#define ll long long
#define pll pair<ll, ll>
#define pii pair<int,int>
#define pb push_back
#define F first
#define S second
#define mod 1000000007
#define maxn 100005
#define inf 1e18
#define boost ios::sync_with_stdio(false);cin.tie(0)
#define fr freopen("source.txt","r",stdin),freopen("output.txt","w",stdout)
#define SET(a,b) memset(a,b,sizeof(a))
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define all(x) x.begin(), x.end()
#define ps(x,y) fixed<<setprecision(y)<<x
//template<typename T>
//using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
template<class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a) {
    return out <<  "(" << a.F << ", " << a.S << ")";
}
 
template<class A> ostream& operator << (ostream& out, const vector<A> &a) {
    out << "[";
    for (auto it = a.begin(); it != a.end(); ++it) {
        if (it != a.begin())
            out << ", ";
        out << *it;
    }
    return out << "]";
}
void solve(){
    ll n,i,j,x,t,y;
    cin>>n;
    ll a[n];
    for(i=0;i<n;i++) cin>>a[i];
    ll ans=0;
    vector<ll>v(n,0);
    for(i=1;i<n-1;i++){
        if(a[i]>a[i-1]&&a[i]>a[i+1]){
            v[i]=1;
            ans++;
        }
        else if(a[i]<a[i-1]&&a[i]<a[i+1]){
            v[i]=1;
            ans++;
        }
    }
    if(ans<2){
        cout<<"0\n";
        return;
    }
    ll res=ans;
    for(i=0;i<n-1;i++){
        ll temp=ans;
        ll l=max(1LL,i-5);
        ll r=min(n-2,i+5);
        ll prev=a[i];
        a[i]=a[i+1];
        for(j=l;j<=r;j++){
            if(a[j]>a[j-1]&&a[j]>a[j+1]){
                if(v[j]==0) temp++;
            }
            else if(a[j]<a[j-1]&&a[j]<a[j+1]){
                if(v[j]==0) temp++;
            }
            else if(v[j]==1) temp--;
        }
        res=min(res,temp);
        a[i]=prev;
    }

    for(i=1;i<n;i++){
        ll temp=ans;
        ll l=max(1LL,i-5);
        ll r=min(n-2,i+5);
        ll prev=a[i];
        a[i]=a[i-1];
        for(j=l;j<=r;j++){
            if(a[j]>a[j-1]&&a[j]>a[j+1]){
                if(v[j]==0) temp++;
            }
            else if(a[j]<a[j-1]&&a[j]<a[j+1]){
                if(v[j]==0) temp++;
            }
            else if(v[j]==1) temp--;
        }
        res=min(res,temp);
        a[i]=prev;
    }

    cout<<res<<"\n";
}
int main()
{
    boost;
    ll n,i,j,x,t,y;
    cin>>t;
    while(t--) solve();
}