#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 5;
int arr[MAXN];
vector<int> v1[MAXN];
bool exists[MAXN];
set<int> s1;
map<int, int> m1;
bool visited[MAXN];
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    for (int i = 1; i <= 3000; i++) {
      v1[i].clear();
      visited[i] = false;
      exists[i] = false;
    }
    for (int i = 1; i <= n; i++) {
      cin >> arr[i];
    }
    sort(arr + 1, arr + n + 1);
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= 3000; j++) {
        if (arr[i] % j == 0) {
          v1[j].push_back(i);
        }
      }
    }
    for (int i = 1; i <= 3000; i++) {
      sort(v1[i].rbegin(), v1[i].rend());
    }
    vector<int> res;
    res.push_back(arr[n]);
    int val = arr[n];
    visited[n] = true;
    while (true) {
      bool ok = false;
      for (int i = val; i >= 2; i--) {
        if (val % i == 0 && v1[i].size()) {
          for (int x : v1[i]) {
            if (!visited[x]) {
              ok = true;
              val = arr[x];
              res.push_back(arr[x]);
              visited[x] = true;
              break;
            }
          }
          if (ok) {
            break;
          }
        }
      }
      if (!ok) {
        break;
      }
    }
    for (int i = 1; i <= n; i++) {
      if (!visited[i]) {
        res.push_back(arr[i]);
      }
    }
    for (int x : res) {
      cout << x << " ";
    }
    cout << endl;
  }
}
