#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define sorta(a) sort(a, a + n)
#define sortv(v) sort(begin(a), end(a))
#define rep(i, j, n) for (int i = j; i < n; i++)

int main()
{
    ll t;
    cin >> t;
    while (t--)
    {
        ll n;
        cin >> n;
        ll a[n];
        ll r = 0;
        rep(i, 0, n)
        {
            cin >> a[i];
        }
        ll tot = 0;
        map<ll, ll> mp, hill, valley;
        rep(i, 1, n - 1)
        {
            if (a[i] > a[i - 1] && a[i] > a[i + 1])
                tot++, hill[i]++;

            if (a[i] < a[i - 1] && a[i] < a[i + 1])
                tot++, valley[i]++;
        }

        ll ans = tot;
        ll minus = 0;

        rep(i, 0, n)
        {
            ll val = a[i];
            minus = 0;
            if (i - 1 >= 0)
            {
                a[i] = a[i - 1];

                rep(j, i - 1, i + 2)
                {
                    if (j >= 1 && j < n - 1)
                    {
                        if (!(a[j] > a[j - 1] && a[j] > a[j + 1]))
                        {
                            if (hill[j])
                                minus++;
                        }
                        else
                            minus--;

                        if (!(a[j] < a[j - 1] && a[j] < a[j + 1]))
                        {
                            if (valley[j])
                                minus++;
                        }
                        else
                            minus--;
                    }
                }

                ans = min(ans, tot - minus);
            }
            minus = 0;
            if (i + 1 < n)
            {
                a[i] = a[i + 1];

                rep(j, i - 1, i + 2)
                {
                    if (j >= 1 && j < n - 1)
                    {
                        if (!(a[j] > a[j - 1] && a[j] > a[j + 1]))
                        {
                            if (hill[j])
                                minus++;
                        }
                        else
                            minus--;

                        if (!(a[j] < a[j - 1] && a[j] < a[j + 1]))
                        {
                            if (valley[j])
                                minus++;
                        }
                        else
                            minus--;
                    }
                }

                ans = min(ans, tot - minus);
            }

            a[i] = val;
        }
        cout << ans << endl;
    }

    return 0;
}