#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int MAXN = 3e5 + 5;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    map<int, int> m;
    vector<int> primes;
    while (n % 2 == 0) {
      n /= 2;
      primes.push_back(2);
    }
    for (int i = 3; i <= sqrt(n); i += 2) {
      while (n % i == 0) {
        n /= i;
        primes.push_back(i);
      }
    }
    if (n > 2) primes.push_back(n);
    sort(primes.begin(), primes.end());
    vector<int> factors;
    if (primes.size() == 2 && primes[0] != primes[1]) {
      cout << primes[0] << " " << primes[1] << " " << primes[0] * primes[1]
           << "\n"
           << 1 << "\n";
    } else {
      factors.push_back(1);
      for (int i = 0; i < primes.size(); i++) {
        int len = factors.size();
        if (i != 0) {
          if (m[primes[i] * primes[i - 1]] == 0) {
            factors.push_back(primes[i] * primes[i - 1]);
            m[primes[i] * primes[i - 1]] = 1;
          }
        }
        for (int j = 0; j < len; j++) {
          int prod = factors[j] * primes[i];
          if (m.count(prod) == 0) {
            m[prod] = 1;
            factors.push_back(prod);
          }
        }
      }
      for (int i = 1; i < factors.size(); i++) cout << factors[i] << " ";
      cout << "\n";
      cout << 0;
      cout << "\n";
    }
  }
}
