#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define siz(x) (int)(x.size())
#define all(x) x.begin(), x.end()
#define debug_arr(x,len) for(int _=1; _<=len; _++) cout<<x[_]<<" "; cout<<'\n';
#define debug(x) cout<<'\n'<<#x<<": "<<x<<'\n';
const int maxN = 2e5+5;
int n, a[maxN], truoc[maxN], sau[maxN];
struct custom_set
{
bool operator()(int a1, int a2) const
{
auto k1 = max(a[truoc[a1]], a[sau[a1]]);
auto k2 = max(a[truoc[a2]], a[sau[a2]]);
if (k1 != k2) return k1 > k2;
return a1 < a2;
}
};
void solve()
{
int ans = 0;
set<int, custom_set>clone;
deque<pair<int,int>>dq;
for(int i=1; i<=n; i+=1) dq.push_back({a[i], i});
sort(all(dq), greater<pair<int,int>>());
set<int>se;
for(int i=1; i<=n; i+=1) se.insert(i);
for(int i=0; i<n; i+=1)
{
int need = dq[i].fi, loc = dq[i].se;
// cout<<need<<'\n';
// for(auto j: clone)
// {
// cout<<a[truoc[j]]<<" "<<a[sau[j]]<<'\n';
// }
// cout<<"_______________\n"<<'\n';
for(auto j: clone)
{
if(max(a[truoc[j]], a[sau[j]]) > need) clone.erase(j);
else break;
}
bool ok = 1;
if(clone.empty()) ok = 0;
else
{
int tmp = *clone.begin();
if(max(a[truoc[tmp]], a[sau[tmp]]) == need) ok = 1;
else ok = 0;
}
if(!ok)
{
ans++;
auto tmp = se.upper_bound(loc);
if(tmp == se.end()) sau[ans] = n+1;
else sau[ans] = *tmp;
tmp = se.lower_bound(loc);
if(tmp == se.begin()) truoc[ans] = 0;
else
{
tmp--;
truoc[ans] = *tmp;
}
clone.insert(ans);
}
else
{
int cur = *clone.begin();
clone.erase(cur);
// cout<<truoc[cur]<<" "<<sau[cur]<<'\n';
if(a[sau[cur]] >= a[truoc[cur]])
{
loc = sau[cur];
auto tmp = se.upper_bound(loc);
if(tmp == se.end()) sau[cur] = n+1;
else sau[cur] = *tmp;
}
else
{
loc = truoc[cur];
auto tmp = se.lower_bound(loc);
if(tmp == se.begin()) truoc[cur] = 0;
else
{
tmp--;
truoc[cur] = *tmp;
}
}
// cout<<truoc[cur]<<" "<<sau[cur]<<'\n';
clone.insert(cur);
}
// cout<<ok<<'\n';
se.erase(loc);
}
cout<<ans<<'\n';
}
int32_t main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
int test=1;
cin>>test;
while(test--)
{
cin>>n;
for(int i=0; i<=n+1; i+=1) a[i] = 0, truoc[i] = sau[i] = 0;
for(int i=1; i<=n; i+=1) cin>>a[i];
solve();
}
}