#include <bits/stdc++.h>
using namespace std;
int t;
int n;
struct Factor {
  int p;
  int k;
};
bool operator<(const Factor &a, const Factor &b) { return a.k > b.k; }
vector<Factor> v;
vector<int> answer;
vector<int> aux;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> t;
  while (t--) {
    cin >> n;
    v.clear();
    int p = 2;
    int cntDiv = 1;
    int auxn = n;
    int cnt = 0;
    while (auxn > 1) {
      if (p * p > auxn) p = auxn;
      if (auxn % p == 0) {
        v.push_back(Factor{p, 0});
        while (auxn % p == 0) {
          auxn /= p;
          v.back().k++;
        }
        cntDiv *= (v.back().k + 1);
      }
      p++;
    }
    sort(v.begin(), v.end());
    answer.clear();
    int suff = n;
    int lg = cntDiv;
    for (int i = 0; i < (int)v.size(); i++) {
      Factor f = v[i];
      lg = lg / (f.k + 1) * f.k;
      suff /= f.p;
      for (int i = 1; i <= lg; i++) answer.push_back(f.p);
      aux.clear();
      for (int d = 1; d * d <= suff; d++)
        if (suff % d == 0) {
          aux.push_back(d);
          if (d * d < suff) aux.push_back(suff / d);
        }
      int a = -1, b = -1;
      if (i < (int)v.size() - 1) {
        for (int d : aux)
          if (d % v[i + 1].p == 0) {
            a = d;
            break;
          }
        if (a == -1) cnt++;
      }
      if (i == 0 && (int)v.size() > 1) {
        for (int d : aux)
          if (d != a && d % v.back().p == 0) {
            b = d;
            break;
          }
        if (b == -1) cnt++;
      }
      if (a != -1) answer.end()[-1] *= a;
      if (b != -1) answer.end()[-lg] *= b;
      int pos = 0;
      for (int i = (int)answer.size() - lg + (b != -1);
           i < (int)answer.size() - (a != -1); i++) {
        while (aux[pos] == a || aux[pos] == b) pos++;
        answer[i] *= aux[pos];
        pos++;
      }
      lg /= f.k;
      while (suff % f.p == 0) suff /= f.p;
    }
    for (int val : answer) cout << val << " ";
    cout << "\n" << cnt << "\n";
  }
  return 0;
}
