#include<algorithm>
#include<iostream>
#include<sstream>
#include<cstring>
#include<iomanip>
#include<cstdio>
#include<string>
#include<vector>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<set>
#define AC 0
#define endl '\n'
#define PI acos(-1)
#define Please return
#define int long long
using namespace std;
const int N=2e5+7;
const int mod=1e9+7;
const int INF=0x3f3f3f3f;
const double eps=1e-8;
int gcd(int a,int b){return b==0?a:gcd(b,a%b);}
int lcm(int a,int b){return a*b/gcd(a,b);}
int factorials(int a){if(a==0)return 1;return a*factorials(a-1);}
void fastio(){ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);}
int qpow(int a,int b){int ans=1;while(b){if(b&1)ans=ans*a;b>>=1;a=a*a;}return ans;}
int qpow(int a,int b,int m){int ans=1%m;while(b){if(b&1)ans=ans*a%m;b>>=1;a=a*a%m;}return ans;}
int exgcd(int a,int b,int&x,int&y){if(!b){x=1,y=0;return a;}int r=exgcd(b,a%b,x,y);int te=y;y=x-(a/b)*y;x=te;return r;}

int a[N];

int check(int a,int b,int c)
{
    return !(a>=b&&b>=c||a<=b&&b<=c);
}

void solve()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;++i)
    {
        cin>>a[i];
    }
    int ans=2*n-1;
    for(int i=3;i<=n;++i)
    {
        ans+=check(a[i],a[i-1],a[i-2]);
    }
    for(int i=4;i<=n;++i)
    {
        ans+=check(a[i],a[i-1],a[i-2])&&check(a[i],a[i-1],a[i-3])&&check(a[i],a[i-2],a[i-3])&&check(a[i-1],a[i-2],a[i-3]);
    }
    cout<<ans<<endl;
}

signed main()
{
    fastio();
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int t;
    t=1;
    cin>>t;
    while(t--)
    {
        solve();
    }
    Please AC;
}