#yuki-1339 T = int(input()) candidates = [2*i+1 for i in range(1, 15811)] primelist = [2] p = 3 while p**2 <= 31623: primelist.append(p) candidates = [c for c in candidates if c%p] p = candidates[0] primelist += candidates l = len(primelist) def euler(n): """ nが奇数の時 """ i = 1 ans = n while i < l and primelist[i]**2 <= n: p = primelist[i] if not n%p: ans -= ans//p while not n%p: n //= p i += 1 if n > 1: ans -= ans//n return ans def divlist(n): from collections import defaultdict as ddt d = ddt(int) i = 0 while primelist[i]**2 <= n: p = primelist[i] while not n%p: d[p] += 1 n //= p i += 1 if n > 1: d[n] += 1 ans = {1} for k in d.keys(): plus = set() for x in ans: for ex in range(d[k]): plus.add(x*k**(ex+1)) ans |= plus return sorted(ans) for _ in range(T): N = int(input()) #10**9以下 while not N%2: N //= 2 while not N%5: N //= 5 if N == 1: print(1) for d in divlist(euler(N)): if pow(10, d, N) == 1: print(d) break