#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n,a[1000000],b[1000000];
int solve(int x,int n){
      if(x>=n)return 0;
      if(b[x])return b[x];
      else return b[x]=a[x]+solve(x+a[x],n);
}
int main(){int t;
	cin>>t;
	while(t--){
	cin>>n;

	for(int i=0;i<n;i++){
	      cin>>a[i];
	      b[i]=0;
	}
	for(int i=0;i<n;i++){
	      if(b[i]==0){
	            solve(i,n);
	}
	}int ans=0;
	for(int i=0;i<n;i++){
	      ans=max(ans,b[i]);
	}
	cout<<ans<<endl;
}
}
