#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mp make_pair
#define pb push_back
#define f first

int mod = 1000000007;
ll binpow(ll a, ll b)
{
    ll res = 1;
    while(b>0)
    {
        if(b&1)
        res = (res*a)%mod;
        a = (a*a)%mod;
        b>>=1;
    }
    return res;
}

bool soll (int a, int b, int c, int d)
{
    if(a>=b && b>=c)
        return 0;
    if(a<=b && b<=c)
        return 0;
    if(a<=c && c<=d)
        return 0;
    if(a >= c && c >= d)
        return 0;
    if(a <=b && b<=d)
        return 0;
    if(a >= b && b>=d)
        return 0;
    if(b <=c && c<=d)
        return 0;
    if(b>=c && c>=d)
        return 0;
    return 1;
}

bool soll(int a, int b, int c)
{
    if(a>=b && b>=c)
        return 0;
    if(a<=b && b<=c)
        return 0;
    return 1;
}

void solve()
{
    int n;
    cin>>n;
    vector<int>a(n);
    for(int i=0; i<n; ++i)
        cin>>a[i];
    if(n == 1){
        cout<<1<<endl;
        return;
    }
    if(n == 2)
    {
        cout<<3<<endl;
        return;
    }
    if(n == 3)
    {
        if(soll(a[0], a[1], a[2]))
        {
            cout<<6<<endl;
        }
        else {
            cout<<5<<endl;
        }
        return;
    }
    int count = n+(n-1);
    for(int i=2; i<n; ++i)
    {
        if(soll(a[i-2], a[i-1], a[i]))
            ++count;
    }
    for(int i=3; i<n; ++i)
    {
        if(soll(a[i-3], a[i-2], a[i-1], a[i]))
            ++count;
    }
    cout<<count<<endl;
    return;
}
 
int32_t main() {
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
#endif
    ll t;cin>>t;
    while(t--){
        solve();
    }
    return 0;
}
