#include <bits/stdc++.h>
using namespace std;
int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
vector<pair<int, int> > v;
vector<int> now;
void dfs(int x, int num = 1) {
  if (x == v.size()) return now.push_back(num), void();
  for (int i = 0; i <= v[x].first; i++, num *= v[x].second) {
    dfs(x + 1, num);
  }
}
void mian() {
  int n;
  cin >> n;
  v.clear();
  for (int i = 2; i * i <= n; i++)
    if (n % i == 0) {
      v.push_back(make_pair(0, i));
      while (n % i == 0) v.back().first++, n /= i;
    }
  if (n > 1) v.push_back(make_pair(1, n));
  sort(v.begin(), v.end());
  if (v.size() == 2 && v[0].first == 1 && v[1].first == 1)
    return printf("%d %d %d\n%d\n", v[0].second, v[1].second,
                  v[0].second * v[1].second, 1),
           void();
  for (int i = 0; i < v.size(); i++) {
    now.clear();
    dfs(i + 1);
    vector<int> vv;
    for (int j = 0; j < now.size(); j++)
      for (int k = 1, o = v[i].second; k <= v[i].first; k++, o *= v[i].second)
        vv.push_back(now[j] * o);
    now = vv;
    for (int j = 0; j < now.size(); j++) {
      if (i + 1 < v.size() && now[j] == v[i].second * v[i + 1].second)
        swap(now[j], now.back());
      if (i == 0) {
        if (v.size() == 2 && now[j] == v[i].second * v[1].second * v[1].second)
          swap(now[j], now[0]);
        if (v.size() > 2 && now[j] == v[i].second * v.back().second)
          swap(now[j], now[0]);
      }
    }
    for (int j = 0; j < now.size(); j++)
      if (now[j]) printf("%d ", now[j]);
  }
  puts("\n0");
}
int main() {
  int testnum = 1;
  cin >> testnum;
  while (testnum--) mian();
  return 0;
}
