#include <bits/stdc++.h>
using namespace std;
void fast_io() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long C(int n, int r) {
  float ans = 1;
  for (int i = 1; i <= r; i++) {
    ans *= ((double)n / i);
    n--;
  }
  return (long long)ans;
}
int main() {
  fast_io();
  int t = 1;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    vector<long long> div;
    for (int i = 2; i <= sqrt(n); i++) {
      if (n % i == 0) {
        if (i == n / i)
          div.push_back(i);
        else {
          div.push_back(i);
          div.push_back(n / i);
        }
      }
    }
    div.push_back(n);
    sort(div.begin(), div.end());
    unordered_map<int, int> vis;
    vector<long long> ans((int)div.size());
    ans[0] = div[0];
    vis[div[0]] = 1;
    for (int i = 1; i < div.size(); i++) {
      for (int j = 0; j < div.size(); j++) {
        if (vis[div[j]] == 0 && gcd(ans[i - 1], div[j]) > 1) {
          ans[i] = div[j];
          vis[div[j]] = 1;
          break;
        }
      }
    }
    for (int i = 0; i < (int)ans.size(); i += 1) cout << ans[i] << " ";
    cout << '\n';
    int vul = 0;
    if (gcd(ans[ans.size() - 1], ans[0]) == 1) vul++;
    cout << vul << '\n';
  }
}
