#include <bits/stdc++.h>
using namespace std;
const int M = 1010;
int a[M], vis[M];
int gcd(int a, int b) { return !b ? a : gcd(b, a % b); }
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int n;
    scanf("%d", &n);
    int maxn = 0;
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]), maxn = max(maxn, a[i]);
    printf("%d ", maxn);
    for (int i = 1; i <= n; i++) {
      if (maxn == a[i]) {
        vis[i] = 1;
        break;
      }
    }
    int cnt = 1;
    while (cnt < n) {
      int gg = 0, k;
      for (int i = 1; i <= n; i++) {
        if (vis[i]) continue;
        int g = gcd(maxn, a[i]);
        if (g > gg) {
          gg = g;
          k = i;
        } else if (g == gg) {
          if (a[k] < a[i]) k = i;
        }
      }
      maxn = a[k];
      vis[k] = 1;
      cnt++;
      printf("%d ", maxn);
    }
    for (int i = 1; i <= n; i++) vis[i] = 0;
    printf("\n");
  }
  return 0;
}
