#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>

using namespace std;
typedef long long LL;
#define FILEIN(s) freopen(s, "r", stdin)
#define FILEOUT(s) freopen(s, "w", stdout)
#define mem(s, v) memset(s, v, sizeof s)

inline int read(void) {
    int x = 0, f = 1; char ch = getchar();
    while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
    while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
    return f * x;
}

const int MAXN = 2e5 + 5;

int n;
int ans;

struct Point {
    int x, y;
}a[MAXN];

inline bool is_bad(const Point&A, const Point&B, const Point&C) {
    int d1 = abs(A.x - B.x) + abs(A.y - B.y);
    int d2 = abs(A.x - C.x) + abs(A.y - C.y);
    int d3 = abs(B.x - C.x) + abs(B.y - C.y);
    return d1 + d2 == d3;
}

inline bool check(const Point&A, const Point&B, const Point&C) {
    if (is_bad(A, B, C)) return false;
    if (is_bad(A, C, B)) return false;
    if (is_bad(B, C, A)) return false;
    return true;
}

int main() {
    int T = read();
    while (T --) {
        n = read();
        ans = n + n - 1;
        for (int i = 1; i <= n; ++ i) {
            a[i].x = read(); a[i].y = i;
        }
        for (int i = 1; i <= n - 2; ++ i) {
            if (check(a[i], a[i + 1], a[i + 2])) ++ ans;
        }
        for (int i = 1; i <= n - 3; ++ i) {
            if (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]))
                    ++ ans;
        }
        printf("%d\n", ans);
    }
    return 0;
}