#test def inverse(a,mod): #aのmodを法にした逆元を返す return pow(a,mod-2,mod) N = int(input()) for i in range(N): p = int(input()) if p == 2: print (2) else: print ((p-1) * inverse(p-1,p)) """ for i in range(100): ans = [] f2 = True flag = False bl = None for j in range(i): if (2**j % i == j): flag = True bl = j if j > 1 and i % j == 0: f2 = False if f2: print (i,flag,bl) """