#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

void solve() {
    int t;
    if (!(cin >> t)) return;
    while (t--) {
        int n;
        cin >> n;
        vector<long long> h(n);
        for (int i = 0; i < n; ++i) {
            cin >> h[i];
        }
        vector<long long> R(n), L(n);
        for (int k = 0; k < n; ++k) {
            R[k] = 0;
            for (int step = 1; step < n; ++step) {
                int curr = (k + step) % n;
                int prev = (curr - 1 + n) % n;
                R[curr] = max(R[prev], h[prev]);
            }
            L[k] = 0;
            for (int step = 1; step < n; ++step) {
                int curr = (k - step + n) % n;
                int next = (curr + 1) % n;
                L[curr] = max(L[next], h[curr]);
            }
            long long sum = 0;
            for (int i = 0; i < n; ++i) {
                sum += min(L[i], R[i]);
            }
            cout << sum << (k == n - 1 ? "" : " ");
        }
        cout << "\n";
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}