#include <bits/stdc++.h>

using namespace std;

class dsu {
 public:
  vector<int> p;
  int n;

  dsu(int _n) : n(_n) {
    p.resize(n);
    iota(p.begin(), p.end(), 0);
  }

  inline int get(int x) {
    return (x == p[x] ? x : (p[x] = get(p[x])));
  }

  inline bool unite(int x, int y) {
    x = get(x);
    y = get(y);
    if (x != y) {
      p[x] = y;
      return true;
    }
    return false;
  }
};

int tt;

int main() {
  cin >> tt;
  while(tt--) {
    int n;
    cin >> n;
    vector<int> s(n);
    for(int i = 0; i < n; i++) cin >> s[i];
    long long ret = 0;
    dsu d(n);
    for(int i = 0; i < n - 1; i++) if(s[i] == 1) d.unite(i, i + 1);
    for(int i = 0; i < n; i++) {
      if(i == n - 1) {
        ret += s[i] - 1;
        break;
      }
      if(i + s[i] >= n) {
        ret += i + s[i] - n + 1;
        s[i] = n - 1 - i;
      }
      while(s[i] > 1) {
        ret++;
        vector<int> que = {i};
        while(true) {
          int id = que.back();
          if(id + s[id] >= n) break;
          assert(id != n - 1);
          if(s[id] > 1) que.push_back(id + s[id]);
          else {
            assert(id != d.get(id));
            que.push_back(d.get(id));
          }
        }
        for(int j : que) {
          if(s[j] == 1) continue;
          s[j]--;
          if(s[j] == 1 && j != n - 1) d.unite(j, j + 1);
        }
      }
    }
    cout << ret << "\n";
  }
  return 0;
}
