#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
const int N=1e6+10;
int a[N];
signed main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int T;
cin>>T;
while(T--){
int n;
cin>>n;
for(int i=1;i<=n;i++) cin>>a[i];
int l=1,r=0,ans=0,maxn=-1;
while(l<=n){
if(a[l]==l){
l++;
continue;
}
while(r<n&&r<maxn) maxn=max(maxn,a[++r]);
ans+=(r-l+1);
l++;
}
cout<<ans<<endl;
}
return 0;
}