#include <bits/stdc++.h>
using namespace std;
int a[1100];
int gcd(int m, int n) {
  if (n == 0) return m;
  return gcd(n, m % n);
}
int main() {
  int T;
  cin >> T;
  int n;
  while (T--) {
    int vis[1100], Max = 0;
    ;
    cin >> n;
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
      Max = max(Max, a[i]);
      vis[i] = 0;
    }
    cout << Max << " ";
    for (int i = 1; i <= n; i++) {
      if (a[i] == Max) {
        vis[i] = 1;
        break;
      }
    }
    int Maxgcd = Max, cnt = 1;
    while (cnt < n) {
      int num = 0;
      for (int i = 1; i <= n; i++) {
        if (vis[i] == 1) continue;
        if (gcd(a[i], Maxgcd) > num) {
          num = gcd(a[i], Maxgcd);
        }
      }
      for (int i = 1; i <= n; i++) {
        if (vis[i] == 1) continue;
        if (gcd(a[i], Maxgcd) == num) {
          cout << a[i] << " ";
          vis[i] = 1;
          continue;
        }
      }
      Maxgcd = num;
      cnt++;
    }
    cout << endl;
  }
  return 0;
}
