#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  long long x = a, y = b;
  a = max(x, y);
  b = min(x, y);
  if (b == 0) return a;
  return gcd(b, a % b);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  long long t;
  cin >> t;
  while (--t >= 0) {
    long long n, i, j, x, y, sum = 0;
    cin >> n;
    long long n1 = 0;
    vector<long long> v(n);
    for (i = 0; i < n; ++i) cin >> v[i];
    sort(v.begin(), v.end(), greater<long long>());
    vector<long long> ans(n), c(n);
    c[0] = v[0];
    ans[0] = v[0];
    for (i = 1; i < n; ++i) {
      long long ma = -1, mj = 0;
      for (j = i; j < n; ++j) {
        x = gcd(c[i - 1], v[j]);
        if (x > ma) {
          ma = x;
          mj = j;
        } else if (x == ma && v[j] < v[mj]) {
          ma = x;
          mj = j;
        }
      }
      ans[i] = v[mj];
      c[i] = gcd(c[i - 1], v[mj]);
      swap(v[i], v[mj]);
    }
    for (i = 0; i < n; ++i) cout << ans[i] << " ";
    cout << endl;
  }
  return 0;
}
