/**
 *   Author:   ShacozzZ
 *   Created:  2021-02-28 22:23:42
**/

#include <bits/stdc++.h>
using namespace std;
#define check(x) cout << "x = " << x << " "
// #define endl '\n'
#define x first
#define y second
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
const int inf = 0x3f3f3f3f;
const int md = 1e9 + 7;
const int maxn = 5e3 + 5;
const int maxm = 1e9;
const ull B = 233;
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};

ll n, m;
ll a[maxn], b[maxn];

inline void solve() {
    cin >> n;
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
        // a[i] = 1e9;
        b[i] = 0;
    }
    int u, v;
    ll ans = 0;
    for(int i = 1; i <= n; i++) {
        ans += max((ll)0, a[i] - 1 - b[i]);
        if(a[i] + i > n) {
            if(a[i] + i - n >= b[i]) {
                b[i] = 0;
            } else {
                b[i] = b[i] - (a[i] + i - n);
            }
            a[i] = n - i;
        }
        while(a[i] > 1 || b[i]) {
            b[i + a[i]]++;
            if(a[i] > 1) {
                a[i]--;
                if(b[i]) {
                    b[i]--;
                }
            } else {
                b[i + 1] += b[i] - 1;
                b[i] = 0;
            }
        }
    }
    cout << ans << endl;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("/Users/zhoukaijie/Documents/ACM/a.in", "r", stdin);
    freopen("/Users/zhoukaijie/Documents/ACM/a.out", "w", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    int __ = 1;
    cin >> __;
    // init();
    while(__--) {
        solve();
    }
    return 0;
}
