#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
void merge(long long *arr, long long st, long long mid, long long ed,
           long long maxele) {
  long long i = st, j = mid + 1, k = st;
  while (i <= mid && j <= ed) {
    if (arr[i] % maxele <= arr[j] % maxele) {
      arr[k] = arr[k] + (arr[i] % maxele) * maxele;
      k++;
      i++;
    } else {
      arr[k] = arr[k] + (arr[j] % maxele) * maxele;
      k++;
      j++;
    }
  }
  while (i <= mid) {
    arr[k] = arr[k] + (arr[i] % maxele) * maxele;
    k++;
    i++;
  }
  while (j <= ed) {
    arr[k] = arr[k] + (arr[j] % maxele) * maxele;
    k++;
    j++;
  }
  for (long long i = st; i < ed + 1; i++) arr[i] = arr[i] / maxele;
}
void mergeSortRec(long long *arr, long long st, long long ed,
                  long long maxele) {
  if (st >= ed) return;
  long long mid = (st + ed) / 2;
  mergeSortRec(arr, st, mid, maxele);
  mergeSortRec(arr, mid + 1, ed, maxele);
  merge(arr, st, mid, ed, maxele);
}
void mergeSort(long long *arr, long long n) {
  long long maxele = *max_element(arr, arr + n) + 1;
  mergeSortRec(arr, 0, n - 1, maxele);
}
long long fact(long long n) {
  if (n <= 1) return 1;
  return ((n % 1000000007) * (fact(n - 1) % 1000000007)) % 1000000007;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    long long arr[n];
    for (long long i = 0; i < n; i++) cin >> arr[i];
    ;
    sort(arr, arr + n, greater<long long>());
    set<long long> s;
    s.insert(0);
    vector<long long> ans;
    long long g = arr[0];
    ans.push_back(arr[0]);
    long long next, temp;
    while (s.size() < n) {
      temp = INT_MIN;
      next = 0;
      for (long long i = 0; i < n; i++) {
        if (s.find(i) != s.end()) continue;
        temp = max(temp, gcd(g, arr[i]));
        if (temp == gcd(g, arr[i])) next = i;
      }
      g = temp;
      s.insert(next);
      ans.push_back(arr[next]);
    }
    cout << ans.size() << "\n";
    {
      for (long long i = 0; i < ans.size(); i++) cout << ans[i] << " ";
      cout << "\n";
    };
  }
  return 0;
}
