#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define ll long long
#define dd double
#define MOD1 1000000007
#define MOD2 998244353
#define nl cout<<endl
#define rt ll Q[100005]={0}
#define mp make_pair
#define test() ll t;cin>>t;while(t--)
#define pb push_back
#define ff first    
#define ss second
#define all(v) v.begin(),v.end()
#define s(ar,n) sort(ar,ar+n)
#define rs(ar,n) sort(ar, ar+n, greater<ll>()) 
#define oa(a,n) for(ll i=0;i<n;i++)cout<<a[i]<<" ";nl
#define cn(a,n) for(ll i=0;i<n;i++)cin>>a[i];
#define ov(a,n) for(ll i=n-1;i>=0;i--)cout<<a[i]<<" ";nl
#define ovp(a,n) for(ll i=0;i<n;i++)cout<<a[i].ff<<" "<<a[i].ss<<endl;
#define maxa(ar,N) *max_element(ar,ar+N)
#define mina(ar,N) *min_element(ar,ar+N)
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef pair<ll,ll> pii;
ll powe(ll n,ll m){if(m==0)return 1;ll t=powe(n,m/2);if(m%2==0)return (t*t);return (((t*t))*n);}
ll mpowe(ll n,ll m,ll MOD){if(m==0)return 1;ll t=mpowe(n,m/2,MOD);t%=MOD;if(m%2==0)return (t*t)%MOD;return (((t*t)%MOD)*n)%MOD;}
ll logtwo(ll n){if(n==1)return 0;if(n==0) return -1;return logtwo(n/2)+1;}
ll check(vector<pair<ll,ll> > &v)
{
    ll flag=1;
    
    for (int i = 0; i < v.size(); ++i)
    {
        for (int j = i+1; j < v.size(); ++j)
        {
            for (int k = j+1; k < v.size(); ++k)
            {
                vector<ll> x(3);
                x[0] = abs(v[i].ff-v[j].ff) + abs(v[i].ss-v[j].ss);
                x[1] = abs(v[i].ff-v[k].ff) + abs(v[i].ss-v[k].ss);
                x[2] = abs(v[k].ff-v[j].ff) + abs(v[k].ss-v[j].ss);
                sort(all(x));
                if(x[2]==x[0]+x[1])
                    flag=0;
            }
        }
    }
    //nl;
    //cout<<flag<<endl;
    return  flag;
}

int main()
{
    fastio();
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    int t=1;
    cin>>t;
    while(t--)
    {
        ll n;
        cin>>n;
        ll a[n];
        cn(a,n);
        ll ans = 0;
        for (int i = 0; i < n; ++i)
        {
            vector<pair<ll,ll>> v;
            int j=i;
            while(j>=0)
            {
                v.pb({a[j],j});
                if(check(v))
                    ans++;
                else
                    break;
                j--;
            }
        }
        cout<<ans<<endl;
    }
    
}