#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10, NN = 2e3 + 10, INF = 0x3f3f3f3f, LEN = 20;
const long long MOD = 1e9 + 7;
const unsigned long long seed = 31;
inline long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 1) + (x << 3) + (ch ^ 48);
    ch = getchar();
  }
  return x * f;
}
int n, a[N], vis[N];
bool cmp(int a, int b) { return a > b; }
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    memset(vis, 0, sizeof vis);
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
    sort(a, a + n, cmp);
    printf("%d", a[0]);
    vis[0] = 1;
    int maxx, pos, temp = a[0], cnt = 1;
    while (cnt < n) {
      if (temp == 1) {
        for (int i = 1; i < n; ++i) {
          if (vis[i] == 0) printf(" %d", a[i]);
        }
        break;
      }
      maxx = 0;
      for (int i = 1; i < n; ++i) {
        if (vis[i]) continue;
        int tmp = gcd(max(temp, a[i]), min(temp, a[i]));
        if (tmp > maxx) {
          maxx = tmp;
          pos = i;
        }
      }
      cnt++;
      printf(" %d", a[pos]);
      vis[pos] = 1;
      temp = maxx;
    }
    printf("\n");
  }
  return 0;
}
