#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
const ll mod = 1e9+7;
const ll N = 1e6 + 100;
ll spf[N];
vector<ll>V;

void sieve()
{
     bool prime[N + 1];
    memset(prime, true, sizeof(prime));
 
    for (ll p = 2; p * p <= N; p++)
    {
        // If prime[p] is not changed,
        // then it is a prime
        if (prime[p] == true)
        {
            // Update all multiples
            // of p greater than or
            // equal to the square of it
            // numbers which are multiple
            // of p and are less than p^2
            // are already been marked.
            for (int i = p * p; i <= N; i += p)
                prime[i] = false;
        }
    }
 
    // Print all prime numbers
    for (ll p = 2; p <= N; p++)
        if (prime[p])
            V.push_back(p);
}

ll gcd(ll a, ll b)
{
    if(b == 0)
    {
        return a;
    }

    return gcd(b,a%b);
}

void setting()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif 

}
/*---------------------------------------------------------------------------------------------------------------------------*/


int main()
{
    setting();
    ll t;
    cin >> t;

    while(t--)
    {
        ll n,i,j;
        cin >> n;
        ll a[n];

        for(i=0; i<n; i++)
        {
            cin >> a[i];
        }

        ll ans = 2*n-1;


        for(i=0; i<=n-3; i++)
        {
            if(a[i+1] > a[i] && a[i+1] > a[i+2])
            {
                ans++;
            }
            else if(a[i+1] < a[i] && a[i+1] < a[i+2])
            {
                ans++;
            }
        }

        for(i=0; i<=n-4; i++)
        {
            if(a[i] < a[i+1] && a[i+2] < a[i] && a[i+3] > a[i+2] && a[i+3] < a[i+1])
            {
                ans++;
            }
            else if(a[i] > a[i+1] && a[i+2] > a[i] && a[i+3] < a[i+2] && a[i+3] > a[i+1])
            {
                ans++;
            }
        }

        cout << ans << endl;
    }
}