use std::io::*; fn f(x: usize, n: usize) -> usize { x * 10 % n } fn cycle(n: usize) -> usize { let mut power = 1; let mut len = 1; let mut slow = 10; let mut fast = f(10, n); while slow != fast { if power == len { slow = fast; power *= 2; len = 0; } fast = f(fast, n); len += 1; } 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(); 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)); } }