use std::io::Read; fn main() { let mut s = String::new(); std::io::stdin().read_to_string(&mut s).ok(); let v: Vec = s.split_whitespace().skip(1).flat_map(str::parse).collect(); v.chunks(2).for_each(|x| { let (mut n, k) = (x[0], x[1]); let mut r = k; let mut l = 0; while n > 1 { l += 1; n -= r; r *= k; } println!("{}", l) }); }