#include<bits/stdc++.h>

#define loop(i,a,b) for(long long i=a;i<b;i++)
#define iter(it,v) for(auto it=v.begin();it!=v.end();it++)
#define bloop(i,a,b) for(long long i=a;i>=b;i--)

#define ll long long //data types used often, but you don't want to type them time by time
#define ull unsigned long long
#define ui unsigned int
#define us unsigned short
#define ld long double
#define IOS ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL) //to synchronize the input of cin and scanf
#define INF 1001001001
#define PI 3.1415926535897932384626
//for map, pair
#define mp make_pair
#define fi first
#define se second
//for vectors
#define pb push_back
#define pll pair<ll,ll> 
#define pii pair<int,int>
#define vll vector<ll>
#define vii vector<int>

using namespace std;

ll mod = 1e9 + 7;

//long long modinv[300000];
// multiply and mod
ll facts[1000000];
int mul(ll a, ll b)
{
	return (a*b)%mod;
}
// binary exponentiation
int binexp(ll a, ll b)
{
	if(b == 0)
		return 1;
	ll half = binexp(a, b/2);

	if((b%2) == 0)
		return mul(half, half);
	else
		return mul(a,mul(half, half));

}
// mod inverse if mod is prime
ll mod_inv(ll a)
{
	return binexp(a, mod - 2);
}

struct Node{
	bool value = false;
};

void precompute(map<ll, Node> mp)
{
	loop(i, 1, 10001)
	{
		loop(j, 1, 10001)
		{
			ll temp = i*i*i + j*j*j;
			mp[temp].value = true;
		}
	}

}
int ncr(ll n, ll r)
{
	if(n < r)
		return 0;

	return mul(mul(facts[n], mod_inv(facts[n-r])), mod_inv(facts[r]));
}



int main()
{
	IOS;
	//precompute(mp);

	#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing error to error.text
    freopen("error.txt", "w", stderr);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
	#endif

	int t;
	cin>>t;


	while(t--)
	{
		//do it once more
		//i wont give up
		
		int n;
		cin>>n;
		int arr[n];
		loop(i, 0, n)
		{
			cin>>arr[i];
		}

		int sum = 0;

		loop(i, 1, n-1)
		{
			if(((arr[i]>arr[i-1])&&(arr[i]>arr[i+1]))
				|| ((arr[i]<arr[i-1])&&(arr[i]<arr[i+1])))
				sum++;
		}

		if(n == 3)
		{
			int i = 1;
			if(((arr[i]>arr[i-1])&&(arr[i]>arr[i+1]))
				|| ((arr[i]<arr[i-1])&&(arr[i]<arr[i+1])))
				sum = 0;

			cout<<sum<<endl;
			continue;
		}

		int finsum = sum;
		//cout<<sum<<endl;
		loop(i, 1, n-1)
		{
			int cn1 = 0;
			int cn2 = 0;
			if(i == 1)
			{
				if(((arr[i]>arr[i-1])&&(arr[i]>arr[i+1]))
				|| ((arr[i]<arr[i-1])&&(arr[i]<arr[i+1])))
					cn1++;

				int j = i+1;
				if(((arr[j]>arr[j-1])&&(arr[j]>arr[j+1]))
				|| ((arr[j]<arr[j-1])&&(arr[j]<arr[j+1])))
					cn1++;

				int temp = arr[i];
				arr[i] = arr[j];

				if(((arr[i]>arr[i-1])&&(arr[i]>arr[i+1]))
				|| ((arr[i]<arr[i-1])&&(arr[i]<arr[i+1])))
					cn2++;

				if(((arr[j]>arr[j-1])&&(arr[j]>arr[j+1]))
				|| ((arr[j]<arr[j-1])&&(arr[j]<arr[j+1])))
					cn2++;

				

				if(cn1>cn2)
				{
					finsum = min(finsum, sum - (cn1-cn2));
				}

				arr[i] = temp;
			}
			else if(i == n-2)
			{
				if(((arr[i]>arr[i-1])&&(arr[i]>arr[i+1]))
				|| ((arr[i]<arr[i-1])&&(arr[i]<arr[i+1])))
					cn1++;

				int j = i-1;
				if(((arr[j]>arr[j-1])&&(arr[j]>arr[j+1]))
				|| ((arr[j]<arr[j-1])&&(arr[j]<arr[j+1])))
					cn1++;

				int temp = arr[i];
				arr[i] = arr[j];

				if(((arr[i]>arr[i-1])&&(arr[i]>arr[i+1]))
				|| ((arr[i]<arr[i-1])&&(arr[i]<arr[i+1])))
					cn2++;

				if(((arr[j]>arr[j-1])&&(arr[j]>arr[j+1]))
				|| ((arr[j]<arr[j-1])&&(arr[j]<arr[j+1])))
					cn2++;

				if(cn1>cn2)
				{
					finsum = min(finsum, sum - (cn1-cn2));
				}
				arr[i] = temp;
			}
			else{

				if(((arr[i]>arr[i-1])&&(arr[i]>arr[i+1]))
				|| ((arr[i]<arr[i-1])&&(arr[i]<arr[i+1])))
					cn1++;

				int j = i-1;
				if(((arr[j]>arr[j-1])&&(arr[j]>arr[j+1]))
				|| ((arr[j]<arr[j-1])&&(arr[j]<arr[j+1])))
					cn1++;
				j = i + 1;

				if(((arr[j]>arr[j-1])&&(arr[j]>arr[j+1]))
				|| ((arr[j]<arr[j-1])&&(arr[j]<arr[j+1])))
					cn1++;

				j = i-1;

				int temp = arr[i];
				arr[i] = arr[j];

				if(((arr[i]>arr[i-1])&&(arr[i]>arr[i+1]))
				|| ((arr[i]<arr[i-1])&&(arr[i]<arr[i+1])))
					cn2++;

				if(((arr[j]>arr[j-1])&&(arr[j]>arr[j+1]))
				|| ((arr[j]<arr[j-1])&&(arr[j]<arr[j+1])))
					cn2++;

				j = i + 1;

				if(((arr[j]>arr[j-1])&&(arr[j]>arr[j+1]))
				|| ((arr[j]<arr[j-1])&&(arr[j]<arr[j+1])))
					cn2++;

				//cout<<arr[i]<<endl;
				if(cn1>cn2)
				{
					finsum = min(finsum, sum - (cn1-cn2));
				}

				cn2 = 0;
				j = i + 1;
				arr[i] = arr[j];

				if(((arr[i]>arr[i-1])&&(arr[i]>arr[i+1]))
				|| ((arr[i]<arr[i-1])&&(arr[i]<arr[i+1])))
					cn2++;

				if(((arr[j]>arr[j-1])&&(arr[j]>arr[j+1]))
				|| ((arr[j]<arr[j-1])&&(arr[j]<arr[j+1])))
					cn2++;

				j = i - 1;
				if(((arr[j]>arr[j-1])&&(arr[j]>arr[j+1]))
				|| ((arr[j]<arr[j-1])&&(arr[j]<arr[j+1])))
					cn2++;

				if(cn1>cn2)
				{
					finsum = min(finsum, sum - (cn1-cn2));
				}

				arr[i] = temp;

			}
			//cout<<finsum<<endl;

		}

		cout<<finsum<<endl;

	}
}