#include using ll = long long; #define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i) #define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i) #define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i) #define rreps(i, n) for (int i = ((int)(n)); i > 0; --i) #define rep2(i, s, n) for (int i = (s); i < (int)(n); i++) #define repc2(i, s, n) for (int i = (s); i <= (int)(n); i++) constexpr int inf = 2000'000'000; constexpr ll linf = 4000000000000000000ll; constexpr ll M7 = 1000000007ll; constexpr ll M09 = 1000000009ll; constexpr ll M9 = 998244353ll; #define all(v) begin(v), end(v) #define rall(v) rbegin(v), rend(v) using namespace std; template inline ostream& operator<<(ostream& os, const vector& v) { for (auto itr = v.begin(); itr != v.end(); ++itr) { os << *itr; if (itr != v.end() - 1) { os << " "; } } return os; } template std::ostream& operator<<(std::ostream& os, const std::pair& p) noexcept { return os << "(" << p.first << ", " << p.second << ")"; } vector min_pf; ll euler_phi(ll n) { ll res = n; for (ll i = 2; i * i <= n; i++) { if (n % i == 0) { res -= res / i; while (n % i == 0) n /= i; } } if (n > 1) res -= res / n; return res; } void prime_factorize_init(int n) { min_pf.resize(n + 1, 0); for (int i = 2; i <= n; i++) { if (min_pf.at(i) == 0) { for (int mul = i; mul <= n; mul += i) { min_pf.at(mul) = i; } } } } vector prime_factorize(int n, bool uniq = false) { vector res; if (n <= 1) return res; while (n != 1) { res.push_back(min_pf.at(n)); n /= min_pf.at(n); } if (uniq) res.erase(unique(res.begin(), res.end()), res.end()); return res; } class DisjointSet { private: vector rank, parent; public: DisjointSet() {} DisjointSet(int size) { rank.resize(size, 0); parent.resize(size, 0); rep(i, size) { makeSet(i); } } void makeSet(int x) { parent[x] = -1; rank[x] = 0; } bool same(int x, int y) { return findSet(x) == findSet(y); } void unite(int x, int y) { link(findSet(x), findSet(y)); } void link(int x, int y) { if (x == y) { return; } if (rank[x] > rank[y]) { parent[x] += parent[y]; parent[y] = x; } else { parent[y] += parent[x]; parent[x] = y; if (rank[x] == rank[y]) { rank[y]++; } } } int findSet(int x) { if (parent[x] >= 0) { parent[x] = findSet(parent[x]); return parent[x]; } return x; } int size(int x) { return -parent[findSet(x)]; } }; constexpr int N = 3000000; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); prime_factorize_init(N); DisjointSet ds(N + 1); vector> v = vector>(N + 1); vector ans(N + 1, false); repc2(i, 2, N) { for (auto x : v[i]) { ds.unite(i, x); } ans[i] = ds.size(i) % 2 == 0; for (int j = i; j <= N; j += i) { v.at(j).push_back(i); } } int Q; cin >> Q; while (Q--) { ll n; cin >> n; cout << (ans[n] ? "K" : "P") << endl; } return 0; }