#include <bits/stdc++.h>
using namespace std;
const long long MaxN = 1e5 + 7;
const long long MaxM = 1e2 + 7;
const long long MDL = 1e9 + 7;
const long long INF = 1e18 + 7;
typedef long long arr[MaxN];
long long REPIT = 1;
const bool MQ = true;
long long n;
void Solve() {
  vector<long long> divs, pr;
  cin >> n;
  long long temp = n;
  for (long long i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      long long c = 0;
      while (temp % i == 0) {
        temp /= i;
        ++c;
      }
      if (c >= 1) pr.push_back(i);
      divs.push_back(i);
      if (i * i != n) divs.push_back(n / i);
    }
  }
  vector<long long> r;
  if (temp > 1) pr.push_back(temp);
  set<long long> dne;
  long long m = pr.size();
  for (long long i = m - 2; i >= 0; --i) dne.insert(pr[i] * pr[i + 1]);
  for (long long i = m - 1; i >= 0; --i) {
    if (i + 1 == m) {
      r.push_back(n);
      cout << n << ' ';
      dne.insert(n);
    } else {
      if (pr[i] * pr[i + 1] != n) {
        r.push_back(pr[i] * pr[i + 1]);
        cout << pr[i] * pr[i + 1] << ' ';
      }
    }
    for (long long v : divs) {
      if (v % pr[i] == 0 && dne.count(v) == 0) {
        r.push_back(v);
        cout << v << ' ';
        dne.insert(v);
      }
    }
  }
  if (temp > 1 && dne.size() == 3)
    cout << '\n' << 1 << '\n';
  else
    cout << '\n' << 0 << '\n';
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  if (MQ == true) {
    cin >> REPIT;
    cin.ignore();
    ;
  }
  while (REPIT--) Solve();
  cout.flush();
}
