#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t;
  cin >> t;
  while (t--) {
    long long int n;
    cin >> n;
    long long int a[n];
    for (int i = 0; i < n; i++) cin >> a[i];
    sort(a, a + n);
    vector<long long int> v;
    v.push_back(a[n - 1]);
    long long int p = a[n - 1];
    long long int val;
    a[n - 1] = -1;
    for (int i = 0; i < n - 1; i++) {
      long long int an = 0;
      for (int j = 0; j < n; j++) {
        if (a[j] == -1) continue;
        long long int k = gcd(p, a[j]);
        if (k > an) {
          an = k;
          val = j;
          ;
        }
      }
      v.push_back(a[val]);
      a[val] = -1;
      p = an;
    }
    for (auto u : v) cout << u << " ";
    cout << "\n";
  }
}
