//W4P3R
#include<bits/stdc++.h>
#define inf 1e9
#define eps 1e-6
#define mp make_pair
#define pb push_back
#define re register ll
#define fr first
#define sd second
#define pa pair<ll,ll>
#define FOR(i,a,b) for(re i=a;i<=b;i++)
#define REP(i,a,b) for(re i=a;i>=b;i--)
#define MEM(a) memset(a,0,sizeof(a))
#define N 5010
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
inline ll read()
{
	char ch=getchar();
	ll s=0,w=1;
	while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){s=s*10+ch-'0';ch=getchar();}
	return s*w;
}
inline ll lowbit(ll x){return x&(-x);}
ll T;
ll n,s[N],nxt[N];
ll num,ans;
inline void upd(ll x)
{
	FOR(i,1,x)while(s[nxt[i]]==1)nxt[i]++;
}
int main()
{
	//ios::sync_with_stdio(false);
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	T=read();
	while(T--)
	{
		n=read();ans=0,num=0;FOR(i,1,n)s[i]=read();s[n+1]=0;
		if(n==1){cout<<s[1]-1<<'\n';continue;}
		FOR(i,1,n)nxt[i]=i;FOR(i,1,n)if(s[i]==1)num++,upd(i);
		while(true)
		{
			if(num==n)break;
			ll x=nxt[1];if(s[x]>=n){ans+=s[x]-n;s[x]=n;}
			ll now=1;ans++;
			while(now<=n)
			{
				now=nxt[now];
				if(now>n)break;
				ll to=now+s[now];s[now]--;if(s[now]==1)num++,upd(now);
				now=to;
			}
		}
		cout<<ans<<'\n';
	}
	return 0;
}
//gl

