#include "iostream"
#include "algorithm"
#include "cstring"
#include "cstdio"
#include "cmath"
#include "vector"
#include "map"
#include "set"
#include "queue"
using namespace std;
#define MAXN 3036
//#define int long long
#define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i)
#define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i)
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define all(x) (x).begin() , (x).end()
#define mem( a ) memset( a , 0 , sizeof a )
typedef long long ll;
int n , m;
int A[MAXN];

int dp[MAXN][MAXN] , mn[MAXN][MAXN];

int T[MAXN];
void ad( int x , int c ) {
	while( x <= n ) T[x] += c , x += ( x & -x );
}
int sum( int x ) {
	int re = 0;
	while( x > 0 ) re += T[x] , x -= ( x & -x );
	return re;
}

void solve() {
	cin >> n;
	rep( i , 1 , n ) scanf("%d",A + i) , A[i] += i;
	rep( i , 1 , n ) rep( j , i + 1 , n + 1 ) dp[i][j] = mn[i][j] = 0x3f3f3f3f;
	dp[n][n] = 0 , mn[n][n + 1] = mn[n][n] = 0;
	per( i , n - 1 , 1 ) {
		rep( i , 1 , n ) T[i] = 0;
		rep( j , i + 1 , A[i] ) {
			dp[i][j] = mn[j][A[i] + 1] + sum( n - j + 1 );
			ad( n - A[j] + 1 , 1 );
		}
		per( t , A[i] , i + 1 ) mn[i][t] = min( mn[i][t + 1] , dp[i][t] );
	}
	cout << mn[1][2] << endl;
}

signed main() {
    int T;cin >> T;while( T-- ) solve();
//    solve();
}

  	   					 				 	 	  	 	 	 	