/**
 *  In the Name of God
 *  author: Behradm
 *  :| 
**/
#include <bits/stdc++.h>

using namespace std;

const int N = 1e3 + 2;
int a[N];

void doo() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  
  sort(a, a + n);
  reverse(a, a + n);
  vector<bool> use(n, 0);
  vector<int> b;
  int gcd = a[0];
  b.push_back(a[0]);
  use[0] = 1;

  while ((int) b.size() < n) {
    int id = -1, mx = 0;
    for (int i = 0; i < n; i++) {
      if (!use[i] && __gcd(gcd, a[i]) > mx) {
        mx = __gcd(gcd, a[i]);
        id = i;
      } 
    }
    use[id] = 1;
    b.push_back(a[id]);
  }

  for (int x : b)
    cout << x << " ";
  cout << '\n';
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  int tt;
  cin >> tt;
  while (tt--) doo();
  return 0;
}

