use std::io::Read; fn run() { let mut s = String::new(); std::io::stdin().read_to_string(&mut s).unwrap(); let mut it = s.trim().split_whitespace(); let q: usize = it.next().unwrap().parse().unwrap(); for _ in 0..q { let n: usize = it.next().unwrap().parse().unwrap(); let k: usize = it.next().unwrap().parse().unwrap(); if k == 1 { println!("{}", n - k); continue; } let mut sum = 1; let mut d = k; let mut ans = 0; while sum < n { ans += 1; sum += d; d *= k; } println!("{}", ans); } } fn main() { run(); }