//#include "partition.h"
#include<iostream>
#include<vector>
#include <map>
using namespace std;
int long long sum,n,b[2001000],s,s1;
vector<int> solve(vector<int> A)
{
    vector<int>sol;
    n=0;
    sol.clear();
    while (A.size()) n++,A.pop_back();

    sum=n*(n+1)/2;
    s=sum/2+sum%2;
    s1=0;
    for (int i=n-1; i>=0; i--)
    if (s1+i+1<=s) sol.push_back(i),b[i]=1,s1=s1+i+1;
    for (int i=0; i<=n-1; i++)
    if (b[i]==0) sol.push_back(i);
    for (int i=0; i<=n; i++)
    b[i]=0;

    return sol;
}

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;
}
