#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
const int N = 1e5 + 10;
const int P = 1e9 + 7;
int a[N];
map<int, int>mp;
void solve() {
int pos = 1;
priority_queue<int>ans[N];
mp.clear();
int n;
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++) {
int tmp = i - a[i];
if (mp.find(tmp) != mp.end()) {
ans[mp[tmp]].push(a[i]);
} else {
mp[tmp] = pos++;
ans[mp[tmp]].push(a[i]);
}
}
int res = 0;
for (int i = 1; i < pos; i++) {
while(ans[i].size()>=2){
int tmp=ans[i].top();
ans[i].pop();
tmp+=ans[i].top();
ans[i].pop();
if(tmp>0) res+=tmp;
}
}
cout<<res<<endl;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int _ = 1;
cin>>_;
while (_--) {
solve();
}
return 0;
}#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define P pair<int,int>
#define f first
#define s second
using namespace std;
void solve(){
int n;
cin>>n;
int a[n];
vector<P>b;
for(int i=0;i<n;i++){
cin>>a[i];
b.push_back({i-a[i],i});
}
sort(b.begin(),b.end(),greater<P>());
map<int,int>mp;
int ans=0;
for(int i=0;i+1<n;i++){
if(b[i].f==b[i+1].f&&mp[b[i].s]==0&&mp[b[i+1].s]==0&&b[i].s-b[i].f+b[i+1].s-b[i+1].f>=0){
ans+=b[i].s-b[i].f+b[i+1].s-b[i+1].f;
mp[b[i].s]=1;
mp[b[i+1].s]=1;
}
}
cout<<ans<<endl;
return;
}
signed main(){
int _=1;
cin>>_;
while(_--){
solve();
}
}