tests = int(input()) for _ in range(tests): # result = [] mods = [] n = int(input()) mod = 1 for _ in range(100000): nxt = mod // n mod -= n * nxt # result.append(nxt) mods.append(mod) mod *= 10 for length in range(1, 50001): ok = True for i in range(1, length + 1): # ok &= result[-i] == result[-(i + length)] ok = mods[-i] == mods[-(i + length)] if not ok: break if ok: print(length) break