#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
int t;
cin >> t;
while (t--){
ll n, ans = 0;
cin >> n;
vector<ll> a(n + 10), vis(n + 10), dp(n + 10, 1e18);
for (int i = 1; i <= n; i++){
cin >> a[i];
}
dp[1] = 0, dp[2] = a[1], dp[3] = a[1] + a[2];
for (int i = 1; i <= n; i++){
dp[i + 3] = min(dp[i + 3], dp[i] + a[i + 1] + a[i + 2]);
}
ll j, mn = 1e18;
for (int i = n + 1; i <= n + 3; i++){
if (dp[i] < mn){
mn = dp[i], j = i;
}
} //cout<<mn<<endl;
ans += mn;
mn = 1e18;
for (int i = j; i > 0; i -= 3){
vis[i] = 1, a[i] = 0;
} //for(int i=1;i<=n;i++)cout<<a[i]<<" ";cout<<endl;
dp[2] = a[1], dp[3] = a[1] + a[2];
for (int i = 4; i <= n + 3; i++) dp[i] = 1e18;
for (int i = 1; i <= n; i++){
dp[i + 3] = min(dp[i + 3], dp[i] + a[i + 1] + a[i + 2]);
}
for (int i = n + 1; i <= n + 3; i++){
if (!vis[i] && dp[i] < mn){
mn = dp[i];
}
} //cout<<mn<<endl;
cout << ans + mn << endl;
}
}