#include <bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using ll = long long;
int main() {
FAST;
int tc = 1, ti;
cin >> tc;
for (ti = 1; ti <= tc; ++ti) {
ll n, i, j, t, sum, curr, ans;
cin >> n;
vector<ll> a(n), dp(n), to(n);
for (i = 0; i < n; ++i) cin >> a[i];
ans = 0;
t = n; while (t--) {
sum = accumulate(a.begin(), a.end(), 0ll);
if (sum == 0) break;
fill(dp.begin(), dp.end(), 0ll);
fill(to.begin(), to.end(), n);
for (i = n-3; i < n; ++i) dp[i] = a[i];
for (i = n-4; i >= 0; --i) {
for (j = i+3; j <= min(n-1, i+5); ++j) {
curr = a[i] + dp[j];
if (curr > dp[i]) {
dp[i] = curr;
to[i] = j;
}
}
}
vector<pair<ll,ll>> b;
for (i = 0; i < 3; ++i) b.emplace_back(dp[i], i);
sort(b.rbegin(), b.rend());
i = b[0].second;
while (i < n) {
a[i] = 0;
i = to[i];
}
ans += sum - b[0].first;
}
cout << ans << "\n";
}
return 0;
}