#include <iostream>
using namespace std;

bool notMon(int* arr, int a, int b, int c) {
	return !((arr[a] <= arr[b] && arr[b] <= arr[c]) || (arr[a] >= arr[b] && arr[b] >= arr[c]));
}

int isGood(int* arr, int s, int e) {
	if ((e - s) == 2) {
		if (notMon(arr, s, s+1, e))
			return 1;
		else
			return 0;
	}
	else if ((e - s) == 3) {
		if ( notMon(arr, s, s+1, s+2) && notMon(arr, s,s+1,s+3) && notMon(arr, s,s+2,s+3) && notMon(arr, s+1,s+2,s+3) )
			return 1;
		else 
			return 0;
	}
	else if ((e- s) == 4) {
		if (  notMon(arr, s,s+1,s+2)&& notMon(arr, s,s+1,s+3) && notMon(arr, s,s+1,s+4) && notMon(arr, s,s+2,s+3) && notMon(arr, s,s+2,s+4) 
				&& notMon(arr, s,s+3,s+4) && notMon(arr, s+1,s+2,s+3) && notMon(arr, s+1,s+2,s+4) && notMon(arr, s+1,s+3,s+4) && notMon(arr, s+2,s+3,s+4)    )
					return 1;
		else
			return 0;
	}
	
	return -1;
} 

int main() {
	int nRnd = 0; cin >> nRnd;
	for (int rnd = 0; rnd < nRnd; rnd++) {
		int len; cin >> len;
		int* arr = new int[len];
		for (int i = 0; i < len; i++)
			cin >> arr[i];
		
		int ans = 0;
		ans += len;
		ans += (len - 1);
		for (int k = 2; k < len; k++) {
			ans += isGood(arr, k-2, k);
		}
		for (int k = 3; k < len; k++) {
			ans += isGood(arr, k-3, k);
		}
		for (int k = 4; k < len; k++) {
			ans += isGood(arr, k-4, k);
		}
		cout << ans << endl;
		
		delete[] arr;
	}
	return 0;
}
