#include <bits/stdc++.h>
using namespace std;
 
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp> 
//using namespace __gnu_pbds; 
//https://codeforces.com/blog/entry/11080
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
//std::nth_element(v, v + 4, v + 8);
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//#define endl "\n"
#define ll long long
#define f first
#define s second
#define pii pair<int,int>
#define lui long unsigned int
//#define int long long
 
const int N = 1000005;
const ll MOD = 1e9+7;
const ll M = 1e18;
 
ll qpow(ll a, ll b, ll m)
{
    ll  ans=1;
    while(b)
    {
        if(b&1)
            ans=(ans*a)%m;
        b/=2;
        a=(a*a)%m;
    }
    return ans;
}

int main()
{
 
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    IOS;
 
    int t=1; cin>>t;
    while(t--){
      int n; cin >> n;
      int a[n];
      for(int i=0; i<n; i++)
        cin >> a[i];
      int ans = 2*n-1;
      bool ok;

      for(int i=0; i<n; i++){
        if(i+2 < n){
           ok = true;
           if(abs(a[i+2]-a[i]) == abs(a[i+1]-a[i]) + abs(a[i+2]-a[i+1]))
            ok = false;
           if(ok) ans++;
        }
        if(i+3 < n){
           ok = true;
           if(abs(a[i+2]-a[i]) == abs(a[i+1]-a[i]) + abs(a[i+2]-a[i+1]))
            ok = false;
           if(abs(a[i+3]-a[i]) == abs(a[i+1]-a[i]) + abs(a[i+3]-a[i+1]))
            ok = false;
           if(abs(a[i+3]-a[i]) == abs(a[i+2]-a[i]) + abs(a[i+3]-a[i+2]))
            ok = false;
           if(abs(a[i+3]-a[i+1]) == abs(a[i+2]-a[i+1]) + abs(a[i+3]-a[i+2]))
            ok = false;
           if(ok) ans++;
        }
      }
      cout << ans;
      
      cout << endl;
        
    }
    
    return 0;
}