n = int(input())
for i in range(n):
m = int(input())
s = 0
for j in range(1, int(m ** 0.5)+1):
if m % j == 0:
s += j
if j != m/j:
s += m/j
s -= m
if s == m:
print("%d is perfect"%m)
else:
print("%d is not perfect"%m)