#include <bits/stdc++.h>
using namespace std;

bool check(long long x, int n, const vector<long long>& h_original) {
    vector<long long> h_current = h_original;
    for (int i = n - 1; i >= 2; --i) {
        if (h_current[i] < x) {
            return false;
        }
        long long d = min(h_original[i] / 3LL, (h_current[i] - x) / 3LL);
        h_current[i - 1] += d;
        h_current[i - 2] += 2 * d;
    }
    return h_current[0] >= x && h_current[1] >= x;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        vector<long long> h(n);
        for (int i = 0; i < n; ++i) {
            cin >> h[i];
        }

        long long low = 1, high = 1e9 + 7, ans = 0;
        while (low <= high) {
            long long mid = low + (high - low) / 2;
            if (check(mid, n, h)) {
                ans = mid;
                low = mid + 1;
            } else {
                high = mid - 1;
            }
        }
        cout << ans << endl;
    }
    return 0;
}