#include <bits/stdc++.h>
#define LL long long
#define INF 0x3F3F3F3F
using namespace std;
const int N = 2e5 + 5;
int n, T, a[N], Ans;
bool check(int x, int y) {
    if (y - x <= 1) return 1;
    for (int i = x; i <= y; ++i)
        for (int j = i + 1; j <= y; ++j)
            for (int k = j + 1; k <= y; ++k)
                if (((a[i] <= a[j] && a[j] <= a[k]) || (a[i] >= a[j] && a[j] >= a[k])))
                    return false;
    return true;
}
int main() {
    scanf("%d", &T);
    while (T--) {
        Ans = 0, scanf("%d", &n);
        for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
        for (int i = 1; i <= n; ++i)
            for (int j = i; j >= 1 && check(j, i); --j) ++Ans;
        printf("%d\n", Ans);
    }
	return 0;
}
