N, *p = map(int, open(0).read().split()) for e in p: for i in range(1, int(e ** 0.5)): if pow(2, i, e) == e: print(i) break else: print(-1)