#include<bits/stdc++.h> usingnamespace std; typedeflonglong ll; typedef pair<int , int> pi; #define endl '\n' constint N = 2e5 + 10; int n; int a[N] , b[N]; structbit { #define lowbit(x) (x & -x) int c[N]; voidadd(int x){ for (int i = x; i <= n; i += lowbit(i)) c[i]++; } voiderase(int x){ for (int i = x; i <= n; i += lowbit(i)) c[i]--; } intsum(int x){ int res = 0; for (int i = x; i; i -= lowbit(i)) res += c[i]; return res; } }; bit t1 , t2 , t3;
signedmain(){ ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0); int t; cin >> t; while (t--) { cin >> n; for (int i = 1; i <= n; i++) cin >> a[i] , b[i] = a[i]; sort(b + 1 , b + 1 + n); ll tmp = 0 , ans = 0; for (int i = 1; i <= n; i++) if (b[i] != b[i - 1]) b[++tmp] = b[i]; for (int i = 1; i <= n; i++) a[i] = lower_bound(b + 1 , b + 1 + tmp , a[i]) - b;//离散化 for (int i = 1; i <= n; i++) { bool flag = 1; for (int j = i; j <= n; j++) { if (t2.sum(a[j]) || t3.sum(n) - t3.sum(a[j] - 1)) { flag = 0; // 不能暴力清空,会 TLE for (int k = i; k < j; k++) { t1.erase(a[k]); if (t2.sum(a[k]) - t2.sum(a[k] - 1)) t2.erase(a[k]); if (t3.sum(a[k]) - t3.sum(a[k] - 1)) t3.erase(a[k]); } break; } ans++; if (t1.sum(a[j])) t2.add(a[j]); if (t1.sum(n) - t1.sum(a[j] - 1)) t3.add(a[j]); t1.add(a[j]); } if (!flag) continue; for (int k = i; k <= n; k++) { t1.erase(a[k]); if (t2.sum(a[k]) - t2.sum(a[k] - 1)) t2.erase(a[k]); if (t3.sum(a[k]) - t3.sum(a[k] - 1)) t3.erase(a[k]); } } cout << ans << endl; } return0; }