# d = int(input("分母 d: ")) # print("1 /", d, "を求めます。") # # 例外処理 # if d <= 0: # print("条件を満たさない入力です。d>=1である必要があります。") # exit() # elif d == 1: # print("1 / 1 = 1 です。") # exit() t = int(input()) a = [int(input()) for _ in range(t)] for d in a: done = False x = 1 counter = 1 isRecurringDecimal = False cycleLength = 0 quotientList = [] remainderList = [-1] * d remainderList[1] = 0 while not done: x = x * 10 quotientList.append(x // d) r = x % d if r == 0: done = True elif remainderList[r] != -1: isRecurringDecimal = True cycleLength = counter - remainderList[r] done = True else: remainderList[r] = counter x = r counter += 1 if not isRecurringDecimal: print(1) # print("循環しません。小数点以下の商は", quotientList, "です。") else: print(cycleLength) print() # beforeRecurringCycle = quotientList[0:len(quotientList) - cycleLength] # recurringCycle = quotientList[len(quotientList) - cycleLength:] # print("循環します。") # if beforeRecurringCycle: # print("循環節に含まれない部分は", beforeRecurringCycle, "です。") # else: # print("循環節に含まれない部分はありません。") # print("循環節は", recurringCycle, "です。")