#include using namespace std; bool pri[5000001]; void init(){ pri[0] = pri[1] = true; for(int i = 2; 5000001 > i; i++){ if(!pri[i]){ for(int j = i+i; 5000001 > j; j+=i){ pri[j]=true; } } } } int main(){ init(); int t;cin>>t; for(int i = 0; t > i; i++){ long long a; int p;cin>>a>>p; if(pri[p]){ cout << -1 << "\n"; }else{ cout << 1 << "\n"; } } }