#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vpii = vector<pii>;
using vpll = vector<pll>;
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  for (const auto& x : v) os << x << " ";
  return os << endl;
}
ll ceil_div(ll a, ll b) { return (a + b - 1) / b; }
void primes(int n, std::vector<int>& p, std::vector<int>& e) {
  for (int i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      p.push_back(i);
      int exponent = 0;
      while (n % i == 0) {
        n /= i;
        ++exponent;
      }
      e.push_back(exponent);
    }
  }
  if (n > 1) {
    p.push_back(n);
    e.push_back(1);
  }
}
void dfs(int curIdx, int curVal, int parIdx, const std::vector<int>& p,
         const std::vector<int>& e, std::vector<std::vector<int>>& d) {
  if (curIdx == p.size()) {
    if (parIdx == -1) return;
    if (p.size() >= 2 && curVal == p[0] * p.back()) return;
    d[parIdx].push_back(curVal);
    return;
  }
  dfs(curIdx + 1, curVal, parIdx, p, e, d);
  for (int i = 1; i <= e[curIdx]; ++i) {
    curVal *= p[curIdx];
    dfs(curIdx + 1, curVal, parIdx == -1 ? curIdx : parIdx, p, e, d);
  }
};
void solve(int n) {
  std::vector<int> p, e;
  primes(n, p, e);
  const int k = p.size();
  std::vector<std::vector<int>> d(k);
  if (k >= 2) d.back().push_back(p[0] * p.back());
  dfs(0, 1, -1, p, e, d);
  int ans = k == 2 && e[0] == 1 && e[1] == 1;
  for (int i = 0; i < k; ++i) {
    for (auto& x : d[i])
      if (x % p[(i + 1) % k] == 0) std::swap(x, d[i].back());
    for (auto x : d[i]) std::cout << x << " ";
  }
  std::cout << endl;
  std::cout << ans << endl;
}
int main(int argc, char const* argv[]) {
  int T;
  cin >> T;
  for (int t = 0; t < T; t++) {
    int n;
    cin >> n;
    solve(n);
  }
  return 0;
}
