#include #include #include #include #include #include #include #include #include #include #include using namespace std; #define MOD 1000000007 #define MOD2 998244353 #define INF (1<<29) #define LINF (1LL<<60) #define EPS (1e-10) #define PI 3.1415926535897932384626433832795028 typedef long long Int; typedef pair P; typedef long double Real; typedef complex CP; bool is_prime[5500000]; void init(){ fill(is_prime, is_prime + 5500000, true); is_prime[0] = is_prime[1] = false; for(int i = 2;i*i < 5500000;i++){ if(!is_prime[i])continue; for(Int j = i * i;j < 5500000;j += i) is_prime[j] = false; } } void solve(){ Int a, p; scanf("%lld%lld", &a, &p); if(!is_prime[p]){ puts("-1"); } else{ puts("1"); } } int main(){ Int t; init(); scanf("%lld", &t); while(t--)solve(); return 0; }