#include <bits/stdc++.h>
#pragma GCC diagnostic ignored "-Wunused-const-variable"
#pragma GCC diagnostic ignored "-Wsign-conversion"
#pragma GCC diagnostic ignored "-Wsign-compare"
using namespace std;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-7;
const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, 1, -1};
const int RT = 3;
const int MOD = 998244353;
const int MAXN = 2000005;
int a[MAXN], p[MAXN];
int gcd(int x, int y) {
  if (!x || !y)
    return x + y;
  else
    return gcd(y, x % y);
}
void solve() {
  int n;
  scanf("%d", &n);
  memset(p + 1, 0, 1000 * sizeof(p[0]));
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  sort(a + 1, a + 1 + n);
  int g = a[n];
  for (int i = n; i; i--) {
    int mx = 0, mi = 0;
    for (int j = n; j; j--) {
      if (!a[j]) continue;
      if (gcd(g, a[j]) > mx) {
        mx = gcd(g, a[j]);
        mi = j;
      }
    }
    printf("%d ", a[mi]);
    a[mi] = 0;
    g = mx;
  }
  puts("");
}
int main() {
  int T = 1, cas = 1;
  (void)(cas);
  scanf("%d", &T);
  while (T--) {
    solve();
  }
  return 0;
}
