#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n;
  cin >> n;
  map<long long, long long> pd;
  set<long long, greater<long long> > d;
  for (long long i = 1; i * i <= n; ++i)
    if (n % i == 0) {
      d.insert(i);
      d.insert(n / i);
    }
  d.erase(1);
  for (long long i = 2; i * i <= n; ++i)
    while (n % i == 0) {
      n /= i;
      ++pd[i];
    }
  if (n > 1) ++pd[n];
  bool one = pd.size() == 2 && d.size() == 3;
  long long last = (pd.begin()->first) * ((--pd.end())->first);
  for (auto p : pd) {
    long long x = 1;
    for (long long i = 0; i < (long long)p.second; ++i) {
      x *= p.first;
      cout << x << " ";
      d.erase(x);
    }
    auto it = d.begin();
    while (it != d.end()) {
      if ((*it) % p.first == 0 && (*it) != last) {
        cout << (*it) << " ";
        it = d.erase(it);
      } else
        ++it;
      if (it == d.end()) break;
    }
  }
  if (pd.size() > 1) cout << last;
  cout << "\n" << one << "\n";
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  for (long long i = 0; i < (long long)t; ++i) solve();
  return 0;
}
