#include "partition.h"
#include<iostream>
#include<vector>
#include <map>
using namespace std;
vector<int>sol;
int n,v[2001000];
map<int,int>f;
map<int,int>f1;
vector<int> solve(vector<int> A)
{
    sol.clear();
    f.clear();
    f1.clear();
    n=0;
    while (A.size()) v[++n]=A.back(),A.pop_back();

    for (int i=1; i<=n/2; i++)
    swap (v[i],v[n-i+1]);

    for (int i=1; i<=n; i++)
    f[v[i]]++;

    for (int i=1; i<=n; i++)
    if (f1[v[i]]*2<f[v[i]]) f1[v[i]]++,sol.push_back(i-1);

    for (int i=1; i<=n; i++)
    f[v[i]]=f1[v[i]]=0;

    for (int i=1; i<=n; i++)
    cout<<v[i]<<" ";

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