#include <map>
#include <stack>
#include <cmath>
#include <queue>
#include <cstdio>
#include <vector>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <unordered_map>

#define x first
#define y second
//#define int long long
#define fast_read ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;

typedef pair<LL, LL> PLL;
typedef pair<LL, int> PLI;
typedef pair<int, int> PII;
typedef pair<int, char> PIC;
typedef pair<PII, PII> PIIII;
typedef pair<int, string> PIS;
typedef pair<char, string> PCS;
typedef pair<double, double> PDD;

const int N = 200003, M = 400003, INF = 0x3f3f3f3f, MOD = 998244353;

int n;
LL a[N];

void solve() {
    cin >> n;
    for(int i = 0; i < n; i++) cin >> a[i];
    int ans = 2 * n - 1;
    for(int i = 1; i < n - 1; i++) ans += (a[i] - a[i - 1]) * (a[i] - a[i + 1]) > 0;
    for(int i = 0; i < n - 3; i++) ans += (a[i] - a[i + 1]) * (a[i] - a[i + 2]) < 0 && (a[i + 3] - a[i + 1]) * (a[i + 3] - a[i + 2]) < 0;
    cout << ans << '\n';
}

signed main() { fast_read

    int T; cin >> T;
    while(T--)
    {
        solve();
    }
    return 0;
}
