#include<iostream>
#include<stdio.h>
#include<cmath>
#include<cstring>
#include<set>
#include<vector>
#include<map>
#include<unordered_map>
#include<algorithm>
#include<sstream>
#include<climits>
#include<utility>
#define fast ios::sync_with_stdio(false);cin.tie(0);
#define MX 1000000000
#define MOD 1000000007
#define fs first
#define sec second
#define vint vector<int>
#define vlong vector<ll>
#define pint pair<int,int>
#define vpint vector<pint >
#define vplong vector<pair<ll,ll> >
#define TEST_CASE int T,number = 0;cin>>T;while(T--){number++;solve(number);}
#define loop(i,a,b) for(int i=a;i<b;i++)
#define loop1(i,a) for(int i=1;i<=a;i++)
#define pb(a) push_back(a)
#define ins insert
#define all(a) (a).begin(), (a).end()
#define mp(x, y) make_pair((x), (y))
#define iter(c) typeof(c.begin())
#define foreach(it, c) for(iter(c) it = c.begin(); it != c.end(); it++)
#define ivec(a,n) vint a(n);loop(i,0,n) cin>>a[i];
#define iarr(a,n) int a[n];loop(i,0,n) cin>>a[i];
#define iset(s,n) set<int> s;loop(i,0,n){int x;cin>>x;s.ins(x);}
#define illvec(a,n) vlong a(n);loop(i,0,n) cin>>a[i];
#define illarr(a,n) ll a[n];loop(i,0,n) cin>>a[i];
#define illset(a,n) set<ll> a;loop(i,0,n) {int x;cin>>x;s.in(x);}
 
typedef long long ll;
 
using namespace std;
 
ll binpow(ll a,ll b)
{
    ll exp = 1000000007;
    a%=exp;
    ll res = 1;
    while (b > 0)
    {
        if (b & 1)
            res = ((res) * (a))%exp;
        a = ((a) * (a))%exp;
        b >>= 1;
    }
    return res;
}
 
bool isprime(ll x) {
    for (ll d = 2; d * d <= x; d++) {
        if (x % d == 0)
            return false;
    }
    return true;
}
 
unsigned int countsb(unsigned int n)
{
    unsigned int count = 0;
    while (n) {
        count += n & 1;
        n >>= 1;
    }
    return count;
}

int LCSubStr(string X, string Y, int m, int n)
{
    int LCSufs[m + 1][n + 1];
    int result = 0; 
    for (int i = 0; i <= m; i++)
    {
        for (int j = 0; j <= n; j++)
        {
            if (i == 0 || j == 0)
                LCSufs[i][j] = 0;
 
            else if (X[i - 1] == Y[j - 1]) {
                LCSufs[i][j] = LCSufs[i - 1][j - 1] + 1;
                result = max(result, LCSufs[i][j]);
            }
            else
                LCSufs[i][j] = 0;
        }
    }
    return result;
}

void solve(int cas)
{
    //cout<<"Case #"<<cas<<": ";
    int n;
    cin>>n;
    ivec(a,n);
    int ans = 0;
    loop(i,0,n)
    {
        loop(j,i,n)
        {
            if(i+2 <= j)
            {
                bool val = 1;
                loop(i1,i,j)
                {
                    loop(i2,i1+1,j)
                    {
                        if((a[i1]>=a[i2] && a[i2]>=a[j]) || (a[i1]<=a[i2] && a[i2]<=a[j])) val = 0;
                    }
                }
                if(!val) break;
            }
            ans++;
        }
    }
    cout<<ans<<"\n";
}

int main()
{
    fast
    TEST_CASE
    return 0;
}