#include <bits/stdc++.h>
#define A pair<int,int>
using namespace std;
int t,n,a[200002],ans;
bool check(int x,int y,int z){
	if(x>=y&&y>=z) return 0;
	if(x<=y&&y<=z) return 0;
	return 1;
}
int main(){
	scanf("%d",&t);
	while(t--){
		scanf("%d",&n);
		for(int i=1;i<=n;++i) scanf("%d",&a[i]);
		ans=(n<<1)-1;
		for(int i=1;i<n-1;++i)
			if(check(a[i],a[i+1],a[i+2])) ++ans;
		for(int i=1;i<n-2;++i)
			if(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])) ++ans;
		printf("%d\n",ans);
	}
	return 0;
}