#include <bits/stdc++.h>
using namespace std;
int64_t gcd(int64_t x, int64_t y) {
  if (x < y) {
    swap(x, y);
  }
  if (y == 0) {
    return x;
  }
  return gcd(y, x % y);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int64_t tc;
  cin >> tc;
  for (int64_t tt = 0; tt < tc; tt++) {
    int64_t n;
    cin >> n;
    set<int64_t> s;
    for (int64_t i = 0; i < n; i++) {
      int64_t x;
      cin >> x;
      s.insert(x);
    }
    int64_t x = (*s.rbegin());
    s.erase(x);
    while (s.size() > 0) {
      cout << x << " ";
      int64_t nxt = 0;
      int64_t mx = -1;
      for (auto e : s) {
        int64_t crt = gcd(x, e);
        if (mx <= crt) {
          mx = crt;
          nxt = e;
        }
      }
      x = nxt;
      s.erase(x);
    }
    cout << x << endl;
  }
  return 0;
}
