fn main() { let mut q = String::new(); std::io::stdin().read_line(&mut q).ok(); let q = q.trim().parse::().unwrap(); for _ in 0..q { let mut line = String::new(); std::io::stdin().read_line(&mut line).ok(); let mut line = line.split_whitespace(); let mut n: i64 = line.next().unwrap().parse().unwrap(); let k: i64 = line.next().unwrap().parse().unwrap(); if k == 1 { println!("{}", n-1); continue; } let mut ans = 0; while n > 0 { n /= k; ans += 1; if n == k { ans += 1; break; } } println!("{}", ans); } }