#include<bits/stdc++.h>
#define endl '\n'
#define mt make_tuple
#define pb push_back
#define ff first
#define ss second
#define ALL(v) v.begin(), v.end()


using namespace std;
using ll = long long;
using ld = long double;

const int maxn = 100001;
const ll INF = LLONG_MAX;
const ll mod = 1e9 + 7;

ll POW(ll a, ll b, ll MMM = mod) {ll ret=1; for(;b;b>>=1,a=(a*a)%MMM)if(b&1)ret=(ret*a)% MMM; return ret; }

int n;
vector<int> a;

bool check(int l, int r){
  for(int i = l; i <= r; i++){
    for(int j = i+1; j <= r; j++){
      for(int k = j+1; k <= r; k++){
        if((a[i] <= a[j] && a[j] <= a[k]) || (a[i] >= a[j] && a[j] >= a[k])){
          return false;
        }
      }
    }
  }

  return true;
}  

int go_vishal(){
  cin >> n;
  a = vector<int> (n);
  for(auto &x : a){
    cin >> x;
  }

  
  int j = 0;
  int ans= 0;
  for(int i = 0; i < n; i++){
    while(!check(j, i)){
      j++;
    }
    ans += i - j + 1;
  }

  cout << ans << endl;
  return 0;
}


int main(){
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  int tt;
  tt = 1;
  cin >> tt;
  for(int i = 1; i <= tt; i++){
    // cout << "Case #" << i << ": ";
    go_vishal();
  }
  return 0;
}

