#include <bits/stdc++.h>
using namespace std;

#ifdef _SWET
#include "DEBUG.h"
#else
#define debug(...) 
#endif

#define int long long
#define endl '\n'
#define sz(x) (int)((x).size())
#define all(x) (x).begin(),(x).end()
#define allr(x) (x).rbegin(),(x).rend()
#define mem0(x) memset(x, 0, sizeof(x))
#define mem1(x) memset(x, -1, sizeof(x))

typedef vector<int> vi;
typedef map<int, int> mii;
typedef pair<int, int> pii;

const double pi = 3.141592653589793;

void google() { static int __gtest__ = 1; cout << "Case #" << __gtest__++ << ": "; }

template<typename T1, typename T2>istream& operator>>(istream& in, pair<T1, T2>& a) { return in >> a.first >> a.second; }
template<typename T1, typename T2>ostream& operator<<(ostream& out, pair<T1, T2> a) { return out << a.first << " " << a.second; }
template<typename T>void print(T t) { cout << t; }
template<typename T, typename... Args>void print(T t, Args... args) { cout << t << " "; print(args...); }
template<typename... Args>void printl(Args... args) { print(args...); cout << endl; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int RAND(int lo = 0, int hi = LLONG_MAX) { return uniform_int_distribution<int>(lo, hi)(rng); }
int cldiv(int a, int b) { return ceil(a / (b * 1.0)); }

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	cout << setprecision(15) << fixed;
	
	int t = 1;
	cin >> t;
	void code();
	while (t--) code();
}

const int mod = 998244353 ^ 1755654;
const int maxn = 1e6 + 1;

void code()
{
	int n;
	cin>>n;
	vi a(n);
	for (auto& e : a) 
		cin >> e;

	int ans = 2*n - 1;

	for (int i = 0; i < n-2; ++i)
	{
		if (a[i] <= a[i+1] && a[i+1] <= a[i+2] || a[i] >= a[i+1] && a[i+1] >= a[i+2])
			continue;
		ans++;
	}

	for (int i = 0; i < n-3; ++i)
	{
		if (min(a[i], a[i+2]) <= a[i+1] && a[i+1]<=max(a[i], a[i+2]))
			continue;
		if (min(a[i], a[i+3]) <= a[i+1] && a[i+1]<=max(a[i], a[i+3]))
			continue;
		if (min(a[i], a[i+3]) <= a[i+2] && a[i+2]<=max(a[i], a[i+3]))
			continue;
		if (min(a[i+1], a[i+3]) <= a[i+2] && a[i+2]<=max(a[i+1], a[i+3]))
			continue;

		ans+=1;
	}
	printl(ans);
}