// Slower C++ solution:
#include<iostream>

#include<algorithm>

#include<cmath>

#include<vector>

 

#define REP(i,s,n) for(int i=s;i<n;i++)

#define rep(i,n)   REP(i,0,n)

#define inf (1<<29)

#define MAX 161

using namespace std;



bool dp[MAX][MAX][2];

 

int main()

{

  int T;

  while(cin >> T)

    {

      while(T--)

	{

	  rep(i,MAX)rep(j,MAX)rep(l,2)dp[i][j][l] = false;

	  int N;

	  cin >> N;

	  int input[N];

	  rep(i,N) cin >> input[i];

       

	  if(N <= 2)

	    {

	      cout << input[N-1] << endl;

	      continue;

	    }

       

	  int ans = input[N-1];

 

	  REP(cur,1,N-1)

	    {

	      dp[input[cur-1]][input[cur]][cur&1] = true;

	      int R = input[cur+1];

	      rep(L,MAX)

		{

		  rep(M,MAX)

		    {

		      if(!dp[L][M][cur&1])continue;

		      //cout << cur << " cur(" << L << "," << M << "," << R << ")\n";

		      if(M == 0)

			{

			  if(cur+2 < N)

			    {

			      dp[M][R][(cur+1)&1] = true;

			      //cout << cur << " next ( " << M << "," << R << "," << input[cur+2] << ")\n";

			    }

			  else       ans = max(ans,R);

			}

		      else

			{

			  if(cur+2 < N)

			    {

			      dp[M][R][(cur+1)&1] = true;

			      //cout << cur << " next ( " << M << "," << R << "," << input[cur+2] << ")\n";

			      dp[M-1][R+L][(cur+1)&1] = true;

			      //cout << cur << " next ( " << M-1 << "," << R+L << "," << input[cur+2] << ")\n";

			    }

			  else 

			    {

			      ans = max(ans,R+L);

			      //cout << cur << " ans : " << R << "+" << L << "=" << R+L <<  " (" << L << "," << M << "," << R << ")" <<  endl;

			    }

			}

		    }

		}

	      rep(i,MAX)rep(j,MAX)dp[i][j][cur&1] = false;

	    }

	  

	  cout << ans << endl;      

	}

    }

  return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.1393966178316741x):
#include<iostream>

#include<algorithm>

#include<cmath>

#include<vector>

 

#define REP(i,s,n) for(int i=s;i<n;i++)

#define rep(i,n)   REP(i,0,n)

#define inf (1<<29)

#define MAX 130

using namespace std;



bool dp[MAX][MAX][2];

 

int main()

{

  int T;

  while(cin >> T)

    {

      while(T--)

	{

	  rep(i,MAX)rep(j,MAX)rep(l,2)dp[i][j][l] = false;

	  int N;

	  cin >> N;

	  int input[N];

	  rep(i,N) cin >> input[i];

       

	  if(N <= 2)

	    {

	      cout << input[N-1] << endl;

	      continue;

	    }

       

	  int ans = input[N-1];

 

	  REP(cur,1,N-1)

	    {

	      dp[input[cur-1]][input[cur]][cur&1] = true;

	      int R = input[cur+1];

	      rep(L,MAX)

		{

		  rep(M,MAX)

		    {

		      if(!dp[L][M][cur&1])continue;

		      //cout << cur << " cur(" << L << "," << M << "," << R << ")\n";

		      if(M == 0)

			{

			  if(cur+2 < N)

			    {

			      dp[M][R][(cur+1)&1] = true;

			      //cout << cur << " next ( " << M << "," << R << "," << input[cur+2] << ")\n";

			    }

			  else       ans = max(ans,R);

			}

		      else

			{

			  if(cur+2 < N)

			    {

			      dp[M][R][(cur+1)&1] = true;

			      //cout << cur << " next ( " << M << "," << R << "," << input[cur+2] << ")\n";

			      dp[M-1][R+L][(cur+1)&1] = true;

			      //cout << cur << " next ( " << M-1 << "," << R+L << "," << input[cur+2] << ")\n";

			    }

			  else 

			    {

			      ans = max(ans,R+L);

			      //cout << cur << " ans : " << R << "+" << L << "=" << R+L <<  " (" << L << "," << M << "," << R << ")" <<  endl;

			    }

			}

		    }

		}

	      rep(i,MAX)rep(j,MAX)dp[i][j][cur&1] = false;

	    }

	  

	  cout << ans << endl;      

	}

    }

  return 0;

}