#include <bits/stdc++.h>
using namespace std;
long long po(long long a, long long b) {
  if (b == 0) return 1;
  long long ans = 1;
  if (b % 2 == 0) {
    ans = po(a, b / 2) % 1000000007;
    ans = (ans % 1000000007 * ans % 1000000007) % 1000000007;
  } else {
    ans = po(a, (b - 1) / 2) % 1000000007;
    ans = (ans % 1000000007 * ans % 1000000007 * a) % 1000000007;
  }
  return ans % 1000000007;
}
vector<string> tokens;
void separate_string(string line) {
  stringstream check1(line);
  string lav;
  while (getline(check1, lav, '*')) {
    tokens.push_back(lav);
  }
}
vector<long long> divisors;
void get_Divisors(long long n) {
  for (long long i = 1; i <= sqrt(n); i++) {
    if (n % i == 0) {
      if (n / i == i) {
        divisors.push_back(n / i);
      } else {
        divisors.push_back(i);
        divisors.push_back(n / i);
      }
    }
  }
}
void solve() {
  long long n, i, j;
  cin >> n;
  get_Divisors(n);
  long long temp = n;
  map<long long, long long> pu;
  set<long long> prim;
  while (temp % 2 == 0) {
    prim.insert(2);
    pu[2]++;
    temp = temp / 2;
  }
  for (i = 3; i <= sqrt(temp); i = i + 2) {
    while (temp % i == 0) {
      prim.insert(i);
      pu[i]++;
      temp = temp / i;
    }
  }
  if (temp > 2) {
    prim.insert(temp);
    pu[temp]++;
  }
  if (prim.size() == 2) {
    auto tt = prim.begin();
    auto xx = prim.end();
    auto zz = prim.end();
    long long pqr = (*tt);
    long long mno = (*(--xx));
    if (pu[pqr] == 1 && pu[mno] == 1) {
      xx = prim.end();
      cout << (*tt) << " ";
      cout << ((*tt) * (*(--xx))) << " ";
      cout << (*(--zz)) << " ";
      cout << endl;
      cout << "1" << endl;
      return;
    }
  }
  vector<long long> ans;
  auto x = prim.begin();
  ans.push_back(*x);
  i = 0;
  if (prim.size() == 2) {
    auto uuu = prim.end();
    --uuu;
    ans.push_back((*x) * (*uuu));
    ans.push_back((*uuu));
  } else {
    for (auto it = prim.begin(); it != prim.end(); it++) {
      i++;
      if (i == 1) {
        continue;
      } else if (i == prim.size()) {
        auto zzz = it;
        ans.push_back((*it) * (*(--zzz)));
        ans.push_back(*it);
        ans.push_back((*it) * (*x));
      } else {
        auto zzz = it;
        ans.push_back((*it) * (*(--zzz)));
        ans.push_back(*it);
      }
    }
  }
  map<long long, long long> make_pair;
  for (i = 0; i < ans.size(); i++) {
    make_pair[ans[i]] = 1;
  }
  make_pair[1] = 1;
  vector<long long> bache;
  for (i = 0; i < divisors.size(); i++) {
    if (make_pair[divisors[i]] == 0) {
      bache.push_back(divisors[i]);
    }
  }
  if (ans.size() == 1) {
    cout << ans[0] << " ";
    for (j = 0; j < bache.size(); j++) {
      if (make_pair[bache[j]] == 0 && bache[j] % ans[0] == 0) {
        cout << bache[j] << " ";
        make_pair[bache[j]] = 1;
      }
    }
    cout << endl;
    cout << "0" << endl;
    return;
  }
  vector<long long> final;
  int ftr = 0;
  for (i = 0; i < ans.size(); i += 1) {
    if (i % 2) {
      continue;
    }
    final.push_back(ans[i]);
    for (j = 0; j < bache.size(); j++) {
      if (make_pair[bache[j]] == 0 && bache[j] % ans[i] == 0) {
        final.push_back(bache[j]);
        make_pair[bache[j]] = 1;
      }
    }
    if (i != ans.size() - 1) final.push_back(ans[i + 1]);
  }
  if (prim.size() == 2) {
    final.push_back(final[1]);
    for (i = 0; i < final.size(); i++) {
      if (i != 1) {
        cout << final[i] << " ";
      }
    }
    cout << endl;
    cout << "0" << endl;
    return;
  }
  for (auto it : final) {
    cout << it << " ";
  }
  cout << endl;
  cout << "0" << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    divisors.clear();
    solve();
  }
}
