#include <bits/stdc++.h>
using namespace std;
int arreglo[10003];
int t, n, mayor;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> t;
  while (t--) {
    cin >> n;
    for (int i = 1; i <= n; i++) {
      cin >> arreglo[i];
    }
    sort(arreglo + 1, arreglo + n + 1);
    reverse(arreglo + 1, arreglo + n + 1);
    mayor = arreglo[1];
    cout << mayor << " ";
    arreglo[1] = 0;
    for (int i = 2; i <= n; i++) {
      if (mayor % arreglo[i] == 0) {
        cout << arreglo[i] << " ";
        mayor = arreglo[i];
        arreglo[i] = 0;
      }
    }
    for (int i = 1; i <= n; i++) {
      if (arreglo[i] != 0) {
        cout << arreglo[i] << " ";
      }
    }
    cout << endl;
  }
}
