#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;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKLy8gUGFsaW5kcm9tb3MuCmJvb2wgZXNQYWxpbmRyb21vKHN0cmluZyBwKSB7CiAgICBpbnQgaSA9IDAsIGogPSBwLmxlbmd0aCgpIC0gMTsKICAgIHdoaWxlIChpIDwgaikgewogICAgICAgIGlmIChwW2ldICE9IHBbal0pIGJyZWFrOwogICAgICAgIGkrKzsgai0tOwogICAgfQogICAgaWYgKGkgPj0gaikgcmV0dXJuIHRydWU7CiAgICBlbHNlIHJldHVybiBmYWxzZTsKfQoKaW50IG1haW4oKSB7CiAgICBzdHJpbmcgcGFsYWJyYTsKICAgIGludCBuLCBpOwogICAgYm9vbCByOwogICAgY2luID4+IG47CiAgICBmb3IgKGkgPSAxOyBpIDw9IG47IGkrKykgewogICAgICAgIGNpbiA+PiBwYWxhYnJhOwogICAgICAgIHIgPSBlc1BhbGluZHJvbW8ocGFsYWJyYSk7CiAgICAgICAgaWYgKHIpIGNvdXQgPDwgIlAiIDw8IGVuZGw7CiAgICAgICAgZWxzZSBjb3V0IDw8ICJOUCIgPDwgZW5kbDsKICAgIH0KICAgIHJldHVybiAwOwp9