for _ in range(int(input())): n = int(input()); s = input()+"-"; k = p = 0 for i in range(n): if s[i]=="K" and s[i-1]!="K": k += 1 if s[i]=="P" and s[i-1]!="P": p += 1 print("K" if k>=p else "P")