#include <bits/stdc++.h>
using namespace std;
const int maxn = 1003;
int n, t;
int tmp;
int a[maxn];
int main() {
  cin >> t;
  while (t--) {
    memset(a, 0, sizeof a);
    cin >> n;
    int ma = 0;
    for (int i = 1; i <= n; ++i) {
      cin >> tmp;
      a[tmp] += 1;
      ma = max(ma, tmp);
    }
    vector<int> ttt;
    int tag = 1;
    for (int i = ma; i >= 1; --i) {
      if (tag == 1 && a[i] >= 1) {
        a[i] -= 1;
        ttt.push_back(i);
        for (int j = i - 1; j >= 1; --j) {
          if (i % j == 0) {
            for (int k = i - 1; k >= 1; --k) {
              if (k % j == 0 && a[k] >= 1) {
                a[k] -= 1;
                ttt.push_back(k);
              }
            }
          }
        }
        tag = 0;
      } else if (a[i] >= 1) {
        a[i] -= 1;
        ttt.push_back(i);
      }
    }
    for (auto i : ttt) {
      cout << i << ' ';
    }
    cout << endl;
  }
  return 0;
}
