#include using namespace std; using ll = long long; using ld = long double; using P = pair; using PLL = pair; #define rep(i,n) for(int i = 0; i < (int)(n); i++) #define repn(i,n) for(int i = 0; i <= (int)(n); i++) #define srep(i,l,n) for(int i = l; i < (int)(n); i++) #define srepn(i,l,n) for(int i = l; i <= (int)(n); i++) #define drep(i,n) for(int i = (int)(n-1); i >= 0; i--) #define drepn(i,n) for(int i = (int)(n); i >= 0; i--) #define size(s) (int)s.size() #define debug(var) do{std::cout << #var << " : ";view(var);}while(0) template void view(T e){std::cout << e << std::endl;} template void view(const std::vector& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;} template void view(const std::vector >& vv){ for(const auto& v : vv){ view(v); } } template inline istream& operator>>(istream &i, vector &v) {rep(j, size(v)) i >> v[j]; return i;} templatebool chmax(T &a, const T &b) { if (abool chmin(T &a, const T &b) { if (b T gcd(T a, T b) {if(b==0)return a; else return gcd(b,a%b);} template T lcm(T a, T b) {return a/gcd(a,b)*b;} template using V = vector; template using VV = vector>; bool isIn(int i, int j, int h, int w) {return i >= 0 && i < h && j >= 0 && j < w;} void Yes(){cout << "Yes" << endl;} void No(){cout << "No" << endl;} void YES(){cout << "YES" << endl;} void NO(){cout << "NO" << endl;} void err() {cout << -1 << endl;} #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define pb push_back #define ep emplace_back const int MOD = 1000000007; const int INF = 1e9; #define PI acos(-1); int dx[4] = {1,-1,0,0}; int dy[4] = {0,0,1,-1}; int ddx[8] = {1,1,1,-1,-1,-1,0,0}; int ddy[8] = {0,1,-1,0,1,-1,1,-1}; const int mxN = 5e6 + 3; bool prime[mxN]; void settable() { prime[0] = prime[1] = 0; for(int i = 2; i < mxN; i++) { if(prime[i]) { for(int j = i + i; j < mxN; j += i) { prime[j] = false; } } } } void solve() { ll a; int p; cin >> a >> p; if(!prime[p]) { cout << -1 << endl; }else{ cout << 1 << endl; } } int main(){ ios::sync_with_stdio(false); cin.tie(0); memset(prime, 1, sizeof(prime)); settable(); int t; cin >> t; while(t--) solve(); }