#include #include using namespace std; using ll = long long int; constexpr int TABLEMAX = 5000010; int main(){ vector isprime(TABLEMAX, true); isprime[0] = isprime[1] = false; for(int i = 2; i < TABLEMAX; i++){ if(!isprime[i]) continue; for(int j = 2; i*j < TABLEMAX; j++) isprime[i*j] = false; } int t; cin >> t; while(t--){ ll a, p; cin >> a >> p; if(!isprime[p]) cout << -1 << endl; else{ cout << 1 << endl; } } return 0; }