#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <stack>

using namespace std;
typedef long long ll;
const int MAXN = 3e5 + 300;
int a[MAXN], n, t;
bool flag[MAXN];

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

int main()
{
	cin >> t;
	while ( t-- ) {
		memset(flag, 0, sizeof(flag));
		ll res = 0;
		ll sum = 0;
		cin >> n;
		for (int i = 0; i < n; i ++ ) cin >> a[i];

		for (int i = 1; i < n - 1; i ++ ) {
			if ( flag[i] = is(i) ) sum ++;
		}

		flag[0] = 0;
		flag[n - 1] = 0;
		res = sum;
		for (int i = 1; i < n - 1; i ++ ) {
			int t = a[i];

			a[i] = a[i - 1];
			res = min(res, sum - flag[i - 1] - flag[i] - flag[i + 1] + is(i - 1) + is(i) + is(i + 1));

			a[i] = a[i + 1];
			res = min(res, sum - flag[i - 1] - flag[i] - flag[i + 1] + is(i - 1) + is(i) + is(i + 1));

			a[i] = t;
		}

		cout << res << endl;
	}
	
	return 0;
}