#include <bits/stdc++.h>
using namespace std;
int cnt[200];
vector<int> vec[200];
vector<int> pfac, fac;
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    pfac.clear();
    fac.clear();
    for (int i = 0; i < 200; i++) {
      cnt[i] = 0;
      vec[i].clear();
    }
    int n;
    scanf("%d", &n);
    for (int i = 1; i * i <= n; i++) {
      if (n % i == 0) {
        if (i > 1) fac.push_back(i);
        if (i * i != n) fac.push_back(n / i);
      }
    }
    int temp = n;
    for (int i = 2; i <= sqrt(n); i++) {
      if (temp % i == 0) {
        pfac.push_back(i);
        while (temp % i == 0) {
          cnt[pfac.size() - 1]++;
          temp /= i;
        }
      }
    }
    if (temp > 1) pfac.push_back(temp);
    sort(fac.begin(), fac.end());
    if (pfac.size() == 2 && pfac[0] * pfac[1] == n) {
      printf("%d %d %d\n", pfac[0], pfac[1], n);
      printf("1\n");
      continue;
    }
    if (pfac.size() == 1) {
      for (int i = 0; i < fac.size(); i++)
        printf("%d%c", fac[i], (i == fac.size() - 1) ? '\n' : ' ');
      printf("0\n");
      continue;
    }
    for (auto x : fac) {
      if (x == n) break;
      for (int i = 0; i < pfac.size(); i++) {
        if (x % pfac[i] == 0) {
          if (x == pfac[i] * pfac[i + 1]) break;
          vec[i].push_back(x);
          break;
        }
      }
    }
    for (int i = 0; i + 1 < pfac.size(); i++) {
      vec[i].push_back(pfac[i] * pfac[i + 1]);
    }
    for (int i = 0; i < pfac.size(); i++) {
      for (auto x : vec[i]) printf("%d ", x);
    }
    printf("%d\n", n);
    printf("0\n");
  }
}
