#include using namespace std; #define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i) #define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i) #define all(n) begin(n), end(n) using ll = long long; using P = pair; using vi = vector; using vl = vector; using vs = vector; using vc = vector; using vb = vector; using vd = vector; vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1}; struct Sieve { int n; vector f, primes; Sieve(int n = 1) : n(n), f(n + 1) { f[0] = f[1] = -1; for(ll i = 2; i <= n; ++i) { if(f[i]) continue; primes.push_back(i); f[i] = i; for(ll j = i * i; j <= n; j += i) { if(!f[j]) f[j] = i; } } } bool isPrime(int x) { return f[x] == x; } vector factorList(int x) { vector res; while(x != 1) { res.push_back(f[x]); x /= f[x]; } return res; } vector

factor(int x) { vector fl = factorList(x); if(fl.size() == 0) return {}; vector

res(1, P(fl[0], 0)); for(int p : fl) { if(res.back().first == p) { res.back().second++; } else { res.emplace_back(p, 1); } } return res; } }; int main() { ll t; cin >> t; Sieve s(5e6 + 1); rep(_, t) { ll a; int p; cin >> a >> p; cout << (s.isPrime(p) ? 1 : -1) << '\n'; } }