require 'openssl' require 'prime' T = gets.to_i T.times do a, pv = gets.split.map(&:to_i) bn = OpenSSL::BN.new(pv) if bn.prime? puts 1 else puts -1 end end