#include "stdio.h"
#include "math.h"
#include <algorithm>
#include <vector>
#include <iostream>
#include <map>
#include <string>
#include <set>
#include <cstring>

#define max(a,b) (((a)>(b))?(a):(b))
#define min(a,b) (((a)<(b))?(a):(b))
#define INF 0xFFFFFFFFFF

using namespace std;

long long seq[200010];
long long dp[200010];

int main() {
    int t;
	scanf("%d", &t);
	for (int i = 0; i < t; i++) {
		long long res = 0;
		int n;
		scanf("%d", &n);
		for (int j = 0; j < n; j++) 
			scanf("%lld", &seq[j]);
		dp[0] = 1;
		res += dp[0];
		int cur = 1;
		long long last = seq[0];
		for (int j = 1; j < n; j++) {
            if (j == 1) {
				cur = 2;
				last = seq[1];
				res += 2;
				continue;
			}
		    long long tem = (seq[j] - seq[j - 1]) * (seq[j - 1] - seq[j - 2]);
			if (tem >= 0) {
				res += 2;
				continue;
			}
			tem = 0;
			if (j > 2)
				tem = (seq[j - 2] - seq[j - 3]) * (seq[j - 1] - seq[j - 2]);
			if (j > 2 && seq[j - 1] < seq[j - 2] && seq[j - 3] > seq[j - 1] && tem < 0 && seq[j] < seq[j - 2]) {
				res += 4;
				continue;
			}
			if (j > 2 && seq[j - 1] > seq[j - 2] && seq[j - 3] < seq[j - 1] && tem < 0 && seq[j] > seq[j - 2]) {
				res += 4;
				continue;
			}
			res += 3;
		}
		printf("%lld\n", res);
	}
	return 0;
}