#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define endl '\n'
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define debug(x) cout<<x<<endl;
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define mod 1000000007
map<ll,ll> prime;

ll powerFunction(ll x,ll y)
{
    ll res = 1;
    ll p = mod;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
void sieve(ll n)
{
    for(int i=0;i<=n;i++)
        prime[i]=1;
    prime[0]=0;
    prime[1]=0;
    for (int p=2; p*p<=n; p++)
    {
        if (prime[p])
        {
            for (int i=p*p; i<=n; i += p)
                prime[i] = 0;
        }
    }
}
int hill(int a[], int i, int n)
{
    return (i>0 && i<n-1 && a[i]>a[i-1] && a[i]>a[i+1]);
}
int valley(int a[], int i, int n)
{
    return (i>0 && i<n-1 && a[i]<a[i-1] && a[i]<a[i+1]);
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        int a[n];
        for(int i=0;i<n;i++)
            cin>>a[i];
        int dp[n], cnt=0;
        for(int i=0;i<n;i++)
            dp[i]=0;
        for(int i=1;i<n-1;i++)
        {
            if(hill(a,i,n) || valley(a,i,n))
            {
                dp[i]=1;
                cnt++;
            }
        }
        int ans= cnt;
        for(int i=1;i<n-1;i++)
        {
            int tmp=a[i];
            a[i]=a[i-1];
            ans= min(ans, cnt-dp[i-1]-dp[i]-dp[i+1]+hill(a,i-1,n)+valley(a,i-1,n)+hill(a,i,n)+valley(a,i,n)+hill(a,i+1,n)+valley(a,i+1,n));
            a[i]= a[i+1];
            ans= min(ans, cnt-dp[i-1]-dp[i]-dp[i+1]+hill(a,i-1,n)+valley(a,i-1,n)+hill(a,i,n)+valley(a,i,n)+hill(a,i+1,n)+valley(a,i+1,n));
            a[i]= tmp;
        }
        cout<<ans<<endl;
    }
}
