#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (a > b) swap(a, b);
  if (a == 0)
    return b;
  else
    return gcd(b % a, a);
}
long long check(multiset<long long> s, long long a) {
  long long mm = 0, p = 0;
  for (auto x : s) {
    long long tt = gcd(x, a);
    if (tt >= p) {
      p = tt;
      mm = x;
    }
  }
  return mm * 10000 + p;
}
int main() {
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    multiset<long long> s;
    long long mm = 0;
    for (long long i = 0; i < n; i++) {
      long long a;
      cin >> a;
      s.insert(a);
      if (a > mm) mm = a;
    }
    vector<long long> a(n), b(n);
    a[0] = mm;
    b[0] = mm;
    for (long long i = 1; i < n; i++) {
      s.erase(a[i - 1]);
      long long p = check(s, b[i - 1]);
      a[i] = p / 10000;
      b[i] = p % 10000;
    }
    for (auto x : a) cout << x << " ";
    cout << "\n";
  }
}
