#include<bits/stdc++.h>
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define debug freopen("1.in", "r", stdin), freopen("1.out", "w", stdout)
#define mem(a,b) memset(a,b,sizeof(a))
#define inv(a,p) fpow(a,p-2,p)
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define pw(a) (1LL<<a)
#define ls(a) (a<<1LL)
#define rs(a) (a<<1LL|1LL)
#define make make_pair
#define PP push_back
#define x first
#define y second
using namespace std;
 
typedef long long LL;
typedef double DD;
typedef bool BB;
typedef pair<string,LL> PAIR;
 
const LL INF=1e18;
const LL mod=1e9+7;
const LL N=2e5+10;
 
LL n,m,k,T,cnt,ans,sum;
LL arr[N];
LL check(LL x)
{
    if((arr[x-1]>arr[x])&&(arr[x+1]>arr[x])||(arr[x-1]<arr[x])&&(arr[x+1]<arr[x])) return 1;
    else return 0;
}
LL ok(LL x,LL y,LL z)
{
    if((x>z&&x<y)||(x<z&&x>y)) return 1;
    return 0;
}
LL gcd(LL a,LL b){return (b==0)?a:gcd(b,a%b);}
int main(void)
{
    scanf("%lld",&T);
    while(T--)
    {
        scanf("%lld",&n);
        for(LL i=1;i<=n;i++) scanf("%lld",&arr[i]);
        ans=n+n-1;
        for(LL i=2;i<=n-1;i++)
        {
            if(!check(i)) continue;
            if(i==n-1)
            {
                ans++;
                continue;
            }
            if(check(i+1))
            {
                if(ok(arr[i-1],arr[i],arr[i+1])&&ok(arr[i+2],arr[i+1],arr[i]))
                {
                    i++;
                    ans+=3;
                } 
                else ans++;
            }
            else ans++;
        }
        cout<<ans<<endl;
    }
    // system("pause");
    return 0;
}