#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
  if (b != 0)
    return gcd(b, a % b);
  else
    return a;
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int n;
    scanf("%d", &n);
    int a[n], vis[n];
    for (int i = 0; i < n; i++) {
      scanf("%d", &a[i]);
    }
    for (int i = 0; i < n; i++) vis[i] = 0;
    sort(a, a + n);
    int b[n];
    b[0] = a[n - 1];
    int g = a[n - 1], l = -1;
    for (int i = n - 2; i >= 0; i--) {
      int ma = 0;
      for (int j = 0; j < n - 1; j++) {
        if (vis[j] == 0 && gcd(g, a[j]) > ma) {
          ma = gcd(g, a[j]);
          l = j;
        }
      }
      g = ma;
      b[n - i - 1] = a[l];
      vis[l] = 1;
    }
    for (int i = 0; i < n; i++) {
      printf("%d ", b[i]);
    }
    puts("");
  }
}
