#include <bits/stdc++.h>
inline long long read() {
  long long x = 0, f = 1;
  char c = getchar();
  for (; c > '9' || c < '0'; c = getchar()) {
    if (c == '-') f = -1;
  }
  for (; c >= '0' && c <= '9'; c = getchar()) {
    x = x * 10 + c - '0';
  }
  return x * f;
}
bool flag[1005];
int a[1005];
std::vector<int> ans;
int gcd(int aa, int b) { return !b ? aa : gcd(b, aa % b); }
inline void work() {
  for (int t = read(); t; t--) {
    int n = read();
    for (int i = 1; i <= n; i++) a[i] = read();
    std::sort(a + 1, a + n + 1, [](int a, int b) { return a > b; });
    ans.clear();
    ans.emplace_back(a[1]);
    std::fill(flag + 1, flag + n + 1, false);
    flag[1] = true;
    int g = a[1];
    for (int i = 2; i <= n; i++) {
      int max = 0, pos = -1;
      for (int j = 1; j <= n; j++) {
        if (flag[j]) continue;
        if (gcd(g, a[j]) > max) {
          max = gcd(g, a[j]);
          pos = j;
        }
      }
      ans.emplace_back(a[pos]);
      flag[pos] = true;
      g = gcd(g, a[pos]);
    }
    for (int i = 0; i < ans.size(); i++)
      printf("%d%c", ans[i], i == n - 1 ? '\n' : ' ');
  }
}
int main() {
  work();
  return 0;
}
