import java.math.BigInteger import java.lang.Math fun main() { val n_num = readLine()!!.toInt() repeat(n_num) { val bg = readLine()!!.toBigInteger() var cnt = 0 var isp: Boolean do { isp = IsPrime.Miller_Rabin.isPrime(bg) cnt++ } while (isp && cnt < 10) println(if (isp) "${bg} 1" else "${bg} 0") } } class IsPrime { companion object Miller_Rabin { fun isPrime(num: BigInteger) : Boolean{ if (1.toBigInteger() == num) return false if (2.toBigInteger() == num) return true if (num.mod(2.toBigInteger()) == BigInteger.ZERO) return false var s = 0 var t = num - 1.toBigInteger() while (t.and(1.toBigInteger()) == BigInteger.ZERO) { s = s + 1 t = t.shr(1) } val a = num.minus(1.toBigInteger()).toBigDecimal().times(Math.random().toBigDecimal()).toBigInteger().plus(1.toBigInteger()) // println("a = ${a}") if (a.modPow(t, num) == 1.toBigInteger()) return true for (i in 0..s-1) if (a.modPow(2.toBigInteger().pow(i).times(t), num) == num.minus(1.toBigInteger())) return true return false } } }