#include #include using namespace std; class UnionFind { private: vector par; vector rank; vector size; public: UnionFind(int n) { par.resize(n); rank.resize(n); size.resize(n); for (int i = 0; i < n; ++i) { par[i] = i; rank[i] = 0; size[i] = 1; } } int find(int x) { if (par[x] == x) { return x; } else { return par[x] = find(par[x]); } } void unionSet(int x, int y) { x = find(x); y = find(y); if (x != y) { if (rank[x] < rank[y]) { swap(x, y); } if (rank[x] == rank[y]) { rank[x]++; } par[y] = x; size[x] += size[y]; } } bool isSame(int x, int y) { return find(x) == find(y); } int getSize(int x) { return size[find(x)]; } }; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int T; cin >> T; const int M = 3 * 1000000 + 5; vector L(M, 0); vector> G(M); for (int i = 2; i < M; ++i) { if (L[i]) { continue; } for (int j = 2 * i; j < M; j += i) { G[j].push_back(i); L[j] = 1; } } UnionFind uf(M); vector ans(M, 0); for (int i = 2; i < M; ++i) { for (int j : G[i]) { uf.unionSet(i, j); } ans[i] = uf.getSize(i); } for (int _ = 0; _ < T; ++_) { int num; cin >> num; cout << (ans[num] % 2 == 0 ? "K" : "P") << endl; } return 0; }