def isPrimeMR(n):
    if n in {2, 3, 5, 7, 11, 13, 17}:
        return True
    d = n - 1
    d = d // (d & -d)
    L = (
        [2, 7, 61]
        if n < 1 << 32
        else [2, 3, 5, 7, 11, 13, 17]
        if n < 1 << 48
        else [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
    )
    for a in L:
        t = d
        y = pow(a, t, n)
        if y == 1:
            continue
        while y != n - 1:
            y = (y * y) % n
            if y == 1 or t == n - 1:
                return False
            t <<= 1
    return True


for i in range(int(input())):
  x = int(input())
  print(x, int(isPrimeMR(x)))