#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
  if (b == 0) {
    return a;
  }
  return gcd(b, a % b);
}
void solve() {
  int n;
  cin >> n;
  int a[2000];
  int amax = -1;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    if (a[i] > amax) {
      amax = a[i];
    }
  }
  for (int i = 0; i < n; ++i) {
    if (a[i] == amax) {
      a[i] = -1;
    }
  }
  cout << amax << " ";
  int g = amax;
  for (int i = 0; i < n - 1; ++i) {
    int best = -1;
    int bestj = -1;
    int bestv = -1;
    for (int j = 0; j < n; ++j) {
      if (a[j] == -1) {
        continue;
      }
      if (gcd(a[j], g) > best) {
        best = gcd(a[j], g);
        bestj = j;
        bestv = a[j];
      }
    }
    a[bestj] = -1;
    g = best;
    cout << bestv << " ";
  }
  cout << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  for (int i = 0; i < t; ++i) {
    solve();
  }
  return 0;
}
