#include<bits/stdc++.h>
#define forn(i,a,b)for(int i=(a),_b=(b);i<=_b;i++)
#define fore(i,b,a)for(int i=(b),_a=(a);i>=_a;i--)
#define rep(i,n)for(int i=0,_n=n;i<n;i++)
#define ll long long
#define pii pair<int,int>
#define m_p make_pair
#define pb push_back
#define fi first
#define se second
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define int ll
using namespace std;
const int N=200010;
int t;
int n;
int a[N];
bool ok(int x,int y,int z){
	int aa=abs(x-y)+abs(a[x]-a[y]);
	int bb=abs(y-z)+abs(a[y]-a[z]);
	int cc=abs(x-z)+abs(a[x]-a[z]);
	if(aa+bb==cc||aa+cc==bb||bb+cc==aa)return 1;
	return 0;
}
signed main(){
	ios::sync_with_stdio(0);
	cin>>t;
	while(t--){
		cin>>n;
		forn(i,1,n)cin>>a[i];
		if(n==1){
			cout<<1<<"\n";
			continue;
		}
		if(n==2){
			cout<<3<<"\n";
			continue;
		}
		ll ans=3;
		forn(i,3,n){
			ll lm=0;
			bool f=0;
			fore(j,i-2,1){
				if(f)break;
				forn(k,j+1,i-1){
					forn(kk,k+1,i)
					if(ok(kk,j,k)){
						lm=j;
						f=1;
						break;
					}
				}
			}
			ans+=(i-lm);
		}
		cout<<ans<<"\n";
	} 
	return 0;
}