from collections import defaultdict # 素因数分解O(√n) def primeFactor(n): res = defaultdict(lambda: 0) for i in range(2, int(n**0.5)+1): while n % i == 0: res[i] += 1 n = n // i if n != 1: res[n] = 1 return res T = int(input()) for _ in range(T): N = int(input()) while N % 2 == 0: N //= 2 while N % 5 == 0: N //= 5 if N == 1: print(1) else: i = 1 while True: M = int('9' * i) if M % N == 0: print(i) break else: i += 1