#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 5;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t, n;
  cin >> t;
  while (t--) {
    cin >> n;
    vector<int> facts, primes;
    for (int i = 2; i * i <= n; i++) {
      if (n % i == 0) {
        facts.push_back(i), facts.push_back(n / i);
      }
      if (i * i == n) facts.pop_back();
    }
    facts.push_back(n);
    int temp = n;
    for (int i = 2; i * i <= temp; i++) {
      if (temp % i == 0) {
        primes.push_back(i);
        while (temp % i == 0) temp /= i;
      }
    }
    if (temp != 1) primes.push_back(temp);
    if (primes.size() == 1) {
      for (auto i : facts) cout << i << ' ';
      cout << "\n0\n";
      continue;
    }
    map<int, bool> vis;
    for (int i = 0; i < primes.size(); i++) {
      cout << primes[i] << ' ';
      int after = primes[i] * primes[(i + 1) % primes.size()];
      for (auto j : facts)
        if (j != primes[i] && !vis[j] && j % primes[i] == 0 && j != after &&
            !(i == 0 && primes.size() > 2 && primes[i] * primes.back() == j))
          cout << j << ' ', vis[j] = 1;
      if (!vis[after] && primes.size() != 2)
        cout << after << ' ', vis[after] = 1;
    }
    if (primes.size() == 2) cout << primes[0] * primes[1];
    cout << endl << (primes.size() == 2 && facts.size() == 3 ? 1 : 0) << endl;
  }
  return 0;
}
