#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int gcd(int x, int y) {
  if (y == 1) return 1;
  if (x % y == 0)
    return y;
  else
    return gcd(y, x % y);
}
int main() {
  int t;
  cin >> t;
  int a[N];
  while (t--) {
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    sort(a + 1, a + n + 1, greater<int>());
    for (int i = 1; i < n; i++) {
      int ma = 0, mi;
      for (int j = i + 1; j <= n; j++)
        if (gcd(a[i], a[j]) > ma) ma = gcd(a[i], a[j]), mi = j;
      swap(a[i + 1], a[mi]);
    }
    for (int i = 1; i <= n; i++)
      if (i == n)
        cout << a[i] << endl;
      else
        cout << a[i] << ' ';
  }
  return 0;
}
