#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long int n;
  cin >> n;
  set<long long int> pf, f;
  long long int nn = n;
  while (nn % 2 == 0) {
    nn /= 2;
    pf.insert(2);
  }
  for (long long int i = 3; i <= (long long int)sqrt(nn); i += 2) {
    while (nn % i == 0) {
      nn /= i;
      pf.insert(i);
    }
  }
  if (nn > 2) pf.insert(nn);
  vector<long long int> pff;
  for (long long int i : pf) pff.push_back(i);
  pff.push_back(*pf.begin());
  for (long long int i = 1; i <= (long long int)sqrt(n); i++) {
    if (n % i == 0) {
      f.insert(i);
      f.insert(n / i);
    }
  }
  f.erase(1);
  for (long long int i : pf) f.erase(i);
  long long int ans = 0;
  unordered_map<long long int, vector<long long int>> multiples;
  unordered_map<long long int, bool> avail;
  unordered_map<long long int, long long int> fx;
  for (long long int i = 0; i < pff.size() - 1; i++) {
    long long int x = pff[i] * pff[i + 1];
    bool flg = true;
    for (long long int j : f) {
      if (j % x == 0) {
        avail[pff[i]] = true;
        fx[pff[i]] = j;
        f.erase(j);
        flg = false;
        break;
      }
    }
    if (flg) {
      avail[pff[i]] = false;
      ans++;
    }
  }
  for (long long int i : pf) {
    for (long long int j : f) {
      if (j % i == 0) multiples[i].push_back(j);
    }
    for (long long int j : multiples[i]) f.erase(j);
  }
  for (long long int i = 0; i < pff.size() - 1; i++) {
    cout << pff[i] << " ";
    for (long long int j : multiples[pff[i]]) cout << j << " ";
    if (avail[pff[i]]) cout << fx[pff[i]] << " ";
  }
  cout << "\n";
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  cin >> t;
  while (t--) solve();
  return 0;
}
