#include <bits/stdc++.h>
using namespace std;
#define FOR(i, j, k, in) for (int i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (int i=j ; i>=k ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define all(cont) cont.begin(), cont.end()
#define INF (int)1e9
#define EPS 1e-6
#define SWAP(t,x,y) t tmp; tmp = (x); (x) = (y); (y) = tmp;
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define MP make_pair
#define PB push_back
#define MEM(a, b) memset(a, (b), sizeof(a))
typedef long long int lli;
typedef pair<lli, lli> pll;
typedef pair<int, int> pii;
typedef unordered_map<char, lli> mcl;
typedef unordered_map<lli, lli> mll;
typedef unordered_set<lli> usl;
typedef unordered_set<char> usc;
typedef unordered_set<pll> uspll;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<pll> vpll;
typedef map<int,int> mpii;
typedef set<int> si;
typedef multiset<int> msi;
typedef pair<double, double> pdd;
const double pi = 3.14159265358979323;
lli n, k, m, tc, ans = 0, count = 0, mymax = -1e18, mymin = 1e18, x, y;
string final_ans = "";
string s = "";
 
vector<pair<int, int>> directions = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};

template <typename T> 
ostream& operator<<(ostream& os, const vector<T>& v) 
{  
    REP(i, v.size())
        os << v[i] << " ";
	os << '\n';
    return os; 
}
bool isGood(lli a, lli b, lli c, lli i, lli j, lli k){
	lli val1 = abs(a - b) + abs(i - j);
	lli val2 = abs(b - c) + abs(j - k);
	lli val3 = abs(a - c) + abs(i - k);
	if(val1 + val2 == val3 || val1 + val3 == val2 || val2 + val3 == val1) return false;
	return true;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin >> tc;
	REP(i, tc){
		cin >> n;
		vector<lli> vec(n);
		REP(j, n) cin >> vec[j];
		if(n < 3) cout << n * (n + 1) / 2 << '\n';
		else{
			ans = 0;
			ans += 2 * n - 1; //sizes of 1, 2
			//check size of 3.. 
			REP(j, n - 2){
				if(isGood(vec[j], vec[j + 1], vec[j + 2], j, j+1, j+2)) ans++;
			}
			REP(j, n - 3){
				vector<vector<lli>> combinations = {{0, 1, 2}, {0, 1, 3}, {0, 2, 3}, {1, 2, 3}};
				bool possible = true;
				for(vector<lli> combination: combinations){
					if(!isGood(vec[j + combination[0]], vec[j + combination[1]], vec[j + combination[2]], j + combination[0], j + combination[1], j + combination[2])) possible = false;
				}
				ans += possible;
			}
			cout << ans << '\n';
		}
			
			
	}
}
