def solve n = gets.to_s.to_i x = 1 i = 0 cnt = {} while cnt[x].nil? cnt[x] = i x = (x * 10) % n if x.zero? return 1 end i += 1 end return i - cnt[x] end t = gets.to_s.to_i t.times do puts solve end