#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
const double EPS = 1e-9;
typedef pair<int, int> P;
typedef unsigned int ui;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
int p, q;
bool basic(int x,int y) {
	int a[8] = { 1,0,-1,0,p,-p,q,-q };
	int b[8] = { 0,1,0,-1,q,-q,-p,p };
	rep(i, 8) {
		if (x == a[i] && y == b[i])return true;
	}
	return false;
}
int main() {
	int r; cin >> r;
	rep(i, r) {
		cin >> p >> q;
		bool out = false;
		int a = p * p + q * q;
		int b = (int)sqrt(a + 0.5);
		Rep1(m, -b, b) {
			int c = a - m * m;
			int d = (int)sqrt(c + 0.5);
			Rep1(n, -d, d) {
				int x = m * m + n * n;
				if (x == 0)continue;
				int s = m * p + n * q;
				int t = m * q - n * p;
				if (!basic(m, n) && s%x == 0 && t%x == 0) {
					out = true; break;
				}
			}
			if (out)break;
		}
		if (out)cout << "C" << endl;
		else cout << "P" << endl;
	}
	return 0;
}
