#include <bits/stdc++.h>
using namespace std;
const int M = 200000;
int pp[M], qq[M + 1];
bool used[M + 1];
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n_;
    cin >> n_;
    int n = n_, np = 0;
    for (int p = 2; p <= n / p; p++)
      if (n % p == 0) {
        while (n % p == 0) n /= p;
        pp[np++] = p;
      }
    if (n > 1) pp[np++] = n;
    n = n_;
    int nq = 0;
    for (int q = 1; q <= n / q; q++)
      if (n % q == 0) {
        qq[nq++] = q;
        if (q < n / q) qq[nq++] = n / q;
      }
    if (np == 1) {
      for (int j = 1; j < nq; j++) cout << qq[j] << ' ';
      cout << '\n';
      cout << 0 << '\n';
      continue;
    }
    if (np == 2) {
      int p_ = pp[0] * pp[1];
      for (int j = 1; j < nq; j++) {
        int q = qq[j];
        if (q != pp[0] && q != p_ && q != pp[1]) cout << q << ' ';
      }
      cout << pp[0] << ' ' << p_ << ' ' << pp[1] << '\n';
      cout << (nq == 4 ? 1 : 0) << '\n';
      continue;
    }
    fill(used, used + nq, false);
    for (int i = 0; i < np; i++) {
      int p = pp[i], p_ = p * pp[(i + 1) % np];
      for (int j = 1; j < nq; j++) {
        int q = qq[j];
        if (q == p || q == p_) used[j] = true;
      }
    }
    for (int i = 0; i < np; i++) {
      int p = pp[i], p_ = p * pp[(i + 1) % np];
      for (int j = 1; j < nq; j++) {
        int q = qq[j];
        if (!used[j] && q % p == 0 && q != p && q != p_) {
          used[j] = true;
          cout << q << ' ';
        }
      }
      cout << p << ' ' << p_ << ' ';
    }
    cout << '\n';
    cout << 0 << '\n';
  }
  return 0;
}
