#include<bits/stdc++.h>
using namespace std;

const int N = 2000006;

long long a[N];
long long b[N];

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	int t;
	cin>>t;
	while(t--){
		long long n;
		cin>>n;
		long long cnt = 0;
		long long ans = 0;
		for(long long i=1;i<=n;i++){
			cin>>a[i];
			//if(a[i] == 1)continue;
			cnt += b[i];
			long long l = 2,r = a[i];
			ans += max(0LL,a[i]-1-cnt);
			//cout<<a[i]<<" "<<b[i]<<endl;
			//cout<<i+l<<" "<<min(n+1,i+r+1)<<endl;
			long long k = cnt - a[i] + 1;
			if(k > 0){
				b[i+1] += k;
				b[i+2] -= k;
			}
			b[i+l] += 1;
			int idx = min(n+1,i+r+1);
			b[idx] -= 1;
		}
		cout<<ans<<endl;
		if(t){
			for(int i=1;i<=n+3;i++){
				a[i] = b[i] = 0;
			}
		}
	}
	
	return 0;
}
