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

const int N=5010;
int T,n;
long long sum[N];

int main(){
	scanf("%d",&T);
	while(T--){
		scanf("%d",&n);
		memset(sum,0,sizeof(sum));
		int x;
		long long tot=0,ans=0;
		for(int i=1;i<=n;i++) {
			scanf("%d",&x);
			tot+=sum[i];
			long long now=tot;
			if(tot<x-1) ans+=x-1-tot,now=x-1;
			if(now>x) sum[i+1]+=now-x,sum[i+2]+=x-now,now=x;
			if(i+x+1<=n) sum[i+x+1]--;
			if(i+x-now+1<=n) sum[i+x-now+1]++;
		}
		printf("%lld\n",ans);
	}
}