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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    vector<long long> b(n);
    long long ans = 0;
    for (int i = 0; i < n; i++) {
      long long sum = 0;
      for (int j = i; j < n; j += a[j]) {
        if (b[j] == 0) {
          sum += a[j];
        } else {
          sum += b[j];
          break;
        }
      }
      ans = max(ans, sum);
      for (int j = i; j < n; j += a[j]) {
        if (b[j] == 0) {
          b[j] = sum;
          sum -= a[j];
        } else {
          break;
        }
      }
    }
    cout << ans << '\n';
  }
  return 0;
}