#include<iostream>
#include<cstdio>
#include<algorithm>
#include<map>
#include<cmath>
#include<string>
#include<cstring>
using namespace std;
const int N = 2e5+10;
int T,n,a[N];
bool check(int x, int y, int z) {
	return y<min(x, z) || y>max(x, z);
}
int ans;
int main() {
	scanf("%d", &T);
	while (T--) {
		ans = 0;
		scanf("%d", &n);
		for (int i = 1; i <= n; i++) {
			scanf("%d", &a[i]);
		}
		ans = n+n-1;
		for (int i = 1; i <= n - 2; i++) {
			ans += check(a[i], a[i + 1], a[i + 2]);
			ans += 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]);
		}
		printf("%d\n", ans);
	}
	return 0;
}