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

int p[5002];
int n;
long long int num[5002];
long long int res;
int pila[5002];
int tam;

void limpia()
{
    for (int i = 0; i <= n + 1; i++)
    {
        p[i] = 0;
        num[i] = 0;
    }
    res = 0;
}

int padre(int nodo)
{
    if (p[nodo] != nodo)
        return p[nodo] = padre(p[nodo]);
    return nodo;
}

void unir(int u, int v)
{
    p[u] = padre(v);
}

void convertiAUno(int pos)
{
    if (num[pos + 1] == 1)
        unir(pos, pos + 1);
    else
        p[pos] = pos;
    if (num[pos - 1] == 1)
        unir(pos - 1, pos);
}

int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        res = 0;
        cin >> n;
        for (int i = 1; i <= n; i++)
        {
            cin >> num[i];
        }
        num[n + 1] = 0;
        p[n + 1] = n + 2;
        for (int i = n; i >= 1; i--)
        {
            if (num[i] == 1)
            {
                if (num[i + 1] == 1)
                {
                    unir(i, i + 1);
                }
                else
                {
                    p[i] = i;
                }
            }
        }
        for (int ini = 1; ini <= n; ini++)
        {
            if (ini + num[ini] > n)
            {
                res += (ini + num[ini] - n);
                num[ini] -= (ini + num[ini] - n);
            }
            if (ini == n) res--;
            if (num[ini] <= 1)
                convertiAUno(ini);
            while (num[ini] > 1)
            {
                int pos = ini;
                res++;
                while (pos <= n)
                {
                    if (num[pos] == 1)
                    {
                        pos = padre(pos) + 1;
                    }
                    else
                    {
                        int sig = pos + num[pos];
                        num[pos]--;
                        if (num[pos] == 1)
                            convertiAUno(pos);
                        pos = sig;
                    }
                }
            }
        }
        cout << res << "\n";
        limpia();
    }
    return 0;
}
