#include <bits/stdc++.h>

using namespace std;
const int N = 1e5 + 50;
struct num {
    int x;
    int id;
} ns[N];

bool cmp(num a, num b) {
    if (a.x == b.x)return a.id < b.id;
    else return a.x > b.x;
}

int main() {
    int T, n;
    scanf("%d", &T);
    while (T--) {
        int n;
        scanf("%d", &n);
        for (int i = 1; i <= n; i++) {
            scanf("%d", &ns[i].x);
            ns[i].id = i;
        }

        sort(ns + 1, ns + 1 + n, cmp);
        bool fl = 1;
        for (int i = 2; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
                if (ns[j].id % i != 0) {
                    if (fl) {
                        printf("%d", ns[j].x);
                        fl = 0;
                    } else printf(" %d", ns[j].x);
                    break;
                }
            }
        }
        printf("\n");

    }
    return 0;
}