#include <bits/stdc++.h>
using namespace std;
vector<int> mp, p;
void dfs(int x) {
  vector<int> tmp = mp;
  if (tmp.empty())
    tmp.push_back(1);
  else
    tmp.insert(tmp.end() - 1, 1);
  reverse(tmp.begin(), tmp.end());
  while (1) {
    for (auto ppp : tmp) {
      mp.push_back(ppp * p[x]);
    }
    x++;
    if (x == p.size()) return;
    if (p[x - 1] % p[x] == 0) {
      p[x] *= p[x - 1];
      reverse(tmp.begin(), tmp.end());
    } else {
      break;
    }
  }
  dfs(x);
}
int main() {
  int T, n;
  cin >> T;
  while (T--) {
    scanf("%d", &n);
    mp.clear();
    p.clear();
    for (int i = 2; i * i <= n; i++) {
      while (n % i == 0) {
        p.push_back(i);
        n /= i;
      }
    }
    if (n != 1) p.push_back(n);
    if (p.size() == 2 && p[0] != p[1]) {
      cout << p[0] << " " << p[1] << " " << p[0] * p[1];
      cout << endl;
      cout << "1" << endl;
      continue;
    }
    dfs(0);
    for (int i = 0; i < mp.size(); i++) {
      printf("%d ", mp[i]);
    }
    cout << endl;
    cout << "0" << endl;
  }
  return 0;
}
