#include <bits/stdc++.h>
using namespace std;
long long n, ck, t, cntA, cntP;
void helpMeBro() {
  cin >> n;
  vector<long long> allDivisors;
  for (long long i = 2; i * i <= n; ++i)
    if (n % i == 0) {
      allDivisors.push_back(i);
      if (i * i != n) allDivisors.push_back(n / i);
    }
  allDivisors.push_back(n);
  vector<long long> primeDivisors;
  ck = n;
  for (long long i = 2; i * i <= ck; ++i) {
    if (ck % i == 0) primeDivisors.push_back(i);
    while (ck % i == 0) ck /= i;
  }
  if (ck != 1) primeDivisors.push_back(ck);
  cntA = allDivisors.size();
  cntP = primeDivisors.size();
  if (cntP == 1) {
    for (long long a : allDivisors) cout << a << " ";
    cout << "\n0\n";
    return;
  }
  vector<long long> ans[cntP];
  bool ok[cntA];
  for (long long i = 0; i < cntA; i++) ok[i] = false;
  for (long long j = 0; j < cntP; j++) {
    for (long long i = 0; i < cntA; i++) {
      if (!ok[i] && allDivisors[i] % primeDivisors[j] == 0) {
        ans[j].push_back(allDivisors[i]);
        ok[i] = true;
      }
    }
  }
  if (cntA == 3) {
    cout << primeDivisors[0] << " " << primeDivisors[1] << " " << n << "\n1\n";
    return;
  }
  for (long long i = 0; i < cntP; i++) {
    cout << primeDivisors[i] << " ";
    for (long long j = 0; j < ans[i].size(); j++)
      if (ans[i][j] != n && ans[i][j] != primeDivisors[i] &&
          ans[i][j] != primeDivisors[i] * primeDivisors[(i + 1) % cntP])
        cout << ans[i][j] << " ";
    if (i + 1 != cntP)
      cout << primeDivisors[i] * primeDivisors[(i + 1) % cntP] << " ";
    else
      cout << n << "\n0\n";
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> t;
  for (long long i = 0; i < t; i++) helpMeBro();
  return 0;
}
