use std::io::*; fn f(x: usize, n: usize) -> usize { x * 10 % n } fn cycle(n: usize) -> usize { let mut osoi = 10; let mut hayai = f(10, n); while osoi != hayai { osoi = f(osoi, n); hayai = f(f(hayai, n), n); } let mut len = 1; hayai = f(hayai, n); while osoi != hayai { len += 1; hayai = f(hayai, n); } len } fn main() { let mut s: String = String::new(); std::io::stdin().read_to_string(&mut s).ok(); let mut itr = s.trim().split_whitespace(); let t: usize = itr.next().unwrap().parse().unwrap(); for _ in 0..t { let n: usize = itr.next().unwrap().parse().unwrap(); // 10^x mod nの最小循環 let mut m = n; while m % 2 == 0 { m /= 2; } while m % 5 == 0 { m /= 5; } if m == 1 { println!("1"); continue; } println!("{}", cycle(n)); } }