#include<bits/stdc++.h>
using namespace std;
const int maxn=1e3+10;
int n;
int a[maxn],col[maxn],ans;
int get_res()
{
int pre1=0,pre2=0,sum=0;
for(int i=1;i<=n;i++)
{
if(col[i]==1)
{
if(a[i]==a[pre1])sum+=a[pre1];
pre1=i;
}
else
{
if(a[i]==a[pre2])sum+=a[pre2];
pre2=i;
}
}
return sum;
}
void dfs(int x)
{
if(x>n)
{
ans=max(ans,get_res());
return;
}
col[x]=1;
dfs(x+1);
col[x]=2;
dfs(x+1);
}
void solve()
{
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i];
}
ans=0;
dfs(1);
cout<<ans<<"\n";
}
int main()
{
// freopen("T3.in","r",stdin);
// freopen("T3.out","w",stdout);
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
int _;
cin>>_;
while(_--)
{
solve();
}
return 0;
}
/*
3
3
1 2 1
4
1 2 3 4
8
3 5 2 5 1 2 1 4
*/1
这是 2025年10月29日 存档的第 4 版,不是当前版本。查看当前版本