#include <bits/stdc++.h>
using namespace std;
const long long N = 1000005, mod = 1000000007, M = 1005;
const long long inf = 1000000000000000000;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
long long n, m, k, i, j, ans, kaskad[N], cnt[N];
void solve() {
  cin >> n;
  vector<long long> div;
  for (int i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      div.push_back(i);
      if (i * i == n) {
        continue;
      }
      div.push_back(n / i);
    }
  }
  div.push_back(n);
  vector<bool> used(div.size(), false);
  sort(div.begin(), div.end());
  m = n;
  vector<long long> p;
  for (int i = 2; i * i <= m; ++i) {
    if (m % i == 0) {
      p.push_back(i);
      while (m % i == 0) {
        m /= i;
      }
    }
  }
  if (m != 1) {
    p.push_back(m);
  }
  sort(p.begin(), p.end());
  for (int i = 0; i < p.size() - 1; ++i) {
    for (int j = 0; j < div.size(); ++j) {
      if (div[j] % p[i] == 0 && div[j] != p[i] * p[i + 1] && div[j] != n &&
          !used[j]) {
        cout << div[j] << " ";
        used[j] = true;
      }
      if (div[j] == p[i] * p[i + 1]) {
        used[j] = true;
      }
    }
    cout << p[i] * p[i + 1] << " ";
  }
  for (int j = 0; j < div.size(); ++j) {
    if (!used[j]) {
      cout << div[j] << " ";
    }
  }
  cout << '\n';
  if (div.size() == 3 && p.size() == 2) {
    cout << 1 << '\n';
    return;
  }
  cout << 0 << '\n';
}
int main(int argc, char* argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int tests = 1;
  cin >> tests;
  while (tests--) {
    solve();
  }
  return 0;
}
