#include int vis[5000005]; void preWork(int n){ vis[1] = 1; for(int i = 2; i <= n; i++){ if(!vis[i]){ for(int j = 2*i; j <= n; j+=i) vis[j] = 1; } } } int main(){ preWork(5000000); int T; scanf("%d",&T); while(T--){ long long a,p; scanf("%lld%lld",&a,&p); if(vis[p]) printf("-1\n"); else printf("1\n"); } return 0; }