/**
 * Author: Fau
 * Time: 2021-07-15 14:32
**/

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 1; i <= (n); ++i)
#define debug(a) cout << #a << " = " << a << endl
using namespace std;
typedef long long ll;
const int N = 2E5 + 10;
int a[N];

int fact(int x, int y) {
	if (a[x] == a[y]) return 0;
	if (a[x] < a[y]) return -1;
	return 1;
}
bool judge(int l, int r) {
	if (r - l + 1 <= 2) return 1;
	if (r - l + 1 >= 5) return 0;

	if (r - l + 1 == 3) {
		int x = fact(l, l + 1);
		int y = fact(l + 1, r);
		if (x == y or !x or !y) return 0;
		return 1;
	}

	if (a[l + 1] >= a[l]) {
		if (a[l + 2] >= a[l]) return 0;
		if (a[r] <= a[l + 2] or a[r] >= a[l + 1]) return 0;
		return 1;
	}
	else {
		if (a[l + 2] <= a[l]) return 0;
		if (a[r] >= a[l + 2] or a[r] <= a[l + 1]) return 0;
		return 1;
	}
}
int main()
{
#ifndef ONLINE_JUDGE
	freopen("/Users/Fau/Documents/Fau/project/Clion Program/TEXT/in.txt", "r", stdin);
	freopen("/Users/Fau/Documents/Fau/project/Clion Program/TEXT/out.txt", "w", stdout);
#endif
//------------------------------------------------------------CODE BEGIN------------------------------------------------------------

	int t; cin >> t;
	while (t--) {
		int n; scanf("%d", &n);
		rep(i, n) scanf("%d", &a[i]);

		int res = 0;
		for (int l = 1; l <= n; ++l) {
			for (int r = l; r <= n; ++r) {
				if (judge(l, r)) {
					//cout << l << ' ' << r << endl;
					res++;
				}
				else break;
			}
		}

		printf("%d\n", res);
	}

//-------------------------------------------------------------CODE END-------------------------------------------------------------
#ifndef ONLINE_JUDGE
	fclose(stdout);
	system("/Users/Fau/Documents/Fau/project/Clion\\ Program/compare_Fau");
#endif
	return 0;
}