#include <iostream>
using namespace std;
//Palindromos.
bool esPalindromo (string p){
int i=0, j=p.length() -1;
while (i<j){
if (p[i] != p[j]) break;
i++; j--;
}
if (i>=j) return true;
else return false;
}
int main()
{
string palabra;
int n,i;
bool r;
cin >> n;
for (i=1; i<=n; i++){
cin >> palabra;
r = esPalindromo (palabra);
if (r) cout << "P" << endl;
else cout << "NP" << endl;
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwovL1BhbGluZHJvbW9zLgpib29sIGVzUGFsaW5kcm9tbyAoc3RyaW5nIHApewoJaW50IGk9MCwgaj1wLmxlbmd0aCgpIC0xOwoJd2hpbGUgKGk8ail7CgkJaWYgKHBbaV0gIT0gcFtqXSkgYnJlYWs7CgkJaSsrOyBqLS07Cgl9CglpZiAoaT49aikgcmV0dXJuIHRydWU7CgllbHNlIHJldHVybiBmYWxzZTsKCQp9CgppbnQgbWFpbigpIAp7CglzdHJpbmcgcGFsYWJyYTsKCWludCBuLGk7IAoJYm9vbCByOwoJY2luID4+IG47Cglmb3IgKGk9MTsgaTw9bjsgaSsrKXsKCQljaW4gPj4gcGFsYWJyYTsKCXIgPSBlc1BhbGluZHJvbW8gKHBhbGFicmEpOwoJaWYgKHIpIGNvdXQgIDw8ICJQIiA8PCBlbmRsOwoJZWxzZSBjb3V0IDw8ICJOUCIgPDwgZW5kbDsKCX0KCXJldHVybiAwOwp9