# library from https://qiita.com/t_fuki/items/7cd50de54d3c5d063b4a def gcd(a, b): while a: a, b = b%a, a return b def is_prime(n): if n == 2: return 1 if n == 1 or n%2 == 0: return 0 m = n - 1 lsb = m & -m s = lsb.bit_length()-1 d = m // lsb test_numbers = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37] for a in test_numbers: if a == n: continue x = pow(a,d,n) r = 0 if x == 1: continue while x != m: x = pow(x,2,n) r += 1 if x == 1 or r == s: return 0 return 1 def find_prime_factor(n): if n%2 == 0: return 2 m = int(n**0.125)+1 for c in range(1,n): f = lambda a: (pow(a,2,n)+c)%n y = 0 g = q = r = 1 k = 0 while g == 1: x = y while k < 3*r//4: y = f(y) k += 1 while k < r and g == 1: ys = y for _ in range(min(m, r-k)): y = f(y) q = q*abs(x-y)%n g = gcd(q,n) k += m k = r r *= 2 if g == n: g = 1 y = ys while g == 1: y = f(y) g = gcd(abs(x-y),n) if g == n: continue if is_prime(g): return g elif is_prime(n//g): return n//g else: return find_prime_factor(g) def factorize(n): res = {} while not is_prime(n) and n > 1: # nが合成数である間nの素因数の探索を繰り返す p = find_prime_factor(n) s = 0 while n%p == 0: # nが素因数pで割れる間割り続け、出力に追加 n //= p s += 1 res[p] = s if n > 1: # n>1であればnは素数なので出力に追加 res[n] = 1 return res def primeenumeration(n): # 2<= p<=nを満たす素数nのリストを返す ret = [] if n < 2: return ret ok = [False if i % 2 == 0 else True for i in range(n+1)] ok[1] = False ok[2] = True ret.append(2) for i in range(3, n+1, 2): if ok[i]: ret.append(i) for j in range(i, n+1,i): ok[j] = False return ret prime = primeenumeration(3000000) t = int(input()) while t: t -= 1 n = int(input()) if is_prime(n): print("P") continue check = [0 for i in range(n+1)] factor = factorize(n) minkey = min(factor.keys()) lim = n // minkey for p in prime: if p > lim: break for i in range(p, n+1, p): check[i] = 1 # for key in factor.keys(): # for i in range(key, n+1, key): # check[i] = 1 s = sum(check) - 1 # print(check[:100]) if s % 2 == 0: print("P") else: print("K")