import sys sys.setrecursionlimit(3*10**5) t = int(input()) for _ in range(t): n = int(input()) dic = {} now = 1 while now < n: now *= 10 c = 0 ans = 1 while now: x,now = divmod(now,n) if now in dic: ans = c-dic[now] break dic[now] = c now *= 10 #print(now) c += 1 print(ans)