#include <bits/stdc++.h>
using namespace std;
int n;
map<int, int> m;
vector<int> g;
void f(int cur, int cnt, map<int, int>::iterator it) {
  if (cnt == int(m.size())) {
    g.push_back(cur);
    return;
  }
  int val = cur;
  if (cnt) f(val, cnt + 1, next(it, 1));
  int x = it->second;
  while (x) {
    val *= it->first;
    f(val, cnt + 1, next(it, 1));
    x--;
  }
}
void dis(vector<int> &v) {
  for (int i = 0; i < int(v.size()); i++) cout << v[i] << " ";
  cout << "\n";
}
void solve() {
  cin >> n;
  int x = n;
  m.clear();
  for (int i = 2; i * i <= x; i++)
    if (x % i == 0) {
      while (x % i == 0) {
        x /= i;
        m[i]++;
      }
    }
  if (x > 1) m[x]++;
  if (int(m.size()) == 2) {
    if (m.begin()->second == 1 && next(m.begin(), 1)->second == 1) {
      int a = m.begin()->first, b = next(m.begin(), 1)->first;
      cout << a << " " << b << " " << a * b << "\n1\n";
      return;
    }
  }
  vector<int> res;
  map<int, int> temp = m;
  for (auto it = temp.begin(); it != temp.end(); it++) {
    f(1, 0, m.begin());
    m.erase(it->first);
    int val = (m.empty() ? 0 : (it->first * (m.begin()->first)));
    for (int i = 0; i < int(g.size()); i++) {
      if (g[i] == n || g[i] == val) continue;
      res.push_back(g[i]);
    }
    if (val) res.push_back(val);
    g.clear();
  }
  res.push_back(n);
  dis(res);
  cout << "0\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  clock_t z = clock();
  int qc = 1;
  cin >> qc;
  for (int i = 1; i <= qc; i++) {
    solve();
  }
  fprintf(stderr, "Total Time:%.4Lf\n",
          (long double)(clock() - z) / CLOCKS_PER_SEC),
      fflush(stderr);
}
