#include<bits/stdc++.h>
#include <algorithm>
using namespace std;
     
//Author: Udhav Gupta(@SimplyDifficult)
     
#define fo(i,n) for(int i=0;i<n;i++)
#define fo1(i,n) for(int i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define int long long
#define vi vector<int>
#define all(v) (v).begin(), (v).end()
const int N=3e5+10;
int mod=1000000007;
const int inf=1e9+1;
     
     
int power(int a,int b) {int ans=1; while(b){if(b&1)ans=(ans*a)%mod;b/=2;a=(a*a)%mod;}return ans;}
int bit(int n){if(n==0)return 0;int k=1,b=0;while((n/k)!=0){k*=2;b++;}return b-1;}
     
int n,t,k,m,x,y,z,flag=1;
string s;

vi a(N); 

int ishill(int i){
    if(i>0 && i<n-1 && a[i]>a[i-1] && a[i]>a[i+1])return 1;
    else return 0;
}

int isvalley(int i){
    if(i>0 && i<n-1 && a[i]<a[i-1] && a[i]<a[i+1])return 1;
    else return 0;
}

int32_t main(){
     
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin>>t;
    while(t--){
        cin>>n;
        
        fo(i,n)cin>>a[i];
        int cnt=0;
        vi p(n,0);
        for(int i=1;i<n-1;i++){
            if(isvalley(i)){cnt++;p[i]=1;}
            else if(ishill(i)){cnt++;p[i]=1;}
        }
        
        int ans=cnt;
        for(int i=1;i<n-1;i++){
            int tmp=a[i];
            a[i]=a[i-1];
            ans=min(ans,cnt-p[i-1]-p[i]-p[i+1]+ishill(i-1)+ishill(i)+ishill(i+1)+isvalley(i-1)+isvalley(i)+isvalley(i+1));
            a[i]=a[i+1];
            ans=min(ans,cnt-p[i-1]-p[i]-p[i+1]+ishill(i-1)+ishill(i)+ishill(i+1)+isvalley(i-1)+isvalley(i)+isvalley(i+1));
            a[i]=tmp;
        }
        cout<<ans<<endl;
    }
        
     
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
    return 0;
}