#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
using namespace std;

int main()
{
    int task;
    cin>>task;
    while(task--)
    {
        int n;
        cin>>n;
        int a[n];

        int ans=n+n-1;

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

        //cout<<ans<<endl;


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


        cout<<ans<<endl;






    }
    return 0;
}


