#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int i, t;
  cin >> t;
  for (i = 0; i < t; i++) {
    long long int n, j = 2;
    cin >> n;
    vector<long long int> a, c, a1;
    long long int n1 = n;
    for (j = 2; j <= sqrt(n); j++) {
      if (n % j == 0) {
        a1.push_back(j);
        if (j != n / j) a1.push_back(n / j);
      }
    }
    sort(a1.begin(), a1.end());
    j = 2;
    while ((n1 > 1) & (j * j <= n)) {
      if (n1 % j == 0) {
        a.push_back(j);
        while (n1 % j == 0) {
          n1 /= j;
        }
      }
      j++;
    }
    if (n1 != 1) a.push_back(n1);
    long long int k, b;
    map<long long int, vector<long long int>> m;
    for (j = 0; j < a1.size(); j++) {
      auto g = std::find(a.begin(), a.end(), a1[j]);
      if (g != a.end()) {
        m[a1[j]].push_back(a1[j]);
        continue;
      }
      for (long long int k = 2; k <= sqrt(a1[j]); k++) {
        if (a1[j] % k == 0) {
          m[k].push_back(a1[j]);
          break;
        }
      }
    }
    for (map<long long int, vector<long long int>>::iterator g1 = m.begin();
         g1 != m.end(); g1++) {
      long long int h = 0;
      for (long long int k = 0; k < m[g1->first].size(); k++) {
        auto g = lower_bound(a.begin(), a.end(), g1->first);
        long long int v = g - a.begin();
        if ((long long int)(m[g1->first][k]) == a[v] * a[(v + 1) % a.size()])
          h = m[g1->first][k];
        else
          c.push_back(m[g1->first][k]);
      }
      if (h > 0) c.push_back(h);
    }
    c.push_back(n);
    for (j = 0; j < c.size(); j++) cout << c[j] << " ";
    cout << '\n';
    if (a.size() == 1)
      cout << '0' << '\n';
    else if ((a.size() == 2) && (a1.size() == 2))
      cout << '1' << '\n';
    else
      cout << '0' << '\n';
  }
  return 0;
}
