//I am so vegetable
//#define err
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define FIO ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define all(x) x.begin(),x.end() 
#define POB pop_back
#define PUB push_back
#define IN insert
#define ER erase
#define MP make_pair
#define CT count
#define EP empty()
#define FI first
#define SE second
#define lsi p<<1
#define rsi p<<1|1
#define lson l,m,lsi
#define rson m+1,r,rsi
#define BE 1,n,1
#define _for(type,i,a,b) for(type i = (a);i<(b);++i)
#define _rfor(type,i,a,b) for(type i = (a);i>(b);--i)
#define _sfor(p,st) for(auto &p:st)
#define endl '\n'
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf = 0x3f3f3f3f;
const int MOD = 1e9+7;
const double eps = 1e-6;
const double pi = acos(-1.0);
void debug() { cerr << endl; } template <typename T, typename... Ts> void debug(T x, Ts... y) { cerr << "\033[31m" << x << "\033[0m"; if (sizeof...(y) > 0) cerr << ' '; debug(y...); } template <typename T> void debug(const T& a, int l, int r, char c) { for (int i = l; i <= r; ++i) cerr << "\033[31m" << a[i] << "\033[0m" << (i == r ? '\n' : c); } template <typename T> void debug(vector<T> a) { for (int i = 0; i < (int)a.size(); ++i) cerr << "\033[31m" << a[i] << "\033[31m" << " \n"[i == ((int)a.size() - 1)]; }
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll qpow(ll x, ll y) { ll ans = 1; for (; y > 0; y >>= 1) { if (y & 1)ans *= x; x *= x; }return ans; }
ll qpow(ll x, ll y, int MOD) { ll ans = 1; for (; y > 0; y >>= 1) { if (y & 1)ans = ans*x%MOD; x = x*x%MOD; }return ans; }
void exgcd(ll a,ll b,ll &x,ll &y){
    if(!b){x=1;y=0;return;}
    exgcd(b,a%b,x,y);
    ll X=x;
    x=y; y=X-a/b*y;
}
ll inv(ll x, int mod = MOD) { return qpow(x, mod - 2,mod); }
ll m_m(ll a){ return (a%MOD+MOD)%MOD; }


signed main() {
  //ifstream cin("E:\\acm dream\\in.in");
  //ofstream cout("E:\\acm dream\\out.out");
  FIO;
  #ifdef err
  double be = clock();
  #endif

  int T;cin>>T;
  while(T--){
    int n;cin>>n;
    vector<int>a(n);
    _for(int,i,0,n)cin>>a[i];
    ll ans=2*n-1;
    for(int i=0;i<=n-3;++i){
      int f=1;
      if(a[i]<=a[i+1]&&a[i+1]<=a[i+2])f=0;
      if(a[i]>=a[i+1]&&a[i+1]>=a[i+2])f=0;
      ans+=f;
      //cout<<f;
    }
    //cout<<endl;
    for(int i=0;i<=n-4;++i){
      int f=1;
      for(int j=i;j<=i+3;++j){
        for(int k=j+1;k<=i+3;++k){
          for(int l=k+1;l<=i+3;++l){
            if(a[j]<=a[k]&&a[k]<=a[l])f=0;
            if(a[j]>=a[k]&&a[k]>=a[l])f=0;
          }
        }
      }
      ans+=f;
    }
    cout<<ans<<endl;
  }

  #ifdef err
  double en = clock();
  cout<<"time: "<<fixed<<setprecision(8)<<en-be;
  #endif
  return 0;
}
