#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define p push
#define pp pop
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define maxe *max_element
#define mine *min_element
#define B begin()
#define E end()
#define rB rbegin()
#define rE rend()
#define L size()
#define C count()
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

typedef long long int ll;
#define V(type) vector<type>
#define PQ(type) priority_queue<type>
#define pll pair<ll, ll>
#define F first
#define S second

#define repl(i, a, b) for(ll i=a;i<b;i++)
#define forrl(i, n) for(ll i=0;i<n;i++)
#define coll(v, n) for(int i = 0; i < n;i++){cin>>v[i];}

#define INF 9223372036854775807
const double delta = 0.0000000001;
const double pi = 3.1415926535;

void FAST() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}

ll powM(ll x, ll y, ll m) {  //returns (a^b)%m ( ^ is exponent )
  ll ans = 1, r = 1;
  x %= m;
  while (r > 0 && r <= y)
  {
    if (r & y)
    {
      ans *= x;
      ans %= m;
    }
    r <<= 1;
    x *= x;
    x %= m;
  }
  return ans;
}
ll gcd(ll a, ll b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a);  
} 

ll lcm(ll a, ll b)
{
    ll x = gcd(a, b);
    ll ans = (a*b)/x;
    return ans;
}
bool IsPrime(long long int n){  // Returns if the passed number is prime or not.
        if (n <= 1)  return false; 
        if (n <= 3)  return true; 
  
        if (n%2 == 0 || n%3 == 0) return false; 
  
        for (ll i=5; i*i<=n; i=i+6) 
            if (n%i == 0 || n%(i+2) == 0) 
               return false; 
  
         return true; 
    }
pair<ll,ll> intersection(pair<ll,ll>x, pair<ll,ll>y)
{
    pair<ll,ll> ans;
    if(x.first<=y.first)
    {
        if(x.second<y.first){
            ans=make_pair(-1,-1);//case of no intesection
            return ans;
        }
        else{
            ans.first=max(x.first,y.first);
            ans.second=min(x.second,y.second);
            return ans;
        }
    }
    else{
        if(y.second<x.first){
            ans=make_pair(-1,-1);//case of no intersection
            return ans;
        }
        else{
            ans.first=max(x.first,y.first);
            ans.second=min(x.second,y.second);
            return ans;
        }
    }
}

ll pal(string str)
{
    string temp = str;
    reverse(temp.begin(), temp.end());

    if(temp == str)
        return 1;

    return 0;
}

int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ll t;
  cin>>t;
  while(t--){
    ll n;cin>>n;
    ll arr[n];for(ll i=0;i<n;i++)cin>>arr[i];
    ll s[n];s[0]=-1,s[n-1]=-1;
    ll ans=0;
    for(ll i=1;i<n-1;i++){
        if(arr[i]>arr[i+1] && arr[i]>arr[i-1]){
            ans++;
            s[i]=1;
        }
        else if(arr[i]<arr[i+1] && arr[i]<arr[i-1]){
            ans++;
            s[i]=1;
        }
        else
            s[i]=0;
    }
    ll maxs=0;
    for(ll i=1;i<n-1;i++){
        if( s[i] ){
            ll t = 0;
            
            ll temp = arr[i-1];
            t++;
            if( s[i-1]==1 )t++;
            if( s[i+1]==1 )t++;
            if(i+2<n && (arr[i+2]-arr[i+1])*(arr[i+1]-temp)<0)
            t--;
            
            maxs = max(t,maxs);
            
            t = 0;
            
            temp = arr[i+1];
            t++;
            if( s[i-1]==1 )t++;
            if( s[i+1]==1 )t++;
            if(i-2>=0 && (arr[i-2]-arr[i-1])*(arr[i-1]-temp)<0)
            t--;
            
            maxs = max(t,maxs);
            
        }
    }
    cout<<ans-maxs<<"\n";
  }
}