#include<bits/stdc++.h>
using namespace std;
int arr[200000];
bool check(int a,int b,int c){
	if(a<=b && b<=c)
		return false;
	if(a>=b && b>=c)
		return false;
	return true;
}
void solve(){
	int n,i,answer,i1,i2,i3;
	bool ok;
	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%d",&arr[i]);
	answer=n+n-1;
	for(i=0;i<n-2;i++)
		if(check(arr[i],arr[i+1],arr[i+2]))
			answer++;
	for(i=0;i<n-3;i++){
		ok=true;
		for(i1=0;i1<4;i1++)
			for(i2=i1+1;i2<4;i2++)
				for(i3=i2+1;i3<4;i3++)
					if(!check(arr[i+i1],arr[i+i2],arr[i+i3]))
						ok=false;
		if(ok)
			answer++;
	}
	printf("%d\n",answer);
}
int main(){
	int t,i;
	scanf("%d",&t);
	for(i=0;i<t;i++)
		solve();
	return 0;
}
