#include<bits/stdc++.h>
using namespace std ;
int main () 
{
    long long t ; 
    cin >> t ;
    for (long long w =  0 ; w< t ; w++){
        long long n ;
        cin >> n ;
        long long a[n];
        for(long long u = 0; u<= n-1 ; u++){
            cin >> a[u];
        }
        long long ans = n;
        if (n>=2){
            ans += n-1;
        }
        for(long long u = 0 ; u<= n-3; u++){
            int s = 0;
            if((a[u]>=a[u+1]&&a[u+1]>=a[u+2])||(a[u]<=a[u+1]&&a[u+1]<=a[u+2])){
                s++ ;
            }
            if (s==0){
                ans ++ ;
            }
        }
        for (long long u = 0 ; u<= n-4 ; u++){
            int s = 0 ;
            if ((a[u]>=a[u+1]&&a[u+1]>=a[u+2])||(a[u]>=a[u+1]&&a[u+1]>=a[u+3])||(a[u]>=a[u+2]&&a[u+2]>=a[u+3])||(a[u+1]>=a[u+2]&&a[u+2]>=a[u+3])||(a[u]<=a[u+1]&&a[u+1]<=a[u+2])||(a[u]<=a[u+1]&&a[u+1]<=a[u+3])||(a[u]<=a[u+2]&&a[u+2]<=a[u+3])||(a[u+1]<=a[u+2]&&a[u+2]<=a[u+3])){
                s++;
            }
            if (s==0){
                ans ++ ; 
            }
        }
        cout << ans << "\n";
        
    }
}
