#include using namespace std; #define ll long long #define ld long double #define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++) #define rep(i,n) REP(i,0,n) #define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--) #define rrep(i,n) RREP(i,n-1,0) #define all(v) v.begin(), v.end() const int inf = 1e9+7; const ll longinf = 1LL<<60; const ll mod = 1e9+7; const ld eps = 1e-10; bool arr[1000000000]; set primes; void Eratosthenes(int N) { for(int i=0; i 0) { if(N % 2 == 1) (ans *= tmp) %= mod; (tmp *= tmp) %= mod; N /= 2; } return ans; } void solve() { ll a, p; cin >> a >> p; if(!primes.count(p)) cout << -1 << "\n"; else cout << 1 << "\n"; } int main() { cin.tie(0); ios::sync_with_stdio(false); Eratosthenes(5000005); int t; cin >> t; while(t--) { solve(); } return 0; }