Problem: At a certain research institute, I was developing a medium for energy transfer. This medium has a polymer structure consisting of a special substance as shown in Fig. 3.

Structure of energy transfer medium.
---
(-α-Ea-β-) n
Figure 3: Structure of energy transfer medium.

The part shown by Ea in the figure is the Energy Accumulator, which is the most characteristic part of this medium. This Ea group can take various energy states discretized with a width of 1 kJ. Exciting a certain Ea group has the effect of transferring all the energy stored in the adjacent Ea group bonded to the α side of the Ea group to the adjacent Ea group bonded to the β side. An exothermic reaction is triggered (Fig. 4). During this reaction, the energy of the excited Ea group is consumed by 1 kJ. It should be noted that the excitation reaction does not occur for the Ea groups located at both ends of the polymer and the Ea groups whose energy state is 0 kJ, and that the Ea groups can store a sufficiently large amount of energy. Are known.

Reaction when the central Ea group is excited.
---
Figure 4: Reaction when the central Ea group is excited.

We were thinking of using this property to enable energy transfer, but researchers realized that the order in which each Ea group was excited was important for efficient energy transfer. ..

Fortunately, the order and number of excitations can be controlled arbitrarily, but they do not know the optimum excitation procedure. Therefore, as a stepping stone to their ideas, I would like you to calculate the maximum amount of energy that can be stored in the rightmost Ea group (the Ea group closest to the β end) with respect to the energy distribution in the initial state.



Input

The input consists of multiple datasets and is given in the following format.


N
C1
C2
...
CN


The integer N (0 <N ≤ 60) at the beginning of the input is the number of datasets in question, and the information Ck for each dataset is given over the last 2N lines.

Each dataset Ck is given over two lines in the following format.


L
E1 E2 ... EL


L is the length of the Ea chain of the medium handled by each data set, which means that the number of Ea groups given here are bonded in series. The L integer Ek in the next row is the amount of energy initially stored in the kth Ea chain counting from the left when the α end of the Ea chain of length L is placed at the left end, in kJ units. It is shown.

Here, it is guaranteed that 0 ≤ Ek ≤ 4, 1 ≤ L ≤ 80.

Output

For each data set, describe the maximum energy that can reach the rightmost Ea chain under a given situation in kJ units, and describe only the integer value on one line.

Example

Input

7
1
2
2
1 2
3
4 1 4
3
4 0 4
5
4 1 4 0 4
5
4 1 4 1 4
5
4 2 4 0 4


Output

2
2
8
4
7
12
11

Solution (in CPP):

Solution:
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;

vector<long long int> divisor(long long int n) {
	vector<long long int> res;
	for (long long int i = 1; i * i <= n; ++i) {
		if (n % i == 0) {
			res.push_back(i);
			if (i * i != n) res.push_back(n / i);
		}
	}
	sort(begin(res), end(res));
	return res;
}

vector<int>compress(vector<int>nums) {
	auto divs(divisor(nums.size()));
	reverse(divs.begin(),divs.end());
	for (auto div : divs) {
		bool ok=true;

		for (int i = 0; i < nums.size() / div; ++i) {
			for (int j = 1; j < div; ++j) {
				if(nums[i*div+j])ok=false;
			}
		}
		if (ok) {
			vector<int>ans(nums.size()/div);
			for (int i = 0; i < nums.size() / div; ++i) {
				ans[i]=nums[i*div];
			}
			return ans;
		}
	}
	assert(false);
	return vector<int>();
}

vector<int>mk(string st) {
	vector<int>nums(st.size()/2);
	for (int i = 0; i < st.size() / 2; ++i) {
		char c1 = st[2*i];
		char c2=st[2*i+1];
		int num=!isdigit(c1)?(c1-'A'+10):c1-'0';
		num*=16;
		num+=!isdigit(c2)?(c2-'A'+10):c2-'0';

		nums[i]=num;
	}
	return compress(nums);
}

long long int gcd(long long int l, long long int r) {
	if (l > r)return gcd(r, l);
	else {
		if (r%l) {
			return gcd(l, r%l);

		}
		else {
			return l;
		}
	}
}

int main() {
	int Q;cin>>Q;
	while (Q--) {
		int L;cin>>L;
		vector<int>es(L);
		for(int i=0;i<L;++i)cin>>es[i];

		if (L < 2) {
			cout<<es[L-1]<<endl;
		}
		else {
			vector<vector<vector<int>>>dp(L, vector<vector<int>>(200, vector<int>(200)));
			dp[0][es[0]][es[1]] = 1;
			for (int l = 0; l < L - 2; ++l) {
				for (int a = 0; a < 200; ++a) {
					for (int b = 0; b < 200; ++b) {
						if (dp[l][a][b]) {

							if (b) {
								dp[l + 1][b - 1][a + es[l + 2]] = true;
							}
							dp[l + 1][b][es[l + 2]] = true;
						}
					}
				}
			}
			int ans=0;
			for (int i = 0; i < 200; ++i) {
				for (int j = 0; j < 200; ++j) {
					if(dp[L-2][i][j])ans=max(ans,j);
				}
			}
			cout<<ans<<endl;
		}

		
	}
	return 0;
}