#include<bits/stdc++.h>

#define ll long long
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<long long,long long>

#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;

int n;
vector<ll>v;

int base;
int ans;

bool can(int i){
	if(i>0 && i<n-1){
		if(v[i]>v[i-1] && v[i]>v[i+1]) return true;
		if(v[i]<v[i-1] && v[i]<v[i+1]) return true;
	}
	return false;
}

void f(int i,int val){
	int awal=0;
	if(can(i)) awal++;
	if(can(i+1)) awal++;
	if(can(i-1)) awal++;
	
	int tp=v[i];
	v[i]=val;
	int akhir=0;
	if(can(i)) akhir++;
	if(can(i+1)) akhir++;
	if(can(i-1)) akhir++;
	v[i]=tp;
	
	ans=min(ans,base-(awal-akhir));
}

void solve(){
	
	cin>>n;
	v.resize(n);
	for(int i=0;i<n;i++) cin>>v[i];
	
	if(n<=2){
		cout<<0<<endl;
		return;
	}
	
	ans=0;
	for(int i=1;i<n-1;i++){
		if(can(i)) ans++;
	}
	base=ans;
	for(int i=0;i<n;i++){
		if(i-1>=0) f(i,v[i-1]);
		if(i+1<n) f(i,v[i+1]);
	}
	
//	cout<<base<<" "<<ans<<endl;
	cout<<ans<<endl;
}

int main(){
	
	fastio();
	
	int t=1;
	cin>>t;
	
	for(int tt=0;tt<t;tt++){
//		cout<<"Case "<<tt+1<<":\n";solve();
		solve();
	}
	
	return 0;
}