#The solution in Python 3 is as follows:
t=int(input())
i=0
while i<t:
N = int(input())
print (((N//2 + 1)**2) % N) #Output follows this pattern
i+=1
#Keep visiting for more solutions of SPOJ problems in Python 3.Thank you!!!
t=int(input())
i=0
while i<t:
N = int(input())
print (((N//2 + 1)**2) % N) #Output follows this pattern
i+=1
#Keep visiting for more solutions of SPOJ problems in Python 3.Thank you!!!