#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
bool cmp(int X, int Y) { return X > Y; }
long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; }
long long modpow(long long a, long long b, long long m = MOD) {
  a %= m;
  long long res = 1;
  while (b) {
    if (b & 1) res = (res * a) % m;
    a = (a * a) % m;
    b >>= 1;
  }
  return res;
}
long long bpow(long long a, long long b) {
  if (b < 0) {
    return 0;
  }
  long long res = 1;
  while (b) {
    if (b & 1) res = res * a;
    a = a * a;
    b >>= 1;
  }
  return res;
}
const int N = 1e7 + 2;
bool present[1005];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    long long a[n];
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      present[a[i]] = 1;
    }
    sort(a, a + n);
    long long gd = a[n - 1];
    present[a[n - 1]] = 0;
    vector<long long> ans;
    ans.push_back(a[n - 1]);
    for (long long i = 0; i < n - 1; i++) {
      long long prev = 0;
      long long pos = -1;
      for (long long j = 0; j < n; j++) {
        if (present[a[j]]) {
          long long k = gcd(gd, a[j]);
          if (k > prev) {
            prev = k;
            pos = a[j];
          }
        }
      }
      for (int j = 0; j < n; j++) {
        long long p = gcd(gd, a[j]);
        if (present[a[j]] && p == prev) {
          present[a[j]] = 0;
          ans.push_back(a[j]);
          break;
        }
      }
      if (prev > 0) {
        gd = prev;
      }
    }
    for (int i = 0; i < (int)ans.size(); i++) {
      cout << ans[i] << " ";
    }
    cout << '\n';
  }
}
