#include<bits/stdc++.h>


using namespace std;


int main()

{

    ios::sync_with_stdio(false);

    cin.tie(NULL);

    cout.tie(NULL);

    

    int t,n;

    cin>>t;

    while(t--){

        cin>>n;

        vector<int> v;

        long long int tmp, cnt=0;

        for(int i=1; i<=n; i++){

            cin>>tmp;

            if(tmp<i){

                cnt+=upper_bound(v.begin(),v.end(),tmp-1)-lower_bound(v.begin(),v.end(),1);

                v.push_back(i);

            }

        }

        cout<<cnt<<"\n";

    }

}