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

template<typename T>
class SegTree { //Array is 0-based, Tree is 1 based
    ll size;
    vector<T> Lazy;
    function<T(T,T)> operation;
    T neutral;

    void push_down(ll node) {
        if (Lazy[node] != neutral) {
            Lazy[2 * node] = operation(Lazy[node], Lazy[2 * node]);
            Lazy[2 * node + 1] = operation(Lazy[node], Lazy[2 * node + 1]);
            Lazy[node] = neutral;
        }
    }

    void update(ll node, ll l, ll r, ll idL, ll idR, T value) {
        if (l != r)
            push_down(node);

	if (idL <= l && r <= idR) {
		Lazy[node] = operation(value, Lazy[node]);
		return;
	}

	if (idL > r || idR < l) return;

	ll m = (l + r) / 2;

        update(2 * node, l, m, idL, idR, value);
        update(2 * node + 1, m + 1, r, idL, idR, value);
    }

    T get(ll id, ll node, ll L, ll R) {
        if (L == R)
            return Lazy[node];

        push_down(node);

        ll M = (L + R) / 2;
        if (id <= M)
            return get(id, 2 * node, L, M);
        else
            return get(id, 2 * node + 1, M + 1, R);
    }

public:
    SegTree(ll len, function<T(T,T)> _operation, T _neutral) : size(len), operation(_operation), neutral(_neutral) {
        Lazy = vector<T>(4 * size, neutral);
    }

    void update(ll idL, ll idR, T value) {
	update(1, 0, size - 1, idL, idR, value);
    }

    T get(ll id) {
        return get(id, 1, 0, size - 1);
    }
};

void test_case() {

    ll n;
    cin >> n;
    vector<ll> a(n);
    for (ll& i : a)
        cin >> i;
    SegTree<ll> L(n + 10, [&](ll x, ll y) { return x + y; }, 0);

    ll answer = 0;
    for (ll curr = 0; curr < n; curr++) {
        ll l = L.get(curr);
        if (curr == n - 1) {
            a[curr] = max(a[curr] - l, 1ll);
            answer += a[curr] - 1;
            break;
        }
        ll ub = min(n - 1, curr + a[curr]);
        ll lb = max(curr + 1, curr + a[curr] - l + 1);


        if (lb <= ub) {
            L.update(lb, ub, 1);
        }
        ll was = a[curr];
        a[curr] = max(a[curr] - l, 1ll);

        l -= was;
        if (l > 0) L.update(curr + 1, curr + 1, l);

        if (a[curr] > n - 1 - curr) {
            ll now = n - 1 - curr;
            ll was2 = a[curr];
            answer += was2 - now;
            a[curr] = n - 1 - curr;
        }

        ub = curr + a[curr];
        lb = curr + 2;
        if (lb <= ub) {
            L.update(lb, ub, 1);
            answer += ub - lb + 1;
        }
    }

    cout << answer << "\n";
}

int main() {
    ios::sync_with_stdio(false);

    ll tc;
    cin >> tc;
    while (tc--) {
        test_case();
    }



    return 0;
}
