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

#ifdef LOCAL
#include "bib/debug.h"
#else
#define debug
#define cerr if (false) cerr 
#endif

int score(vector<int> &A, int n, int id) {
  if (id < 1 || id >= n - 1) {
    return 0;
  }
  if (A[id - 1] > A[id] && A[id + 1] > A[id]) {
    return 1;
  }
  if (A[id - 1] < A[id] && A[id + 1] < A[id]) {
    return 1;
  }  
  return 0;
}

void solve(int qq) {
  int n;
  cin >> n;
  vector<int> A(n);
  for (int i = 0; i < n; i++) {
    cin >> A[i];
  }

  int s = 0;
  for (int i = 0; i < n; i++) {
    s += score(A, n, i);
  }
  
  int mx = 0;
  for (int i = 0; i < n; i++) {
    vector<int> V = {A[i]};
    if (i > 0) {
      V.push_back(A[i - 1]);
    }
    if (i + 1 < n) {
      V.push_back(A[i + 1]);
    }    

    int org = -1;
    int mn = 1e9;
    for (auto &c : V) {
      A[i] = c;
      int ch = score(A, n, i);
      if (i > 0) {
        ch += score(A, n, i - 1);
      }
      if (i + 1 < n) {
        ch += score(A, n, i + 1);
      }      
      if (org == -1) org = ch;
      mn = min(mn, ch);
    }
    A[i] = V[0];
    debug(i, org, mn);
    mx = max(mx, org - mn);
  }
  debug(s, mx);
  cout << s - mx << '\n';
}

int32_t main(int32_t argc, char **argv) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);

  int tt, qq = 0;
  cin >> tt;
  while (tt--) {
    solve(++qq);
  }

  return 0;
}
