#include<bits/stdc++.h>
#define fr(i,a,b) for(i = a ; i <= b ; ++i)
#define rf(i,a,b) for(i = a ; i >=b ; i--)
using namespace std;
vector <int>  a(300005,0);
int i , j , n, t;
int fun(int i)
{
	if(i == 1 || i == n)
		return 0;
	
	return ((a[i+1]>a[i] && a[i-1]>a[i]) || (a[i+1]<a[i] && a[i-1]<a[i]));

}

int main()
{

	cin >> t;
	while(t--)
	{


		cin >> n;
		fr(i,1,n)
			cin >> a[i];
		int cnt = 0;
		fr(i,1,n)
		{
			if(fun(i))
				cnt++;
		}

		int ans = cnt;
		int best = 0, cost;
		fr(i,2,n-1)
		{
			int val = a[i];
			cost = fun(i-1)+fun(i)+fun(i+1);
			a[i] = a[i-1];
			best = max(best, cost - (fun(i-1)+fun(i)+fun(i+1)));
			a[i] = a[i+1];
			best = max(best, cost - (fun(i-1)+fun(i)+fun(i+1)));
			a[i] = val;
		
		}
		
		cout << ans-best << "\n";


	}

	return 0;

}