You are given a sequence $A_1, A_2, \ldots, A_N$. Calculate the number of ways to remove a non-empty contiguous subsequence from it such that the resulting sequence is non-empty and strictly increasing.

-----Input-----
- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
- The first line of each test case contains a single integer $N$.
- The second line contains $N$ space-separated integers $A_1, A_2, \ldots, A_N$.

-----Output-----
For each test case, print a single line containing one integer ― the number of ways.

-----Constraints-----
- $1 \le T \le 10$
- $1 \le N \le 10^5$
- $|A_i| \le 10^9$ for each valid $i$

-----Subtasks-----
Subtask #1 (40 points): $N \le 1,000$
Subtask #2 (60 points): original constraints

-----Example Input-----
2
3
1 1 2
4
2 4 3 5

-----Example Output-----
4
7

```python

USER_FILENAME = "<user_code>"
import sys, json, builtins
import math, heapq, bisect, itertools, functools, collections, statistics, fractions, decimal, operator, array, random, re, string, os, pathlib
try:
    import resource as _res
except Exception:
    _res = None
from collections import Counter, defaultdict, deque, OrderedDict
from functools import lru_cache, reduce
from itertools import accumulate, permutations, combinations, product
from math import gcd, ceil, floor, sqrt
from decimal import Decimal
try:
    from typing import *
except Exception:
    pass
try:
    sys.setrecursionlimit(1_000_000)
except Exception:
    pass
try:
    import site as _site
    try:
        _sys_sites = _site.getsitepackages() if hasattr(_site, "getsitepackages") else []
        for _p in _sys_sites:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
    try:
        _usp = _site.getusersitepackages()
        if isinstance(_usp, str):
            _usp = [_usp]
        for _p in _usp:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
except Exception:
    pass

ns = {"__name__": "__main__"}
for _k, _v in list(globals().items()):
    if not _k.startswith("_"):
        ns[_k] = _v
_CODE = 'for _ in range(int(input())):\n n = int(input())\n arr = list(map(int,input().split()))\n front = [0 for i in range(n)]\n back = [n-1 for i in range(n)]\n for i in range(1,n):\n  if front[i-1]==i-1 and arr[i]>arr[i-1]:\n   front[i] = i\n  else:\n   front[i] = front[i-1]\n for i in range(n-2,-1,-1):\n  if back[i+1]==i+1 and arr[i]<arr[i+1]:\n   back[i] = i\n  else:\n   back[i] = back[i+1]\n if(back[0]==0):\n  print(2*n-2+(n-2)*(n-1)//2)\n else:\n  ans = n-back[0]\n  for i in range(1,n):\n   if front[i-1]==i-1:\n    ans+=1\n    key = arr[i-1]\n    low = back[i]\n    high = n-1\n    if arr[high]>key:\n     flag = False\n     while low<high:\n      mid = (low+high)//2\n      if arr[mid]>key:\n       high = mid\n      else:\n       low = mid\n      if low+1==high:\n       if flag:\n        high-=1\n       flag = True\n     mid = (low+high)//2\n     if arr[mid]<=key:\n      mid+=1\n     ans += (n-mid)\n    \n  print(ans)\n'
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

```

Measured memory_bytes: 13789