#include using namespace std; using SS = int; class SegmentTree{ public: int siz = 1; vector dat; SS op(SS a, SS b){return a+b;} SS e(){return 0;} void renew (SS &a,SS x){ //a = op(a,x); a = x; //その他. } void make(int N){ while(siz < N) siz *= 2; dat.resize(siz*2,e()); } void make2(int N,vector &A){ make(N); for(int i=0; i0; i--) dat.at(i) = op(dat.at(i*2),dat.at(i*2+1)); } void update(int pos,SS x){ pos = pos+siz; renew(dat.at(pos),x); while(pos != 1){ pos = pos/2; dat.at(pos) = op(dat.at(pos*2),dat.at(pos*2+1)); } } SS findans(int l, int r){ SS retl = e(),retr = e(); l += siz,r += siz; while(l < r){ if(l&1) retl = op(retl,dat.at(l++)); if(r&1) retr = op(dat.at(--r),retr); l >>= 1; r >>= 1; } return op(retl,retr); } SS get(int pos){return dat.at(pos+siz);} SS rangeans(int l, int r){return findans(l,r);} SS allrange(){return findans(0,siz);} //ノーマルセグ木 二分探索は実装してない. }; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int T; cin >> T; int Need = 3e6+9; vector prime(Need+1,1); prime.at(0) = 0; prime.at(1) = 0; for(int i=2; i*i<=Need; i++){ if(!prime.at(i)) continue; for(int k=i*i; k<=Need; k+=i) prime.at(k) = 0; } SegmentTree Z; Z.make2(Need+1,prime); while(T--){ int N; cin >> N; if(prime.at(N)){cout << "P" << endl; continue;} int p = Z.rangeans(N/2+1,N); N -= p; N -= 2; if(N%2) cout << "K" << endl; else cout << "P" << endl; } }