import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto n = readln.strip.to !(int);
		auto s = readln.splitter.map !(to !(int)).array;
		s ~= 0;
		long res = 0;
		auto p = iota (n + 1).array;
		for (int i = 0; i < n; i++)
		{
			int add = max (0, s[i] - n + i);
			res += add;
			s[i] = max (0, s[i] - add);
			while (s[i] > 1)
			{
				for (int j = i; j < n; j += s[j] + 1)
				{
					if (s[j] <= 1)
					{
						p[j] = p[j + 1];
					}
					j = p[j];
					s[j] = max (0, s[j] - 1);
				}
				res += 1;
			}
		}
		writeln (res);
	}
}
