#include <bits/stdc++.h>
#define N 200005
using namespace std;
using ll = long long;

int n, a[N];

bool valid(int l, int r) {
	for (int i=l; i<r; i++) {
		for (int j=i+1; j<r; j++) {
			for (int k = j+1; k<r; k++) {
				if (a[i] <= a[j] && a[j] <= a[k]) return false;
				if (a[i] >= a[j] && a[j] >= a[k]) return false;
			}
		}
	}
	return true;
}

void solve() {
	cin >> n;
	for (int i=0; i<n; i++) cin >> a[i];

	int ans = 0;
	for (int l=1; l<=4; l++) {
		for (int i=0; i<n-l+1; i++) {
			ans += valid(i, i+l);
		}
	}

	cout << ans << endl;
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(nullptr);
	int t; cin>>t;
	while (t--) solve();
}
