#include<bits/stdc++.h> usingnamespace std; #define int long long constint maxn=1e6; int n; int a[maxn+5]; int f[maxn+5]; int s[maxn+5]; int lst[maxn+5]; inlinevoidSolve(){ scanf("%lld",&n); for(int i=1;i<=n;i++){ scanf("%lld",&a[i]); if(1<i) s[i]=s[i-1]+(a[i]==a[i-1])*a[i]; } memset(lst,0,sizeof(lst)); for(int i=1;i<=n;i++){ f[i]=f[i-1]; if(lst[a[i]]) f[i]=max(f[i],f[lst[a[i]]+1]+a[i]+s[i]-s[lst[a[i]]+1]); lst[a[i]]=i; } printf("%lld\n",f[n]); } signedmain(){ int tcnt;scanf("%lld",&tcnt); while(tcnt--) Solve(); return0; }