#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 ediv(n): """ nが奇数の時 """ from collections import defaultdict as ddt d = ddt(int) i = 1 while i < l and primelist[i]**2 <= n: p = primelist[i] if not n%p: n //= p j = 0 m = p-1 while primelist[j]**2 <= m: q = primelist[j] while not m%p: d[q] += 1 m //= q j += 1 if m > 1: d[m] += 1 while not n%p: n //= p d[p] += 1 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 ediv(N): if pow(10, d, N) == 1: print(d) break