#include <bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=j;i<=n;i++)
#define repp(i,j,n) for(int i=n;i>=j;i--)
#define pb push_back
#define in insert
#define ll long long int
#define pii pair<int,int>
#define pip pair<int,pii>
#define pll pair<ll,ll>
#define pib pair<int,bool>
#define p_q priority_queue
#define mp map<int,int>
#define mpl map<ll,ll>
#define inf 1000000005
# define fi first 
# define se second 
#define mod 1000000007
#define vi vector<int>
#define vpi vector<pi>
#define vll vector<ll>
#define qu queue
#define N 1000005
#define BLK 700
#define pi 3.1415926535897932384626433832795
#define lowercase(a) transform(a.begin(), a.end(), a.begin(), ::tolower);
#define uppercase(a) transform(a.begin(), a.end(), a.begin(), ::toupper);
int main()
{
ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;cin>>t;
    while(t--){
        ll n;
        cin>>n;
        ll a[n];
        rep(i,0,n-1) cin>>a[i];
        ll ans = n + n-1;
        int w,x,y,z;
        rep(i,0,n-3){
        x=a[i];y=a[i+1];z=a[i+2];
        if(x>=y && y>=z || x<=y && y<=z){}
        else{ans++;}
        }
        //cout<<ans<<endl;
        rep(i,0,n-4){
        x=a[i];y=a[i+1];z=a[i+2];w=a[i+3];
        if(x>=y && y>=z || x<=y && y<=z || x>=y && y>=w || x<=y && y<=w || y>=z && z>=w || y<=z && z<=w || x>=z && z>=w || x<=z && z<=w){}
        else{ans++;}
        }
        cout<<ans<<endl;
    }
    return 0;
}
