#include<bits/stdc++.h>
using namespace std;
const long long M=1000,MOD=1e9+7;
typedef long long ll;
int dp[M][10][10][10];
int limit=10;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int t=1;
cin>>t;
while(t--){
int n;
cin>>n;
vector<int>a(n+1);
for(int i=1;i<=n;i++)cin>>a[i];
for(int l=0;l<limit;l++)
for(int j=0;j<limit;j++)
for(int k=0;k<limit;k++)dp[1][l][j][k]=l*a[1];
for(int l=0;l<limit;l++)
for(int j=0;j<limit;j++)
for(int k=0;k<limit;k++){
if(l!=j)dp[2][l][j][k]=l*a[2]+j*a[1];
else dp[2][l][j][k]=INT_MAX;
}
for(int i=3;i<=n;i++){
for(int l=0;l<limit;l++)
for(int j=0;j<limit;j++)
for(int k=0;k<limit;k++){
dp[i][l][j][k]=INT_MAX;
if(l==j || l==k || j==k)continue;
int cur=a[i]*l+a[i-1]*j+ a[i-2]*k;
for(int x=0;x<limit;x++){
if(x==j || x==k)continue;
for(int y=0;y<limit;y++){
if( y==x || y==k)continue;
for(int z=0;z<limit;z++){
if(z==x || z==y )continue;
dp[i][l][j][k]=min(dp[i][l][j][k],cur+dp[i-3][x][y][z]);
}
}
}
}
}
int mx=INT_MAX;
for(int l=0;l<limit;l++)
for(int j=0;j<limit;j++)
for(int k=0;k<limit;k++)mx=min(dp[n][l][j][k],mx);
cout<<mx<<"\n";
}
return 0;
}