#include <bits/stdc++.h>
using namespace std;
const int N=5050;

int t,n;
int a[N],b[N];
int main()
{
	scanf("%d",&t);
	while(t--)
	{
		scanf("%d",&n);
		for(int i=1;i<=n;i++) scanf("%d",&a[i]),b[i]=0;
		b[n+1]=0;
		long long ans=0;
		for(int i=1;i<=n;i++)
		{
			for(int j=min(n,i+a[i]);j>=i+2;j--) ++b[j];
			ans+=max(0,a[i]-1-b[i]);
			b[i+1]+=max(0,b[i]+1-a[i]);
		}
		printf("%lld\n",ans);
	}
}