#!/usr/bin/env python3 import math import random def is_prime_miller_rabin(n, k=50): """Determing whether the given integer is prime by the Miller-Rabin test. :param int n: The integer to be checked. :param int k: The parameter representing the accuracy of the determination. :return: Whether n is prime or not. :rtype: bool """ assert n > 0 if n == 2: return True elif n == 1 or n % 2 == 0: return False d = n - 1 s = 0 while d % 2 == 0: d //= 2 s += 1 for i in range(k): a = random.randint(1, n - 1) if pow(a, d, n) != 1: for r in range(0, s): if pow(a, d * 2 ** r, n) == n - 1: break else: return False return True def solve(xs): return ((x, int(is_prime_miller_rabin(x))) for x in xs) def main(): n = int(input()) xs = (int(input()) for _ in range(n)) print(*("{} {}".format(r1, r2) for r1, r2 in solve(xs)), sep="\n") if __name__ == '__main__': main()