#include<bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define precise(num,by) cout<<fixed<<setprecision(by)<<num<<" ";
#define int long long
#define mod 1000000007
#define mod2 998244353
#define fir first
#define sec second
#define all(v) v.begin(),v.end()
#define vil vector<long long int>
#define vi vector<int>
#define vi2 vector<vector<int>>
#define vb vector<bool>
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define ub(x) upper_bound(x)
#define lb(x) lower_bound(x)
#define pil pair<long,long>
#define minheap priority_queue<int,vector<int>,greater<int>>// min at top
#define minheap2 priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>>// min at top
#define print(x) cout<<((x==1)?"YES":"NO")<<endl;
#define vin(n,arr) for(int i=0;i<n;i++)cin>>arr[i];
#define vinmp(n,arr,mp) for(int i=0;i<n;i++){int temp;cin>>temp;arr[i]=temp;mp[temp]++;}
#define input1 int n;cin>>n;vi arr(n);vin(n,arr);
#define input2 int n;cin>>n;vi arr(n);unordered_map<int,int>mp;vinmp(n,arr,mp);
#define input3 int n,k;cin>>n>>k;vi arr(n);vin(n,arr);
#define rep(i,a,b)        for(int i=a;i<b;i++)
const int maxn = 1e5 + 5;
const int N = 1e6 + 5;
int dirx[4] = {0, 0, -1, 1};
int diry[4] = { -1, 1, 0, 0};
char dir[4] = {'R', 'L', 'D', 'U'};//modify as per need;
int a[(int)2e5+5];
bool check(vector<int> &v){
	int n = v.size();
	rep(i,0,n){
		rep(j,i+1,n){
			rep(k,j+1,n){
				if((v[i] >= v[j] && v[j] >= v[k]) ||
					(v[i] <= v[j] && v[j] <= v[k])){
					return true;
				}
			}
		}
	}
	return false;
}

void solve() {
	int n;
	cin >> n;
	rep(i,0,n){
		cin >> a[i];
	}
	
	int ans = 0;
	rep(i,0,n){
		vector<int> v;
		rep(j,i,n){
			v.pb(a[j]);
			if(check(v)) break;
			ans++;
		}
	}
	cout << ans << "\n";
}
signed  main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	FAST;
	int t;
	// t = 1;
	cin >> t;
	while (t--)
		solve();
	return 0;
}	