#include <bits/stdc++.h>
using namespace std;
int a[1000];
int b[1000];
int c[1000];
int mcd(int a, int b);
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    sort(a, a + n);
    reverse(a, a + n);
    int pos;
    for (int i = 0; i < n - 1; i++) {
      int mayor = 0;
      for (int j = i + 1; j < n; j++) {
        if (mcd(a[i], a[j]) > mayor) {
          mayor = mcd(a[i], a[j]);
          pos = j;
        }
      }
      swap(a[i + 1], a[pos]);
    }
    for (int i = 0; i < n; i++) {
      cout << a[i] << " ";
    }
    cout << endl;
  }
}
int mcd(int a, int b) {
  if (b == 0) return a;
  return mcd(b, a % b);
}
