#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  vector<int> pr;
  int s[100000] = {0};
  for (int i = 2; i < 100000; i++) {
    if (s[i] == 0) {
      pr.push_back(i);
      for (int j = i; j < 100000; j += i) {
        s[j] = 1;
      }
    }
  }
  while (t-- > 0) {
    int n;
    cin >> n;
    vector<int> ya, vc;
    for (int i = 0; i < pr.size(); i++) {
      if (n % pr[i] == 0) {
        ya.push_back(pr[i]);
        vc.push_back(0);
      }
      while (n % pr[i] == 0) {
        n /= pr[i];
        vc[vc.size() - 1]++;
      }
    }
    if (n != 1) {
      ya.push_back(n);
      vc.push_back(1);
    }
    vector<int> ku;
    set<int> s;
    ;
    stack<int> st, st2;
    st.push(1);
    st2.push(0);
    while (!st.empty()) {
      int sc = st2.top();
      int sn = st.top();
      st2.pop();
      st.pop();
      if (sc == vc.size()) {
        if (sn > 1) {
          ku.push_back(sn);
          s.insert(sn);
        }
        continue;
      }
      for (int i = 0; i <= vc[sc]; i++) {
        st.push(sn * pow(ya[sc], i));
        st2.push(sc + 1);
      }
    }
    int ans[ku.size()];
    int c = 0;
    sort(ku.begin(), ku.end());
    for (int i = 0; i < ya.size(); i++) {
      if (i > 0) {
        s.erase(ya[i] * ya[i - 1]);
        ans[c++] = ya[i] * ya[i - 1];
      }
      ans[c++] = ya[i];
      s.erase(ya[i]);
    }
    ans[c++] = ku[ku.size() - 1];
    s.erase(ku[ku.size() - 1]);
    while (!s.empty()) {
      auto as = s.begin();
      while (as != s.end()) {
        for (int i = 0; i < c; i++) {
          int l = i;
          int r = i + 1;
          if (r >= c) r = 0;
          if ((*as % ans[l] == 0 || ans[l] % *as == 0) &&
              (*as % ans[r] == 0 || ans[r] % *as == 0)) {
            for (int j = c; j > i; j--) {
              ans[j] = ans[j - 1];
            }
            ans[i + 1] = *as;
            as = s.erase(as);
            c++;
            break;
          }
          if (r == 0) as++;
        }
      }
    }
    int cnt = 0;
    for (int i = 0; i < ku.size(); i++) {
      int l = i;
      int r = i + 1;
      if (r >= ku.size()) r = 0;
      if (!(ans[r] % ans[l] == 0 || ans[l] % ans[r] == 0)) {
        cnt++;
      }
      cout << ans[i];
      if (i == ku.size() - 1)
        cout << endl;
      else
        cout << " ";
    }
    cout << cnt << endl;
  }
}
