#include #include #include #pragma GCC target("avx") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") using namespace std; const int limit = 100000; bool isprime[100009]; vector factors[100009]; int main() { fill(isprime + 2, isprime + limit + 1, true); for(int i = 2; i <= limit; ++i) { if(!isprime[i]) continue; for(int j = i * 2; j <= limit; j += i) { isprime[j] = false; } } for(int i = 2; i <= limit; ++i) { if(!isprime[i]) continue; for(int j = 1; j <= i; ++j) { if((1LL * j * j + 1) % i == 0) { for(int k = j; k <= limit; k += i) { factors[k].push_back(i); } } } } cin.tie(0); ios_base::sync_with_stdio(false); int Q; cin >> Q; while(Q--) { int v; cin >> v; long long A = 1LL * v * v + 1; vector ans; for(int i : factors[v]) { while(A % i == 0) { A /= i; ans.push_back(i); } } ans.push_back(A); for(int i = 0; i < int(ans.size()); ++i) { if(i) cout << ' '; cout << ans[i]; } cout << '\n'; } return 0; }