#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#pragma GCC optimize("O3")

const int N = 11000000;
const int X = 1100;
const int K = 31;

array<int, 2> B[N], Bt[N];
vector<int> C;
ll pref[N], cur, S;
int cnt[X], L, R;

void dfs(int l, int r) {
    if (l > r) assert(false);
    int v = B[rand() % (r - l + 1) + l][0];
    int ptr = l;
    for (int i = l; i < r; i++)
        if (B[i][0] < v)
            Bt[ptr++] = B[i];
    int ptrb = ptr;
    for (int i = l; i < r; i++)
        if (B[i][0] == v)
            Bt[ptrb++] = B[i];
    int ptrc = ptrb;
    for (int i = l; i < r; i++)
        if (B[i][0] > v)
            Bt[ptrc++] = B[i];
    for (int i = l; i < r; i++)
        B[i] = Bt[i];
    int tt = l;
    ll upd = 0;
    while (tt < r && cur + B[tt][0] <= S / 2) {
        cur += B[tt][0];
        upd += B[tt][0];
        tt++;
    }
    if (tt == r || ptr <= tt && tt < ptrb) {
        R = tt;
        return;
    }
    if (tt < ptr) {
        cur -= upd;
        dfs(l, ptr - 1);
    }
    if (tt >= ptrb) {
        for (int i = ptrb; i < tt; i++)
            cur -= B[i][0];
        dfs(ptrb, r);
    }
}

vector<int> solve(vector<int> A) {
    int n = A.size();
    S = accumulate(begin(A), end(A), 0ll);
    for (int i = 0; i < n; i++)
        B[i] = Bt[i] = {A[i], i};
    cur = 0;
    dfs(0, n - 1);
    L = n - R;
    if (cur != S / 2)
        L--;
    reverse(B, B + R);
    reverse(B + R, B + n);
    for (int i = 0; i < n; i++)
        pref[i] = (i == 0 ? 0 : pref[i - 1]) + B[i][0];
    auto cnt = [&](int k) -> int {
        auto get = [&](int i) -> ll {
            if (i < k) return pref[i];
            if (i < k + n - R) return pref[i - k + R] - (R == 0 ? 0 : pref[R - 1]) + pref[k - 1];
            return pref[n - 1] - (R == 0 ? 0 : pref[R - 1]) + pref[i - n + R];
        };
        int l = -1, r = n;
        while (r - l > 1) {
            int m = (l + r) / 2;
            if (get(m) <= S / 2) l = m;
            else r = m;
        }
        return r;
    };
    int v = n / 2;
    v = max(v, L);
    v = min(v, R);
    int l = 0, r = R + 1;
    while (r - l > 1) {
        int k = (l + r) / 2;
        if (cnt(k) <= v) l = k;
        else r = k;
    }
    int k = l;
    vector<int> C(n);
    for (int i = 0; i < k; i++)
        C[n - 1 - i] = B[i][1];
    for (int i = R; i < n; i++)
        C[n - 1 - i + R - k] = B[i][1];
    for (int i = k; i < R; i++)
        C[n - 1 - i - n + R] = B[i][1];
    return C;
}




















#ifdef LOCAL

extern vector<int> solve(vector<int> A);
int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin >> t ;
    for (int test=1; test<=t; test++) {
        int n;
        cin >> n ;
        vector <int> a(n);
        for (int i=0; i<n; i++) {
            cin >> a[i] ;
        }

        for (auto ind : solve(a)) {
            cout << ind << " ";
        }
        cout << endl ;
    }
    cout << endl ;
    return 0;
}

#endif // LOCAL
