#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;
mt19937 R(chrono::steady_clock::now().time_since_epoch().count());
template<typename T>
vector<T> normalize(vector<T>& a, T start = 0) {
int n = a.size();
vector<T> b = a;
sort(b.begin(), b.end());
b.erase(unique(b.begin(), b.end()), b.end());
vector<T> ret(n, start);
for (int i = 0; i < n; ++i) {
ret[i] += lower_bound(b.begin(), b.end(), a[i]) - b.begin();
}
return ret;
}
int main() {
FAST;
int tc = 1, ti;
cin >> tc;
for (ti = 1; ti <= tc; ++ti) {
ll n, i, t, curr, ans;
cin >> n;
vector<ll> a(n), col(n);
for (i = 0; i < n; ++i) cin >> a[i];
ans = LLONG_MAX;
t = n*500; while (t--) {
col[0] = R() % 6;
col[1] = R() % 6;
while (col[1] == col[0]) col[1] = R() % 6;
for (i = 2; i < n; ++i) {
col[i] = R() % 6;
while ((col[i] == col[i-2]) || (col[i] == col[i-1])) {
col[i] = R() % 6;
}
}
curr = 0;
for (i = 0; i < n; ++i) curr += col[i] * a[i];
ans = min(ans, curr);
}
cout << ans << "\n";
}
return 0;
}