N = int(input()) for _ in range(N): P = int(input()) if P == 2: print(2) else: print(pow(P - 1, -1, P) * (P - 1))