#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fast ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
const int MOD = 1e9 + 7;

ll n;
vector<ll> a;

bool counter(ll i) {
	if (i >= n - 1 || i < 1)
		return false;
	if ((a[i] > a[i - 1] && a[i] > a[i + 1]) || (a[i] < a[i - 1] && a[i] < a[i + 1])) {
		return true;
	}

	return false;
}


void solve() {
	cin >> n;
	a.resize(n);
	for (ll i = 0 ; i < n; i++)
		cin >> a[i];

	if (n <= 2) {
		cout << 0 << endl;
		return;
	}
	ll count = 0;
	ll maxi = 0;
	for (ll i = 1; i < n - 1; i++)
		if (counter(i))
			count++;

	for (ll i = 1; i < n - 1; i++) {
		ll cp = 0, cn = 0;
		if (counter(i))
			cp++;
		if (counter(i - 1))
			cp++;
		if (counter(i + 1))
			cp++;
		ll temp = a[i];
		a[i] = a[i - 1];
		if (counter(i))
			cn++;
		if (counter(i - 1))
			cn++;
		if (counter(i + 1))
			cn++;
		maxi = max(maxi, abs(cp - cn));
		cn = 0;
		a[i] = a[i + 1];
		if (counter(i))
			cn++;
		if (counter(i - 1))
			cn++;
		if (counter(i + 1))
			cn++;
		a[i] = temp;
		maxi = max(maxi, abs(cp - cn));

	}
	if (count == 0 )cout << 0 << endl;
	else
		cout << count - maxi << endl;
}

int main() {
	fast;
#ifndef ONLINE_JUDGE
	// for getting input from input.txt
	freopen("input1.txt", "r", stdin);
	// for writing output to output.txt
	freopen("output1.txt", "w", stdout);
#endif

	int t;
	cin >> t;
	while (t--) {
		solve();
	}


}