#include <bits/stdc++.h>
int t, n, a[1001], cnt[1001], imax = 0;
void deal(int x, int g) {
  for (int i = 1; i <= cnt[x]; i++) printf("%d ", x);
  cnt[x] = 0;
  int r = 0;
  for (int i = 1; i * i <= g; i++)
    if (x % i == 0) {
      int u = g / i;
      for (int j = imax - u; j > 0; j -= u) {
        if (cnt[j]) {
          deal(j, u);
          r++;
        }
      }
      if (r) return;
    }
  int s = sqrt(g);
  for (int i = s; i >= 2; i--)
    if (x % i == 0) {
      for (int j = imax - i; j > 0; j -= i) {
        if (cnt[j]) {
          deal(j, i);
          r++;
        }
      }
      if (r) return;
    }
  return;
}
int main() {
  scanf("%d", &t);
  while (t--) {
    scanf("%d", &n);
    for (int i = 1; i <= 1000; i++) cnt[i] = 0;
    for (int i = 1; i <= n; i++) {
      scanf("%d", &a[i]);
      cnt[a[i]]++;
    }
    imax = 0;
    for (int i = 1000; i >= 1; i--) {
      if (imax > 0) {
        for (int j = 1; j <= cnt[i]; j++) printf("%d ", i);
        cnt[i] = 0;
      } else if (cnt[i] > 0) {
        imax = i;
        deal(i, i);
      }
    }
    puts("");
  }
  return 0;
}
