#include <bits/stdc++.h>
using namespace std;
const long double pi = 3.14159265358979323846;
long long MOD = 1e9 + 7;
const char nl = '\n';
const long long inf = 1e15;
long long nxt() {
  long long x;
  cin >> x;
  return x;
}
long long mul(long long x, long long y) {
  return (1ll * (x % MOD) * (y % MOD));
}
long long modpow(long long x, long long y) {
  long long z = 1;
  while (y > 0) {
    if (y % 2) z = mul(z, x);
    x = mul(x, x);
    y /= 2;
  }
  return z;
}
long long power(long long x, long long y) {
  long long z = 1;
  while (y > 0) {
    if (y % 2) z = z * x;
    x = x * x;
    y /= 2;
  }
  return z;
}
long long gcd(long long a, long long b) {
  if (a < b) return gcd(b, a);
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long min(long long a, long long b) {
  if (a < b) return a;
  return b;
}
long long max(long long a, long long b) {
  if (a > b) return a;
  return b;
}
long long sq(long long a) {
  long long ans = (1ll * a * a);
  return ans;
}
void solve() {
  long long n;
  cin >> n;
  long long a[n];
  vector<long long> c(1001);
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    c[a[i]]++;
  }
  sort(a, a + n);
  reverse(a, a + n);
  long long b[n];
  b[0] = a[0];
  long long gc = a[0];
  c[a[0]]--;
  cout << a[0] << " ";
  for (long long i = (1); i <= n - 1; i++) {
    long long mx = 1;
    long long pos = -1;
    for (long long j = 1; j < n; j++) {
      if (c[a[j]]) {
        if (a[j] < mx) break;
        long long k = gcd(a[j], gc);
        if (k > mx) {
          mx = k;
          pos = j;
        }
      }
    }
    if (pos == -1) {
      for (long long i = 0; i < n; i++) {
        if (c[a[i]]) {
          cout << a[i] << " ";
          c[a[i]]--;
        }
      }
      break;
    }
    cout << a[pos] << " ";
    c[a[pos]]--;
    gc = mx;
  }
  cout << nl;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  long long TC = 1;
  cin >> TC;
  for (long long TT = 0; TT < TC; TT++) {
    solve();
  }
  cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC
       << "ms\n";
}
